Class HttpUrlConnectorProvider
- All Implemented Interfaces:
- ConnectorProvider
connector provider
 that provides connector instances which delegate HTTP requests to HttpURLConnection
 for processing.
 
 The provided connector instances override default behaviour of the property
 ClientProperties.REQUEST_ENTITY_PROCESSING and use RequestEntityProcessing.BUFFERED
 request entity processing by default.
 
 Due to a bug in the chunked transport coding support of HttpURLConnection that causes
 requests to fail unpredictably, this connector provider allows to configure the provided connector
 instances to use HttpURLConnection's fixed-length streaming mode as a workaround. This
 workaround can be enabled via useFixedLengthStreaming() method or via
 USE_FIXED_LENGTH_STREAMING Jersey client configuration property.
 
- Author:
- Marek Potociar
- 
Nested Class SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringA value oftruedeclares that the client will try to set unsupported HTTP method toHttpURLConnectionvia reflection as a workaround for a missing HTTP method.static final StringIftrue, theHttpUrlConnector(if used) will assume the content length from the value of "Content-Length" request header (if present).
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionchunkSize(int chunkSize) Set chunk size for requests transferred using a HTTP chunked transfer coding.connectionFactory(HttpUrlConnectorProvider.ConnectionFactory connectionFactory) Set a customHttpURLConnectionfactory.protected ConnectorcreateHttpUrlConnector(Client client, HttpUrlConnectorProvider.ConnectionFactory connectionFactory, int chunkSize, boolean fixLengthStreaming, boolean setMethodWorkaround) CreateHttpUrlConnector.booleangetConnector(Client client, Configuration config) Get a Jersey client connector instance for a givenclientinstance and Jersey client runtimeconfiguration.inthashCode()Instruct the provided connectors to use thefixed-length streaming modeon the underlying HTTP URL connection instance when sending requests.Instruct the provided connectors to use reflection when setting the HTTP method value.SeeSET_METHOD_WORKAROUNDproperty documentation for more details.
- 
Field Details- 
USE_FIXED_LENGTH_STREAMINGIftrue, theHttpUrlConnector(if used) will assume the content length from the value of "Content-Length" request header (if present).When this property is enabled and the request has a valid non-zero content length value specified in its "Content-Length" request header, that this value will be used as an input to the HttpURLConnection.setFixedLengthStreamingMode(int)method call invoked on the underlyingconnection. This will also suppress the entity buffering in the @{code HttpURLConnection}, which is undesirable in certain scenarios, e.g. when streaming large entities.Note that the content length value defined in the request header must exactly match the real size of the entity. If the HttpHeaders.CONTENT_LENGTHheader is explicitly specified in a request, this property will be ignored and the request entity will be still buffered by the underlying @{code HttpURLConnection} infrastructure.This property also overrides the behaviour enabled by the ClientProperties.CHUNKED_ENCODING_SIZEproperty. Chunked encoding will only be used, if the size is not specified in the header of the request.Note that this property only applies to client run-times that are configured to use the default HttpUrlConnectoras the client connector. The property is ignored by other connectors.The default value is false.The name of the configuration property is "jersey.config.client.httpUrlConnector.useFixedLengthStreaming". - Since:
- 2.5
- See Also:
 
- 
SET_METHOD_WORKAROUNDA value oftruedeclares that the client will try to set unsupported HTTP method toHttpURLConnectionvia reflection as a workaround for a missing HTTP method.NOTE: Enabling this property may cause security related warnings/errors and it may break when other JDK implementation is used. Use only when you know what you are doing. The value MUST be an instance of Boolean.The default value is false.The name of the configuration property is "jersey.config.client.httpUrlConnection.setMethodWorkaround". Since JDK 16 the JDK internal classes are not opened for reflection and the workaround method does not work, unless --add-opens java.base/java.net=ALL-UNNAMEDfor HTTP requests and additional--add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMEDfor HTTPS (HttpsUrlConnection) options are set.- See Also:
 
 
- 
- 
Constructor Details- 
HttpUrlConnectorProviderpublic HttpUrlConnectorProvider()Create newHttpURLConnection-based Jersey client connector provider.
 
- 
- 
Method Details- 
connectionFactorypublic HttpUrlConnectorProvider connectionFactory(HttpUrlConnectorProvider.ConnectionFactory connectionFactory) Set a customHttpURLConnectionfactory.- Parameters:
- connectionFactory- custom HTTP URL connection factory. Must not be- null.
- Returns:
- updated connector provider instance.
- Throws:
- NullPointerException- in case the supplied connectionFactory is- null.
 
- 
chunkSizeSet chunk size for requests transferred using a HTTP chunked transfer coding. If no value is set, the default chunk size of 4096 bytes will be used.Note that this programmatically set value can be overridden by setting the ClientProperties.CHUNKED_ENCODING_SIZEproperty specified in the Jersey client instance configuration.- Parameters:
- chunkSize- chunked transfer coding chunk size to be used.
- Returns:
- updated connector provider instance.
- Throws:
- IllegalArgumentException- in case the specified chunk size is negative.
 
- 
useFixedLengthStreamingInstruct the provided connectors to use thefixed-length streaming modeon the underlying HTTP URL connection instance when sending requests. SeeUSE_FIXED_LENGTH_STREAMINGproperty documentation for more details.Note that this programmatically set value can be overridden by setting the USE_FIXED_LENGTH_STREAMINGproperty specified in the Jersey client instance configuration.- Returns:
- updated connector provider instance.
 
- 
useSetMethodWorkaroundInstruct the provided connectors to use reflection when setting the HTTP method value.SeeSET_METHOD_WORKAROUNDproperty documentation for more details.Note that this programmatically set value can be overridden by setting the SET_METHOD_WORKAROUNDproperty specified in the Jersey client instance configuration or in the request properties.- Returns:
- updated connector provider instance.
 
- 
getConnectorDescription copied from interface:ConnectorProviderGet a Jersey client connector instance for a givenclientinstance and Jersey client runtimeconfiguration.Note that the supplied runtime configuration can be different from the client instance configuration as a single client can be used to serve multiple differently configured runtimes. While the SSL contextorhostname verifierare shared, other configuration properties may change in each runtime.Based on the supplied client and runtime configuration data, it is up to each connector provider implementation to decide whether a new dedicated connector instance is required or if the existing, previously create connector instance can be reused. - Specified by:
- getConnectorin interface- ConnectorProvider
- Parameters:
- client- Jersey client instance.
- config- Jersey client runtime configuration.
- Returns:
- configured Connectorinstance to be used by the client.
 
- 
createHttpUrlConnectorprotected Connector createHttpUrlConnector(Client client, HttpUrlConnectorProvider.ConnectionFactory connectionFactory, int chunkSize, boolean fixLengthStreaming, boolean setMethodWorkaround) CreateHttpUrlConnector.- Parameters:
- client- JAX-RS client instance for which the connector is being created.
- connectionFactory-- HttpsURLConnectionfactory to be used when creating connections.
- chunkSize- chunk size to use when using HTTP chunked transfer coding.
- fixLengthStreaming- specify if the the- fixed-length streaming modeon the underlying HTTP URL connection instances should be used when sending requests.
- setMethodWorkaround- specify if the reflection workaround should be used to set HTTP URL connection method name. See- SET_METHOD_WORKAROUNDfor details.
- Returns:
- created HttpUrlConnectorinstance.
 
- 
equals
- 
hashCodepublic int hashCode()
 
-