69
69
70
70
/**
71
71
* An XHR transport based on Undertow's {@link io.undertow.client.UndertowClient}.
72
- * Compatible with Undertow from version 1.0 to 1.3.
72
+ * Compatible with Undertow 1.0 to 1.3, as of Spring Framework 4.2.2 .
73
73
*
74
74
* <p>When used for testing purposes (e.g. load testing) or for specific use cases
75
75
* (like HTTPS configuration), a custom OptionMap should be provided:
92
92
*/
93
93
public class UndertowXhrTransport extends AbstractXhrTransport {
94
94
95
- private static final boolean undertow13Present = ClassUtils .isPresent ("io.undertow.connector.ByteBufferPool" ,
96
- UndertowXhrTransport .class .getClassLoader ());
97
-
98
95
private static final AttachmentKey <String > RESPONSE_BODY = AttachmentKey .create (String .class );
99
96
97
+ private static final boolean undertow13Present = ClassUtils .isPresent (
98
+ "io.undertow.connector.ByteBufferPool" , UndertowXhrTransport .class .getClassLoader ());
99
+
100
100
101
101
private final OptionMap optionMap ;
102
102
@@ -116,12 +116,8 @@ public UndertowXhrTransport(OptionMap optionMap) throws IOException {
116
116
this .optionMap = optionMap ;
117
117
this .httpClient = UndertowClient .getInstance ();
118
118
this .worker = Xnio .getInstance ().createWorker (optionMap );
119
- if (undertow13Present ) {
120
- this .undertowBufferSupport = new Undertow13BufferSupport ();
121
- }
122
- else {
123
- this .undertowBufferSupport = new Undertow10BufferSupport ();
124
- }
119
+ this .undertowBufferSupport =
120
+ (undertow13Present ? new Undertow13BufferSupport () : new UndertowXnioBufferSupport ());
125
121
}
126
122
127
123
@@ -490,6 +486,7 @@ public void onFailure(Throwable failure) {
490
486
}
491
487
}
492
488
489
+
493
490
private interface UndertowBufferSupport {
494
491
495
492
Object allocatePooledResource ();
@@ -505,15 +502,16 @@ IoFuture<ClientConnection> httpClientConnect(UndertowClient httpClient, final UR
505
502
final XnioWorker worker , OptionMap options );
506
503
}
507
504
508
- private class Undertow10BufferSupport implements UndertowBufferSupport {
505
+
506
+ private class UndertowXnioBufferSupport implements UndertowBufferSupport {
509
507
510
508
private final org .xnio .Pool <ByteBuffer > xnioBufferPool ;
511
509
512
510
private final Method httpClientConnectCallbackMethod ;
513
511
514
512
private final Method httpClientConnectMethod ;
515
513
516
- public Undertow10BufferSupport () {
514
+ public UndertowXnioBufferSupport () {
517
515
this .xnioBufferPool = new org .xnio .ByteBufferSlicePool (1048 , 1048 );
518
516
this .httpClientConnectCallbackMethod = ReflectionUtils .findMethod (UndertowClient .class , "connect" ,
519
517
ClientCallback .class , URI .class , XnioWorker .class , Pool .class , OptionMap .class );
@@ -543,7 +541,6 @@ public void httpClientConnect(UndertowClient httpClient, ClientCallback<ClientCo
543
541
XnioWorker worker , OptionMap options ) {
544
542
ReflectionUtils .invokeMethod (httpClientConnectCallbackMethod , httpClient , listener , uri , worker ,
545
543
this .xnioBufferPool , options );
546
-
547
544
}
548
545
549
546
@ Override
@@ -555,6 +552,7 @@ public IoFuture<ClientConnection> httpClientConnect(UndertowClient httpClient, U
555
552
}
556
553
}
557
554
555
+
558
556
private class Undertow13BufferSupport implements UndertowBufferSupport {
559
557
560
558
private final ByteBufferPool undertowBufferPool ;
0 commit comments