HttpComponents HttpClient: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
No edit summary
Line 8: Line 8:
* [[Apache Foundation#Subjects|Apache Foundation]]
* [[Apache Foundation#Subjects|Apache Foundation]]


=Concepts=
=Multithreaded Execution=


* [[HttpComponents HttpClient Concepts]]
{{External|http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e405}}


In order to allow execution of multiple HTTP requests concurrently on multiple threads, httpclient must be equipped with a pooling connection manager such as <tt>PoolingClientConnectionManager</tt>.


!!!Troubleshooting
=Redirect Handling=


{{External|http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e334}}


!!httpclient Automatically Follows Redirects
Turn it off:


Sometimes this is not the behavior you want, for example when you try to get the OAuth token which is embedded in the redirect Location that you are supposed to parse.
<pre>
RedirectStrategy redirectStrategy = new RedirectStrategy() {
    @Override
    public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
        return false;
    }


See [HTTPClientConcepts#Redirect Handling]
    @Override
    public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
        throw new RuntimeException("getRedirect() NOT YET IMPLEMENTED");
    }
};


__Referenced by:__\\
... HttpClients.custom().setRedirectStrategy(redirectStrategy).build();
[{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=20, maxwidth=50}]
</pre>
 
=Troubleshooting=
 
==httpclient Automatically Follows Redirects==
 
Sometimes this is not the behavior you want, for example when you try to get the OAuth token which is embedded in the redirect Location that you are supposed to parse. See [[#Redirect_Handling|Redirect Handling]] above.

Revision as of 17:06, 20 March 2017

External

Internal

Multithreaded Execution

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e405

In order to allow execution of multiple HTTP requests concurrently on multiple threads, httpclient must be equipped with a pooling connection manager such as PoolingClientConnectionManager.

Redirect Handling

http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e334

Turn it off:

RedirectStrategy redirectStrategy = new RedirectStrategy() {
    @Override
    public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
        return false;
    }

    @Override
    public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
        throw new RuntimeException("getRedirect() NOT YET IMPLEMENTED");
    }
};

... HttpClients.custom().setRedirectStrategy(redirectStrategy).build();

Troubleshooting

httpclient Automatically Follows Redirects

Sometimes this is not the behavior you want, for example when you try to get the OAuth token which is embedded in the redirect Location that you are supposed to parse. See Redirect Handling above.