org.springframework.remoting.httpinvoker

Class HttpComponentsHttpInvokerRequestExecutor

    • Constructor Detail

      • HttpComponentsHttpInvokerRequestExecutor

        public HttpComponentsHttpInvokerRequestExecutor()
        Create a new instance of the HttpComponentsHttpInvokerRequestExecutor with a default HttpClient that uses a default org.apache.http.impl.conn.PoolingClientConnectionManager.
      • HttpComponentsHttpInvokerRequestExecutor

        public HttpComponentsHttpInvokerRequestExecutor(HttpClient httpClient)
        Create a new instance of the HttpComponentsClientHttpRequestFactory with the given HttpClient instance.
        Parameters:
        httpClient - the HttpClient instance to use for this request executor
    • Method Detail

      • setHttpClient

        public void setHttpClient(HttpClient httpClient)
        Set the HttpClient instance to use for this request executor.
      • getHttpClient

        public HttpClient getHttpClient()
        Return the HttpClient instance that this request executor uses.
      • setConnectTimeout

        public void setConnectTimeout(int timeout)
        Set the connection timeout for the underlying HttpClient. A timeout value of 0 specifies an infinite timeout.

        Additional properties can be configured by specifying a RequestConfig instance on a custom HttpClient.

        Parameters:
        timeout - the timeout value in milliseconds
        See Also:
        RequestConfig.getConnectTimeout()
      • setConnectionRequestTimeout

        public void setConnectionRequestTimeout(int connectionRequestTimeout)
        Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlying HttpClient. A timeout value of 0 specifies an infinite timeout.

        Additional properties can be configured by specifying a RequestConfig instance on a custom HttpClient.

        Parameters:
        connectionRequestTimeout - the timeout value to request a connection in milliseconds
        See Also:
        RequestConfig.getConnectionRequestTimeout()
      • createHttpPost

        protected HttpPost createHttpPost(HttpInvokerClientConfiguration config)
                                   throws java.io.IOException
        Create a HttpPost for the given configuration.

        The default implementation creates a standard HttpPost with "application/x-java-serialized-object" as "Content-Type" header.

        Parameters:
        config - the HTTP invoker configuration that specifies the target service
        Returns:
        the HttpPost instance
        Throws:
        java.io.IOException - if thrown by I/O methods
      • createRequestConfig

        @Nullable
        protected RequestConfig createRequestConfig(HttpInvokerClientConfiguration config)
        Create a RequestConfig for the given configuration. Can return null to indicate that no custom request config should be set and the defaults of the HttpClient should be used.

        The default implementation tries to merge the defaults of the client with the local customizations of the instance, if any.

        Parameters:
        config - the HTTP invoker configuration that specifies the target service
        Returns:
        the RequestConfig to use
      • setRequestBody

        protected void setRequestBody(HttpInvokerClientConfiguration config,
                                      HttpPost httpPost,
                                      java.io.ByteArrayOutputStream baos)
                               throws java.io.IOException
        Set the given serialized remote invocation as request body.

        The default implementation simply sets the serialized invocation as the HttpPost's request body. This can be overridden, for example, to write a specific encoding and to potentially set appropriate HTTP request headers.

        Parameters:
        config - the HTTP invoker configuration that specifies the target service
        httpPost - the HttpPost to set the request body on
        baos - the ByteArrayOutputStream that contains the serialized RemoteInvocation object
        Throws:
        java.io.IOException - if thrown by I/O methods
      • executeHttpPost

        protected org.apache.http.HttpResponse executeHttpPost(HttpInvokerClientConfiguration config,
                                                               HttpClient httpClient,
                                                               HttpPost httpPost)
                                                        throws java.io.IOException
        Execute the given HttpPost instance.
        Parameters:
        config - the HTTP invoker configuration that specifies the target service
        httpClient - the HttpClient to execute on
        httpPost - the HttpPost to execute
        Returns:
        the resulting HttpResponse
        Throws:
        java.io.IOException - if thrown by I/O methods
      • validateResponse

        protected void validateResponse(HttpInvokerClientConfiguration config,
                                        org.apache.http.HttpResponse response)
                                 throws java.io.IOException
        Validate the given response as contained in the HttpPost object, throwing an exception if it does not correspond to a successful HTTP response.

        Default implementation rejects any HTTP status code beyond 2xx, to avoid parsing the response body and trying to deserialize from a corrupted stream.

        Parameters:
        config - the HTTP invoker configuration that specifies the target service
        response - the resulting HttpResponse to validate
        Throws:
        java.io.IOException - if validation failed
      • getResponseBody

        protected java.io.InputStream getResponseBody(HttpInvokerClientConfiguration config,
                                                      org.apache.http.HttpResponse httpResponse)
                                               throws java.io.IOException
        Extract the response body from the given executed remote invocation request.

        The default implementation simply fetches the HttpPost's response body stream. If the response is recognized as GZIP response, the InputStream will get wrapped in a GZIPInputStream.

        Parameters:
        config - the HTTP invoker configuration that specifies the target service
        httpResponse - the resulting HttpResponse to read the response body from
        Returns:
        an InputStream for the response body
        Throws:
        java.io.IOException - if thrown by I/O methods
        See Also:
        isGzipResponse(org.apache.http.HttpResponse), GZIPInputStream
      • isGzipResponse

        protected boolean isGzipResponse(org.apache.http.HttpResponse httpResponse)
        Determine whether the given response indicates a GZIP response.

        The default implementation checks whether the HTTP "Content-Encoding" header contains "gzip" (in any casing).

        Parameters:
        httpResponse - the resulting HttpResponse to check
        Returns:
        whether the given response indicates a GZIP response