|
31 | 31 | import java.util.Optional;
|
32 | 32 | import java.util.concurrent.CancellationException;
|
33 | 33 | import java.util.concurrent.CompletableFuture;
|
| 34 | +import java.util.concurrent.ExecutionException; |
34 | 35 | import java.util.concurrent.Future;
|
35 | 36 | import java.util.concurrent.TimeUnit;
|
| 37 | +import java.util.concurrent.TimeoutException; |
36 | 38 | import java.util.concurrent.atomic.AtomicBoolean;
|
37 | 39 | import java.util.concurrent.atomic.AtomicReference;
|
38 | 40 | import java.util.logging.Level;
|
|
45 | 47 |
|
46 | 48 | import javax.net.ssl.SSLContext;
|
47 | 49 |
|
| 50 | +import org.eclipse.jetty.client.util.BasicAuthentication; |
| 51 | +import org.eclipse.jetty.client.util.BytesContentProvider; |
| 52 | +import org.eclipse.jetty.client.util.FutureResponseListener; |
| 53 | +import org.eclipse.jetty.client.util.OutputStreamContentProvider; |
48 | 54 | import org.glassfish.jersey.client.ClientProperties;
|
49 | 55 | import org.glassfish.jersey.client.ClientRequest;
|
50 | 56 | import org.glassfish.jersey.client.ClientResponse;
|
|
65 | 71 | import org.eclipse.jetty.client.api.Request;
|
66 | 72 | import org.eclipse.jetty.client.api.Response;
|
67 | 73 | import org.eclipse.jetty.client.api.Result;
|
68 |
| -import org.eclipse.jetty.client.util.BasicAuthentication; |
69 |
| -import org.eclipse.jetty.client.util.BytesContentProvider; |
70 |
| -import org.eclipse.jetty.client.util.OutputStreamContentProvider; |
71 | 74 | import org.eclipse.jetty.http.HttpField;
|
72 | 75 | import org.eclipse.jetty.http.HttpFields;
|
73 | 76 | import org.eclipse.jetty.http.HttpHeader;
|
@@ -130,6 +133,7 @@ class JettyConnector implements Connector {
|
130 | 133 | private final HttpClient client;
|
131 | 134 | private final CookieStore cookieStore;
|
132 | 135 | private final Configuration configuration;
|
| 136 | + private final Integer responseBufferMaxSize; |
133 | 137 |
|
134 | 138 | /**
|
135 | 139 | * Create the new Jetty client connector.
|
@@ -199,6 +203,12 @@ class JettyConnector implements Connector {
|
199 | 203 | client.setCookieStore(new HttpCookieStore.Empty());
|
200 | 204 | }
|
201 | 205 |
|
| 206 | + responseBufferMaxSize = (Integer) Optional.ofNullable(configuration.getProperties() |
| 207 | + .get(JettyClientProperties.RESPONSE_BUFFER_MAX_SIZE)).orElse(2 * 1024 * 1024); |
| 208 | + if (responseBufferMaxSize <= 0) { |
| 209 | + throw new IllegalArgumentException(JettyClientProperties.RESPONSE_BUFFER_MAX_SIZE + " can not be negative."); |
| 210 | + } |
| 211 | + |
202 | 212 | try {
|
203 | 213 | client.start();
|
204 | 214 | } catch (final Exception e) {
|
@@ -248,7 +258,20 @@ public ClientResponse apply(final ClientRequest jerseyRequest) throws Processing
|
248 | 258 | }
|
249 | 259 |
|
250 | 260 | try {
|
251 |
| - final ContentResponse jettyResponse = jettyRequest.send(); |
| 261 | + final FutureResponseListener listener = new FutureResponseListener(jettyRequest, responseBufferMaxSize); |
| 262 | + jettyRequest.send(listener); |
| 263 | + final ContentResponse jettyResponse; |
| 264 | + try { |
| 265 | + jettyResponse = listener.get(); |
| 266 | + } |
| 267 | + catch (ExecutionException x) { |
| 268 | + if (x.getCause() instanceof TimeoutException) { |
| 269 | + TimeoutException t = (TimeoutException) (x.getCause()); |
| 270 | + throw t; |
| 271 | + } |
| 272 | + throw x; |
| 273 | + } |
| 274 | + |
252 | 275 | HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, jerseyRequest.getHeaders(),
|
253 | 276 | JettyConnector.this.getClass().getName(), jerseyRequest.getConfiguration());
|
254 | 277 |
|
|
0 commit comments