[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12470328
 ] 

Roland Weber commented on HTTPCLIENT-385:
-----------------------------------------

OperatedClientConnection provides direct access to the socket.
ManagedClientConnection currently does not. We might add an optional interface 
to cast down to.
If we do so, we should consider to disable keep-alive (at least by default) for 
a connection with a twisted socket.

cheers,
  Roland



> Access to SO_TIMEOUT for open connections
> -----------------------------------------
>
>                 Key: HTTPCLIENT-385
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-385
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpConn
>    Affects Versions: 3.0 Alpha 2
>         Environment: Operating System: All
> Platform: All
>            Reporter: Gustavo Hexsel
>            Priority: Minor
>             Fix For: 4.0 Alpha 1
>
>
> I'm trying to access a set of pages in order, for which I have a maximum delay
> permissible.  The complete operation includes following all redirects and
> fetching the complete page content.  What I need, which doesn't seem to be
> doable right now (according to the common-users list) is to reset the 
> SO_TIMEOUT
> property of the socket before each read to the inputstream.  I'd need an 
> access
> to the HttpConnection, or a way to set the parameters for that object.
> This is a simplified version of what I'm doing:
> -----
> HttpURL url = new HttpURL(urlString);
> method.setURI(url);
> method.setFollowRedirects(false);
> method.getParams().setSoTimeout(remainingTime);
> HostConfiguration hostConfig = new HostConfiguration();
> hostConfig.setHost(url);
> method.setHostConfiguration(hostConfig);
> timeoutChecker.getRemainingTime());
> int statusCode = client.executeMethod(hostConfig, method, state);
> String pageContent;
> if (isRedirect(statusCode)) {
>     if (timeoutChecker.isTimeout()) {
>         throw new TimeoutException("Total execution time for fetch exceeded
> timeout parameter");
>     } else {
>         Header locationHeader = method.getResponseHeader("location");
>         HttpURL nextLocation = new 
> HttpURL(locationHeader.getValue().toCharArray());
>         pageContent = fetchGet(nextLocation.getEscapedURI(), addressHolder,
> timeoutChecker, state);
>     }
> } else if (isSuccess(statusCode)) {
>     // at least 4K buffers, might be as big as the webpage
>     int responseSize = Math.max(getResponseSize(method), 
> DEFAULT_RESPONSE_SIZE);
>     InputStream response = method.getResponseBodyAsStream();
>     ByteArrayOutputStream outstream = new ByteArrayOutputStream(responseSize);
>     byte[] buffer = new byte[responseSize];
>     int len;
>     do {
>         // ***TODO need to reset the SO_TIMEOUT to the remaining time
>         len = response.read(buffer);
>         outstream.write(buffer, 0, len);
>     while ((len > 0) && !timeoutChecker.isTimeout());
>     outstream.close();
>     pageContent = EncodingUtil.getString(outstream.toByteArray(),
> method.getResponseCharSet());
>     response.close();
> } else {
>     ...
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to