Skip to content

Commit

Permalink
Ensuring that request-scoped config gets propagated to HttpUriRequest
Browse files Browse the repository at this point in the history
The change makes the config changes introduced via
`Invocation.Builder#property(propertyName, propertyValue)` effective.
We want to use this pattern because it is truely request creation scoped.
In contrast the current implementation is only effective if config changes
are being introduced via `WebTarget#property(propertyName, propertyValue)`
which unfortunatly creates a new copy of copy of
`org.glassfish.jersey.client.ClientRuntime` which effectively makes it
innefective for implementing dynamic configuration (we saw OutOfMemory
errors due to that).

Original change can be founde here: #939

Closes #1137
  • Loading branch information
velocipedist authored and arteam committed Jun 26, 2015
1 parent da1ae9b commit 5a0dde2
Showing 1 changed file with 5 additions and 6 deletions.
Expand Up @@ -24,7 +24,6 @@
import org.glassfish.jersey.message.internal.Statuses; import org.glassfish.jersey.message.internal.Statuses;


import javax.ws.rs.ProcessingException; import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -135,18 +134,18 @@ private HttpUriRequest buildApacheRequest(ClientRequest jerseyRequest) {
builder.addHeader(headerName, jerseyRequest.getHeaderString(headerName)); builder.addHeader(headerName, jerseyRequest.getHeaderString(headerName));
} }


Optional<RequestConfig> requestConfig = addJerseyRequestConfig(jerseyRequest.getConfiguration()); Optional<RequestConfig> requestConfig = addJerseyRequestConfig(jerseyRequest);
if (requestConfig.isPresent()) { if (requestConfig.isPresent()) {
builder.setConfig(requestConfig.get()); builder.setConfig(requestConfig.get());
} }


return builder.build(); return builder.build();
} }


private Optional<RequestConfig> addJerseyRequestConfig(Configuration configuration) { private Optional<RequestConfig> addJerseyRequestConfig(ClientRequest clientRequest) {
final Integer timeout = (Integer) configuration.getProperty(ClientProperties.READ_TIMEOUT); final Integer timeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, Integer.class);
final Integer connectTimeout = (Integer) configuration.getProperty(ClientProperties.CONNECT_TIMEOUT); final Integer connectTimeout = clientRequest.resolveProperty(ClientProperties.CONNECT_TIMEOUT, Integer.class);
final Boolean followRedirects = (Boolean) configuration.getProperty(ClientProperties.FOLLOW_REDIRECTS); final Boolean followRedirects = clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, Boolean.class);


if (timeout != null || connectTimeout != null || followRedirects != null) { if (timeout != null || connectTimeout != null || followRedirects != null) {
RequestConfig.Builder requestConfig = RequestConfig.copy(defaultRequestConfig); RequestConfig.Builder requestConfig = RequestConfig.copy(defaultRequestConfig);
Expand Down

0 comments on commit 5a0dde2

Please sign in to comment.