Class HttpUrlConnector
- java.lang.Object
-
- org.glassfish.jersey.client.internal.HttpUrlConnector
-
- All Implemented Interfaces:
Connector,Inflector<ClientRequest,ClientResponse>
public class HttpUrlConnector extends java.lang.Object implements Connector
Default client transport connector usingHttpURLConnection.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringALLOW_RESTRICTED_HEADERS_SYSTEM_PROPERTYprivate intchunkSizeprivate HttpUrlConnectorProvider.ConnectionFactoryconnectionFactoryprivate booleanfixLengthStreamingprivate booleanisRestrictedHeaderPropertySetprivate static java.util.logging.LoggerLOGGERprivate static java.lang.String[]restrictedHeadersprivate static java.util.Set<java.lang.String>restrictedHeaderSetprivate booleansetMethodWorkaroundprivate LazyValue<javax.net.ssl.SSLSocketFactory>sslSocketFactory
-
Constructor Summary
Constructors Constructor Description HttpUrlConnector(javax.ws.rs.client.Client client, HttpUrlConnectorProvider.ConnectionFactory connectionFactory, int chunkSize, boolean fixLengthStreaming, boolean setMethodWorkaround)Create newHttpUrlConnectorinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private ClientResponse_apply(ClientRequest request)ClientResponseapply(ClientRequest request)Synchronously process client request into a response.java.util.concurrent.Future<?>apply(ClientRequest request, AsyncConnectorCallback callback)Asynchronously process client request into a response.voidclose()Close connector and release all it's internally associated resources.private static java.io.InputStreamgetInputStream(java.net.HttpURLConnection uc)java.lang.StringgetName()Get name of current connector.private booleanisHeaderRestricted(java.lang.String name, java.lang.String value)protected voidsecureConnection(JerseyClient client, java.net.HttpURLConnection uc)Secure connection if necessary.private voidsetOutboundHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers, java.net.HttpURLConnection uc)private static voidsetRequestMethodViaJreBugWorkaround(java.net.HttpURLConnection httpURLConnection, java.lang.String method)Workaround for a bug inHttpURLConnection.setRequestMethod(String)The implementation of Sun/Oracle is throwing aProtocolExceptionwhen the method is not in the list of the HTTP/1.1 default methods.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
ALLOW_RESTRICTED_HEADERS_SYSTEM_PROPERTY
private static final java.lang.String ALLOW_RESTRICTED_HEADERS_SYSTEM_PROPERTY
- See Also:
- Constant Field Values
-
restrictedHeaders
private static final java.lang.String[] restrictedHeaders
-
restrictedHeaderSet
private static final java.util.Set<java.lang.String> restrictedHeaderSet
-
connectionFactory
private final HttpUrlConnectorProvider.ConnectionFactory connectionFactory
-
chunkSize
private final int chunkSize
-
fixLengthStreaming
private final boolean fixLengthStreaming
-
setMethodWorkaround
private final boolean setMethodWorkaround
-
isRestrictedHeaderPropertySet
private final boolean isRestrictedHeaderPropertySet
-
sslSocketFactory
private final LazyValue<javax.net.ssl.SSLSocketFactory> sslSocketFactory
-
-
Constructor Detail
-
HttpUrlConnector
public HttpUrlConnector(javax.ws.rs.client.Client client, HttpUrlConnectorProvider.ConnectionFactory connectionFactory, int chunkSize, boolean fixLengthStreaming, boolean setMethodWorkaround)Create newHttpUrlConnectorinstance.- 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 thefixed-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. SeeHttpUrlConnectorProvider.SET_METHOD_WORKAROUNDfor details.
-
-
Method Detail
-
getInputStream
private static java.io.InputStream getInputStream(java.net.HttpURLConnection uc) throws java.io.IOException- Throws:
java.io.IOException
-
apply
public ClientResponse apply(ClientRequest request)
Description copied from interface:ConnectorSynchronously process client request into a response. The method is used by Jersey client runtime to synchronously send a request and receive a response.- Specified by:
applyin interfaceConnector- Specified by:
applyin interfaceInflector<ClientRequest,ClientResponse>- Parameters:
request- Jersey client request to be sent.- Returns:
- Jersey client response received for the client request.
-
apply
public java.util.concurrent.Future<?> apply(ClientRequest request, AsyncConnectorCallback callback)
Description copied from interface:ConnectorAsynchronously process client request into a response. The method is used by Jersey client runtime to asynchronously send a request and receive a response.
-
close
public void close()
Description copied from interface:ConnectorClose connector and release all it's internally associated resources.
-
secureConnection
protected void secureConnection(JerseyClient client, java.net.HttpURLConnection uc)
Secure connection if necessary. Provided implementation setsHostnameVerifierandSSLSocketFactoryto give connection, if that is an instance ofHttpsURLConnection.- Parameters:
client- client associated with this client runtime.uc- http connection to be secured.
-
_apply
private ClientResponse _apply(ClientRequest request) throws java.io.IOException
- Throws:
java.io.IOException
-
setOutboundHeaders
private void setOutboundHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers, java.net.HttpURLConnection uc)
-
isHeaderRestricted
private boolean isHeaderRestricted(java.lang.String name, java.lang.String value)
-
setRequestMethodViaJreBugWorkaround
private static void setRequestMethodViaJreBugWorkaround(java.net.HttpURLConnection httpURLConnection, java.lang.String method)Workaround for a bug inHttpURLConnection.setRequestMethod(String)The implementation of Sun/Oracle is throwing aProtocolExceptionwhen the method is not in the list of the HTTP/1.1 default methods. This means that to use e.g.PROPFINDand others, we must apply this workaround. See issue http://java.net/jira/browse/JERSEY-639
-
getName
public java.lang.String getName()
Description copied from interface:ConnectorGet name of current connector. Should contain identification of underlying specification and optionally version number. Will be used in User-Agent header.
-
-