/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code null} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param type expected property class type. * @param <T> property Java type. * @return resolved property value or {@code null} if no such property is registered. */ public <T> T resolveProperty(final String name, final Class<T> type) { return resolveProperty(name, null, type); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code null} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param type expected property class type. * @param <T> property Java type. * @return resolved property value or {@code null} if no such property is registered. */ public <T> T resolveProperty(final String name, final Class<T> type) { return resolveProperty(name, null, type); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code null} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param type expected property class type. * @param <T> property Java type. * @return resolved property value or {@code null} if no such property is registered. */ public <T> T resolveProperty(final String name, final Class<T> type) { return resolveProperty(name, null, type); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code defaultValue} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param defaultValue default value to return if the property is not registered. * @param <T> property Java type. * @return resolved property value or {@code defaultValue} if no such property is registered. */ @SuppressWarnings("unchecked") public <T> T resolveProperty(final String name, final T defaultValue) { return resolveProperty(name, defaultValue, (Class<T>) defaultValue.getClass()); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code defaultValue} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param defaultValue default value to return if the property is not registered. * @param <T> property Java type. * @return resolved property value or {@code defaultValue} if no such property is registered. */ @SuppressWarnings("unchecked") public <T> T resolveProperty(final String name, final T defaultValue) { return resolveProperty(name, defaultValue, (Class<T>) defaultValue.getClass()); }
private Optional<RequestConfig> addJerseyRequestConfig(ClientRequest clientRequest) { final Integer timeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, Integer.class); final Integer connectTimeout = clientRequest.resolveProperty(ClientProperties.CONNECT_TIMEOUT, Integer.class); final Boolean followRedirects = clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, Boolean.class); if (timeout != null || connectTimeout != null || followRedirects != null) { final RequestConfig.Builder requestConfig = RequestConfig.copy(defaultRequestConfig); if (timeout != null) { requestConfig.setSocketTimeout(timeout); } if (connectTimeout != null) { requestConfig.setConnectTimeout(connectTimeout); } if (followRedirects != null) { requestConfig.setRedirectsEnabled(followRedirects); } return Optional.of(requestConfig.build()); } return Optional.empty(); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code defaultValue} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param defaultValue default value to return if the property is not registered. * @param <T> property Java type. * @return resolved property value or {@code defaultValue} if no such property is registered. */ @SuppressWarnings("unchecked") public <T> T resolveProperty(final String name, final T defaultValue) { return resolveProperty(name, defaultValue, (Class<T>) defaultValue.getClass()); }
private HttpUriRequest getUriHttpRequest(final ClientRequest clientRequest) { final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig); final int connectTimeout = clientRequest.resolveProperty(ClientProperties.CONNECT_TIMEOUT, -1); final int socketTimeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, -1); if (connectTimeout >= 0) { requestConfigBuilder.setConnectTimeout(connectTimeout); } if (socketTimeout >= 0) { requestConfigBuilder.setSocketTimeout(socketTimeout); } final Boolean redirectsEnabled = clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, requestConfig.isRedirectsEnabled()); requestConfigBuilder.setRedirectsEnabled(redirectsEnabled); final Boolean bufferingEnabled = clientRequest.resolveProperty(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class) == RequestEntityProcessing.BUFFERED; final HttpEntity entity = getHttpEntity(clientRequest, bufferingEnabled); return RequestBuilder .create(clientRequest.getMethod()) .setUri(clientRequest.getUri()) .setConfig(requestConfigBuilder.build()) .setEntity(entity) .build(); }
if (request.resolveProperty(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, setMethodWorkaround)) { setRequestMethodViaJreBugWorkaround(uc, httpMethod); } else { uc.setInstanceFollowRedirects(request.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); uc.setConnectTimeout(request.resolveProperty(ClientProperties.CONNECT_TIMEOUT, uc.getConnectTimeout())); uc.setReadTimeout(request.resolveProperty(ClientProperties.READ_TIMEOUT, uc.getReadTimeout())); RequestEntityProcessing entityProcessing = request.resolveProperty( ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class);
if (request.resolveProperty(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, setMethodWorkaround)) { setRequestMethodViaJreBugWorkaround(uc, httpMethod); } else { uc.setInstanceFollowRedirects(request.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); uc.setConnectTimeout(request.resolveProperty(ClientProperties.CONNECT_TIMEOUT, uc.getConnectTimeout())); uc.setReadTimeout(request.resolveProperty(ClientProperties.READ_TIMEOUT, uc.getReadTimeout())); RequestEntityProcessing entityProcessing = request.resolveProperty( ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class);
clientRequest.resolveProperty(ApacheClientProperties.CREDENTIALS_PROVIDER, CredentialsProvider.class); if (credentialsProvider != null) { context.setCredentialsProvider(credentialsProvider);
if (request.resolveProperty(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, setMethodWorkaround)) { setRequestMethodViaJreBugWorkaround(uc, httpMethod); } else { uc.setInstanceFollowRedirects(request.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); uc.setConnectTimeout(request.resolveProperty(ClientProperties.CONNECT_TIMEOUT, uc.getConnectTimeout())); uc.setReadTimeout(request.resolveProperty(ClientProperties.READ_TIMEOUT, uc.getReadTimeout())); RequestEntityProcessing entityProcessing = request.resolveProperty( ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class);
builder.setFollowRedirects(requestContext.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); requestContext.resolveProperty(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class); } else { final FeedableBodyGenerator bodyGenerator = new FeedableBodyGenerator(); final Integer chunkSize = requestContext.resolveProperty( ClientProperties.CHUNKED_ENCODING_SIZE, ClientProperties.DEFAULT_CHUNK_SIZE); bodyGenerator.setMaxPendingBytes(chunkSize); final GrizzlyConnectorProvider.RequestCustomizer requestCustomizer = requestContext.resolveProperty( GrizzlyConnectorProvider.REQUEST_CUSTOMIZER, GrizzlyConnectorProvider.RequestCustomizer.class);
private Request translateRequest(final ClientRequest clientRequest) { final URI uri = clientRequest.getUri(); final Request request = client.newRequest(uri); request.method(clientRequest.getMethod()); request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); final Object readTimeout = clientRequest.getConfiguration().getProperties().get(ClientProperties.READ_TIMEOUT); if (readTimeout != null && readTimeout instanceof Integer && (Integer) readTimeout > 0) { request.timeout((Integer) readTimeout, TimeUnit.MILLISECONDS); } return request; }
private HttpRequest createHttpRequest(ClientRequest request) { Object entity = request.getEntity(); if (entity == null) { return HttpRequest.createBodyless(request.getMethod(), request.getUri()); } RequestEntityProcessing entityProcessing = request.resolveProperty( ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class); HttpRequest httpRequest; if (entityProcessing != null && entityProcessing == RequestEntityProcessing.CHUNKED) { httpRequest = HttpRequest.createChunked(request.getMethod(), request.getUri(), connectorConfiguration.getChunkSize()); } else { httpRequest = HttpRequest.createBuffered(request.getMethod(), request.getUri()); } return httpRequest; }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code null} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param type expected property class type. * @param <T> property Java type. * @return resolved property value or {@code null} if no such property is registered. */ public <T> T resolveProperty(final String name, final Class<T> type) { return resolveProperty(name, null, type); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code null} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param type expected property class type. * @param <T> property Java type. * @return resolved property value or {@code null} if no such property is registered. */ public <T> T resolveProperty(final String name, final Class<T> type) { return resolveProperty(name, null, type); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code defaultValue} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param defaultValue default value to return if the property is not registered. * @param <T> property Java type. * @return resolved property value or {@code defaultValue} if no such property is registered. */ @SuppressWarnings("unchecked") public <T> T resolveProperty(final String name, final T defaultValue) { return resolveProperty(name, defaultValue, (Class<T>) defaultValue.getClass()); }
/** * Resolve a property value for the specified property {@code name}. * * <p> * The method returns the value of the property registered in the request-specific * property bag, if available. If no property for the given property name is found * in the request-specific property bag, the method looks at the properties stored * in the {@link #getConfiguration() global client-runtime configuration} this request * belongs to. If there is a value defined in the client-runtime configuration, * it is returned, otherwise the method returns {@code defaultValue} if no such property is * registered neither in the client runtime nor in the request-specific property bag. * </p> * * @param name property name. * @param defaultValue default value to return if the property is not registered. * @param <T> property Java type. * @return resolved property value or {@code defaultValue} if no such property is registered. */ @SuppressWarnings("unchecked") public <T> T resolveProperty(final String name, final T defaultValue) { return resolveProperty(name, defaultValue, (Class<T>) defaultValue.getClass()); }
private Request translateRequest(final ClientRequest clientRequest) { final URI uri = clientRequest.getUri(); final Request request = client.newRequest(uri); request.method(clientRequest.getMethod()); request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); final Object readTimeout = clientRequest.getConfiguration().getProperties().get(ClientProperties.READ_TIMEOUT); if (readTimeout != null && readTimeout instanceof Integer && (Integer) readTimeout > 0) { request.timeout((Integer) readTimeout, TimeUnit.MILLISECONDS); } return request; }