HttpClient with Applet to upload files using MultipartPost is required....
Hi, I got a sample signed applet working that is given at the links you specified. but need help using it with HttpClient... Pl let me know if somebody already worked with applet using HttpClient. thanks. Srinivas. Roland Weber [EMAIL PROTECTED] wrote: Hello Srinivas, java.sun.com seems to be down or overloaded, but I found this link in Google about signed applets: http://www.betrusted.com/downloads/products/keytools/v51/pro/j-docs/html/SampleCodes/sampleApplet/codesign/intro.html Once java.sun.com is back up, these links could be useful for you: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html http://java.sun.com/security/signExample12/ hope that helps, Roland Srinivas Velidanda 07.10.2004 15:33 Please respond to Commons HttpClient Project To [EMAIL PROTECTED] cc Subject Re: HttpClient query... Hi, Greetings. I am running into problems, as you have mentioned, i was trying to work with an Applet. Couldn't set security permissions and even if I set the permissions there could be problems with setting the user credentials. I do not know how I can make the applet access the files at client side. So, pl let me know how can I create a multipart request using HttpClient api or --how can I read the files from the file system once I get the drive and directory names from the client by using javascript, I searched the internet but couldn't find any samples to generate html form using javascript and that must create file items dynamically by reading the files from the file system. I thought of all the options that I could, but not getting a solution, which is very urgent. Pl. suggest me a solution. thanks for the help, Srinivas. Roland Weber wrote: Hello Srinivas, I think some people have succeeded in using HttpClient from an applet. Remember you will have to sign the applet in order to access the client file system. But you could run into problems accessing the user credentials in the applet. You could also try to write JavaScript code which generates an HTML form, including one file element for every file in the directory. In that case, the browser would take care of building the HTTP request and adding user credentials. The problem once more is to access the file system from the script code. Using a combination of both could work out. It is possible to call JavaScript from an applet and vice versa. So you could write (and sign!) an applet that creates a directory listing, then use that listing in JavaScript to create a form which is then posted by the browser to the server. Other ideas? cheers, Roland Srinivas Velidanda 06.10.2004 13:43 Please respond to Commons HttpClient Project To [EMAIL PROTECTED] cc Subject Re: HttpClient query... Hi, Thanks for your help. I found the samples specified by you very much useful. I got it working with my JSP by sending user credential parameters which were required at my server. Now the problem is making the same with an applet as it is not working from remote client accessing the JSP. The flow is like this. I have a screen where I enter drive name, and directory to be uploaded and in the next JSP I get the files of specified folder and create multipart request and send to the server along with User credentials. Everything is working fine on the system which both client and server are running. But If I try the same from remote client then It is looking for files in the folder specified by client in server which is generating null pointer exception. Now I need to make the functionality of creating the multipart request at client side, I am planning to do it in the applet. Is it the right way to go for an applet, or can you suggest me some other solution.. thanks, Srinivas. Roland Weber wrote: Hello Srinivas, you are using HttpClient from within a JSP to connect to the server that is running the JSP? Or to a different server? If you want to set request parameters, you don't do that before creating the multipart request. You create the multipart request, then add the parameters using MP.addParameter(..) or MP.addPart(...). Just make sure to add all required parameters before you *execute* the method. See also the web site at http://jakarta.apache.org/commons/httpclient/methods/multipartpost.html The sample code for multipart file upload is for the 2.0 API, but it should be helpful anyway. Go straight to the actionPerformed method: http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/?only_with_tag=HTTPCLIENT_2_0_BRANCH cheers, Roland Srinivas Velidanda 05.10.2004 14:00 Please respond to Commons HttpClient Project To Commons HttpClient Project cc Subject Re: HttpClient query... Hi Roland, thanks for the reply. I am new to this API and pl let me know how can I do the following. 1. can I set the same parameters coming from the session before creating Multipart request to the Multipart request, if yes, how can I set and
Re: HttpClient with Applet to upload files using MultipartPost is required....
On 08/10/2004, at 4:43 PM, Srinivas Velidanda wrote: Hi, I got a sample signed applet working that is given at the links you specified. but need help using it with HttpClient... Pl let me know if somebody already worked with applet using HttpClient. Hi Srinivas, We use HttpClient extensively from within a signed applet. As long as an applet is correctly signed, it has the same permissions as a stand-alone application. thanks. Srinivas. Regards, Adrian Sutton. -- Intencha tomorrow's technology today Ph: 3420 4584 0422236329 35 Prenzler St Upper Mount Gravatt 4122 Australia QLD www.intencha.com PGP.sig Description: This is a digitally signed message part
Re: HttpClient with Applet to upload files using MultipartPost is required....
Hi, can I get the sample java code to make the signed applet with HttpClient. thanks, Srinivas. Adrian Sutton [EMAIL PROTECTED] wrote: On 08/10/2004, at 4:43 PM, Srinivas Velidanda wrote: Hi, I got a sample signed applet working that is given at the links you specified. but need help using it with HttpClient... Pl let me know if somebody already worked with applet using HttpClient. Hi Srinivas, We use HttpClient extensively from within a signed applet. As long as an applet is correctly signed, it has the same permissions as a stand-alone application. thanks. Srinivas. Regards, Adrian Sutton. -- Intencha tomorrow's technology today Ph: 3420 4584 0422236329 35 Prenzler St Upper Mount Gravatt 4122 Australia QLD www.intencha.com ATTACHMENT part 2 application/pgp-signature x-mac-type=70674453; name=PGP.sig - Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish.
Re: HttpClient with Applet to upload files using MultipartPost is required....
On 08/10/2004, at 5:21 PM, Srinivas Velidanda wrote: Hi, can I get the sample java code to make the signed applet with HttpClient. No unfortunately we develop a commercial product so I can't release the code. However, the usage of HttpClient is exactly the same in an applet as an application. You do however need to make sure the applet is signed and that you are using at least Java 1.3 (ie: you can't be using the Microsoft JVM that is the default in Windows IE). When you load the applet it should bring up a security dialog asking if you want to give the applet permission to run, click yes and you have full permissions. If you don't see that dialog then the applet isn't correctly signed. thanks, Srinivas. Regards, Adrian Sutton -- Intencha tomorrow's technology today Ph: 3420 4584 0422236329 35 Prenzler St Upper Mount Gravatt 4122 Australia QLD www.intencha.com PGP.sig Description: This is a digitally signed message part
Re: HttpClient with Applet to upload files using MultipartPost is required....
Hi Adrian Sutton, thanks for the mail. I need some help regarding using Applet with HttpClient. I am able to make the signed applet get opened in the Internet Explorer, but I got stuck up 1. couldn't grant permissions to read a particular folder at client side. 2. Even If I do that I am not clear with pass the multipart request created in the applet to the servlet. I have been working with it since 1 week but couldn't find the right solution. As far as I know applet can communicate to the servlet using the URLConnection, URLEncoder but how can I make the MultiparPost request linked to the request from applet. Pl. suggest me a solution., thank you, Srinivas. Adrian Sutton [EMAIL PROTECTED] wrote: On 08/10/2004, at 5:21 PM, Srinivas Velidanda wrote: Hi, can I get the sample java code to make the signed applet with HttpClient. No unfortunately we develop a commercial product so I can't release the code. However, the usage of HttpClient is exactly the same in an applet as an application. You do however need to make sure the applet is signed and that you are using at least Java 1.3 (ie: you can't be using the Microsoft JVM that is the default in Windows IE). When you load the applet it should bring up a security dialog asking if you want to give the applet permission to run, click yes and you have full permissions. If you don't see that dialog then the applet isn't correctly signed. thanks, Srinivas. Regards, Adrian Sutton -- Intencha tomorrow's technology today Ph: 3420 4584 0422236329 35 Prenzler St Upper Mount Gravatt 4122 Australia QLD www.intencha.com ATTACHMENT part 2 application/pgp-signature x-mac-type=70674453; name=PGP.sig - Do you Yahoo!? Yahoo! Mail - You care about security. So do we.
[PATCH] ChunkedInputStream no longer requires an HttpMethod parameter
Folks, I would like to make ChunkedInputStream a little more reusable by making HttpMethod parameter optional. Please let me know if you agree/disagree Oleg *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. ***Index: ChunkedInputStream.java === RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v retrieving revision 1.22 diff -u -r1.22 ChunkedInputStream.java --- ChunkedInputStream.java 18 Apr 2004 23:51:34 - 1.22 +++ ChunkedInputStream.java 8 Oct 2004 14:15:54 - @@ -49,7 +49,7 @@ * not requiring the client to remember to read the entire contents of the * response./p * - * @author Ortwin Gl + * @author Ortwin Glueck * @author Sean C. Sullivan * @author Martin Elwin * @author Eric Johnson @@ -80,33 +80,41 @@ private boolean closed = false; /** The method that this stream came from */ -private HttpMethod method; +private HttpMethod method = null; /** Log object for this class. */ private static final Log LOG = LogFactory.getLog(ChunkedInputStream.class); + /** + * ChunkedInputStream constructor * - * - * @param in must be non-null - * @param method must be non-null + * @param in the raw input stream + * @param method the originating HTTP method. Can be ttnull/tt. * * @throws IOException If an IO error occurs */ public ChunkedInputStream( final InputStream in, final HttpMethod method) throws IOException { - if (in == null) { -throw new IllegalArgumentException(InputStream parameter may not be null); - } - if (method == null) { -throw new IllegalArgumentException(HttpMethod parameter may not be null); - } + if (in == null) { + throw new IllegalArgumentException(InputStream parameter may not be null); + } this.in = in; this.method = method; this.pos = 0; } /** + * ChunkedInputStream constructor + * + * @param in the raw input stream + * + * @throws IOException If an IO error occurs + */ +public ChunkedInputStream(final InputStream in) throws IOException { + this(in, null); +} +/** * p Returns all the data in a chunked stream in coalesced form. A chunk * is followed by a CRLF. The method returns -1 as soon as a chunksize of 0 * is detected./p @@ -301,17 +309,21 @@ private void parseTrailerHeaders() throws IOException { Header[] footers = null; try { -footers = HttpParser.parseHeaders(in, -method.getParams().getHttpElementCharset()); +String charset = US-ASCII; +if (this.method != null) { +charset = this.method.getParams().getHttpElementCharset(); +} +footers = HttpParser.parseHeaders(in, charset); } catch(HttpException e) { LOG.error(Error parsing trailer headers, e); IOException ioe = new IOException(e.getMessage()); ExceptionUtil.initCause(ioe, e); throw ioe; } - -for (int i = 0; i footers.length; i++) { -method.addResponseFooter(footers[i]); +if (this.method != null) { +for (int i = 0; i footers.length; i++) { +this.method.addResponseFooter(footers[i]); +} } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
getting through a proxy server
Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting through a proxy server
I believe that your problem is the fact that by calling the GetMethod(url) constructor, you are creating a method with its own host configuration; in this case, the method's host configuration is used when the method is executed (as opposed to the default host configuration that you have created on the connection). In other words, the host, port, and path information for the specific method invocation are extracted from the URL that you used to construct the GetMethod. If you replace this code: client.getHostConfiguration()... with this code: method.getHostConfiguration()... You should be all set. Either that or call the parameter-less GetMethod constructor, which will cause it to default to the host configuration for your client. OR you could call: client.executeMethod( client.getHostConfiguration(), method, client.getState()) That should work, too. Hope that helps, Bob -Original Message- From: Yuzwa, Erik [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 10:53 AM To: 'Commons HttpClient Project' Subject: RE: getting through a proxy server Madeleine, Stupid question but is your proxy server using NTLM authentication? I had to do some hoop jumping to get NTLM to work properly, but it's working now if you need some code. Erik -Original Message- From: Madeleine Wright [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 8:46 AM To: Commons HttpClient Project Subject: getting through a proxy server Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting through a proxy server
Madeleine, If you activate wire/context logging in your application you'll get more details on what exactly goes wrong http://jakarta.apache.org/commons/httpclient/logging.html If you need help reading the log, feel free to post it to this list. Do obfuscate security sensitive bits such as logon credentials prior to posting. Oleg On Fri, 2004-10-08 at 16:45, Madeleine Wright wrote: Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. *** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting through a proxy server
Bob, You are absolutely right about method.getHostConfiguration() taking precedence over client.getHostConfiguration(). However, HttpClient does copy the proxy information from the agent host config to the method host config. So, that should not be the reason for proxy problems Madeleine has been having. We realize this can be horribly confusing. As of release 3.0 the use of HttpMethod#getHostConfiguration() will be deprecated and discouraged Oleg On Fri, 2004-10-08 at 17:01, St Jacques, Robert wrote: I believe that your problem is the fact that by calling the GetMethod(url) constructor, you are creating a method with its own host configuration; in this case, the method's host configuration is used when the method is executed (as opposed to the default host configuration that you have created on the connection). In other words, the host, port, and path information for the specific method invocation are extracted from the URL that you used to construct the GetMethod. If you replace this code: client.getHostConfiguration()... with this code: method.getHostConfiguration()... You should be all set. Either that or call the parameter-less GetMethod constructor, which will cause it to default to the host configuration for your client. OR you could call: client.executeMethod( client.getHostConfiguration(), method, client.getState()) That should work, too. Hope that helps, Bob -Original Message- From: Yuzwa, Erik [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 10:53 AM To: 'Commons HttpClient Project' Subject: RE: getting through a proxy server Madeleine, Stupid question but is your proxy server using NTLM authentication? I had to do some hoop jumping to get NTLM to work properly, but it's working now if you need some code. Erik -Original Message- From: Madeleine Wright [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 8:46 AM To: Commons HttpClient Project Subject: getting through a proxy server Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. *** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting through a proxy server
Hi. Thanks for all the suggestions. I tried replacing client.getHostConfiguration()..with method.getHostConfiguration butit didn't seem to make any difference. I changed method back to client and retried and for the second attempt it did authenticate me - but not for the first. Initially I had this: retryhandler.setRetryCount(3); but then I changed the 3 to 1. Again the first try was refused but the second got through. What I would like to understand is which host configuration is being accessed by client.getHostConfiguration().., the proxy host, the ultimate destination or me?? I was using a logger - and I'm appending the output with the retry at 1 (not that it's any shorter!). Is there something in the order of the code that causes a refusal the first time around that gets fixed the second time? Currently my code (comments stripped out) looks like this: public class MyHttpClient { private static String url = http://www.uct.ac.za/;; public static void main(String[] args) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.getHostConfiguration().setProxy(, ); Credentials creds = new UsernamePasswordCredentials(, ); client.getState().setProxyCredentials(, cache.ru.ac.za, creds); Logger logger = Logger.getLogger(MyHttpClient.class); BasicConfigurator.configure(); logger.info(Entering application.); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRequestSentRetryEnabled(false); retryhandler.setRetryCount(1); method.setMethodRetryHandler(retryhandler); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(Method failed: + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); } catch (IOException e) { System.err.println(Failed to download file.); e.printStackTrace(); } finally { method.releaseConnection(); } } } The error log follows. Thanks so much. Madeleine 468 [main] INFO MyHttpClient - Entering application. 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HttpMethod) 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState) 515 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.open() 547 [main] DEBUG org.apache.commons.httpclient.HttpConnection - HttpConnection.setSoTimeout(0) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.execute(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Execute loop try 1 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.processRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Attempt number 1 to process request 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String) 562 [main] DEBUG httpclient.wire.header - GET http://www.uct.ac.za/ HTTP/1.1[\r][\n] 562 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.print(String) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[]) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[], int, int) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Adding Host request header 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection) 593 [main] DEBUG org.apache.commons.httpclient.HttpState - enter HttpState.getCookies() 593 [main] DEBUG org.apache.commons.httpclient.cookie.CookieSpec - enter CookieSpecBase.match(String, int, String, boolean, Cookie[]) 593 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addAuthorizationRequestHeader(HttpState,
redirect problem in HttpClient
I am getting the following exception for redirect responses from HttpClient. Attached is the log from HttpClient. I know that HttpClient does not support redirect directly, hence we have written some code to handle that. The problem seems to be that, occasionally HttpClient does not send the request body though it writes out the Content-Length header. If you send the same request one after another by starting a new JVM for each request, such as running a client from commandline, you will see that, it sends the request body for a few times and then it does not send it once and then it starts to send it again. This behavior keeps repeating. Below is the request sent out by HttpClient and response received by it, captured through a tunnel. I will appreciate if someone can explain the behavior. Exception in thread main java.rmi.RemoteException: java.net.SocketException: S oftware caused connection abort: recv failed; nested exception is: org.apache.commons.httpclient.HttpRecoverableException: java.net.SocketE xception: Software caused connection abort: recv failed at com.sssw.jbroker.web.ServiceException.mapToRemote(ServiceException.ja va:92) at hello.HelloBinding_Stub.sayHello(HelloBinding_Stub.java:85) at hello.Client.main(Client.java:25) Caused by: org.apache.commons.httpclient.HttpRecoverableException: java.net.Sock etException: Software caused connection abort: recv failed at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB ase.java:1965) at org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMetho dBase.java:2659) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j ava:1093) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:675) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:558) Request going out from HttpClient: POST /services/hello HTTP/1.1 SOAPAction: http://www.hello/sayHello; Content-Type: text/xml; charset=utf-8 Connection: keep-alive User-Agent: Jakarta Commons-HttpClient/2.0final Host: 840serv7:54892 Content-Length: 421 Response received by HttpClient: HTTP/1.1 307 redirected Set-Cookie: dispatch-http-rt=840serv7:80; path=/; Content-Length: 0 Location: http://840serv7:80/services/hello Thanks, Zulfi [DEBUG] HttpConnection - -HttpConnection.setSoTimeout(0) [DEBUG] wire - - POST /services/hello HTTP/1.1[\r][\n] [DEBUG] wire - - SOAPAction: http://www.hello/sayHello[\r][\n]; [DEBUG] wire - - Content-Type: text/xml; charset=utf-8[\r][\n] [DEBUG] wire - - Connection: keep-alive[\r][\n] [DEBUG] wire - - User-Agent: Jakarta Commons-HttpClient/2.0final[\r][\n] [DEBUG] wire - - Host: localhost:[\r][\n] [DEBUG] wire - - Content-Length: 421[\r][\n] [DEBUG] wire - - [\r][\n] [DEBUG] wire - - SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.or g/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http:/ /www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/ soap/encoding/'SOAP-ENV:Bodyns1:sayHello SOAP-ENV:encodingStyle='http://sche mas.xmlsoap.org/soap/encoding/' xmlns='' xmlns:ns1='http://www.hello'/ns1:sayH ello/SOAP-ENV:Body/SOAP-ENV:Envelope - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting through a proxy server
Progress - just moved the GetMethod constructor down below the logging details. Now, though I still get a cache MISS at first, I don't get an authentication refusal. I also tried moving the credential details higher than the host configuration, but that didn't make any difference. Madeleine Oleg Kalnichevski wrote: Bob, You are absolutely right about method.getHostConfiguration() taking precedence over client.getHostConfiguration(). However, HttpClient does copy the proxy information from the agent host config to the method host config. So, that should not be the reason for proxy problems Madeleine has been having. We realize this can be horribly confusing. As of release 3.0 the use of HttpMethod#getHostConfiguration() will be deprecated and discouraged Oleg On Fri, 2004-10-08 at 17:01, St Jacques, Robert wrote: I believe that your problem is the fact that by calling the GetMethod(url) constructor, you are creating a method with its own host configuration; in this case, the method's host configuration is used when the method is executed (as opposed to the default host configuration that you have created on the connection). In other words, the host, port, and path information for the specific method invocation are extracted from the URL that you used to construct the GetMethod. If you replace this code: client.getHostConfiguration()... with this code: method.getHostConfiguration()... You should be all set. Either that or call the parameter-less GetMethod constructor, which will cause it to default to the host configuration for your client. OR you could call: client.executeMethod( client.getHostConfiguration(), method, client.getState()) That should work, too. Hope that helps, Bob -Original Message- From: Yuzwa, Erik [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 10:53 AM To: 'Commons HttpClient Project' Subject: RE: getting through a proxy server Madeleine, Stupid question but is your proxy server using NTLM authentication? I had to do some hoop jumping to get NTLM to work properly, but it's working now if you need some code. Erik -Original Message- From: Madeleine Wright [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 8:46 AM To: Commons HttpClient Project Subject: getting through a proxy server Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. *** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting through a proxy server
Hi Madeleine, The first request fails because the credentials are not sent on the first method execution. This is for two reasons. One, because the proxy credentials have been specified with a particular realm. HttpClient does not know that a URL is protected by a particular realm until is tries and fails. Also, HttpClient by default does not include credentials in requests except when challenged or when preemptive authentication has been turned on. You should be able to fix this problem by doing the following: // use a null realm client.getState().setProxyCredentials(null, cache.ru.ac.za, creds); // enable preemptive authentication client.getState().setAuthenticationPreemptive(true); Mike Madeleine Wright wrote: Hi. Thanks for all the suggestions. I tried replacing client.getHostConfiguration()..with method.getHostConfiguration butit didn't seem to make any difference. I changed method back to client and retried and for the second attempt it did authenticate me - but not for the first. Initially I had this: retryhandler.setRetryCount(3); but then I changed the 3 to 1. Again the first try was refused but the second got through. What I would like to understand is which host configuration is being accessed by client.getHostConfiguration().., the proxy host, the ultimate destination or me?? I was using a logger - and I'm appending the output with the retry at 1 (not that it's any shorter!). Is there something in the order of the code that causes a refusal the first time around that gets fixed the second time? Currently my code (comments stripped out) looks like this: public class MyHttpClient { private static String url = http://www.uct.ac.za/;; public static void main(String[] args) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.getHostConfiguration().setProxy(, ); Credentials creds = new UsernamePasswordCredentials(, ); client.getState().setProxyCredentials(, cache.ru.ac.za, creds); Logger logger = Logger.getLogger(MyHttpClient.class); BasicConfigurator.configure(); logger.info(Entering application.); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRequestSentRetryEnabled(false); retryhandler.setRetryCount(1); method.setMethodRetryHandler(retryhandler); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(Method failed: + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); } catch (IOException e) { System.err.println(Failed to download file.); e.printStackTrace(); } finally { method.releaseConnection(); } } } The error log follows. Thanks so much. Madeleine 468 [main] INFO MyHttpClient - Entering application. 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HttpMethod) 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState) 515 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.open() 547 [main] DEBUG org.apache.commons.httpclient.HttpConnection - HttpConnection.setSoTimeout(0) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.execute(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Execute loop try 1 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.processRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Attempt number 1 to process request 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String) 562 [main] DEBUG httpclient.wire.header - GET http://www.uct.ac.za/ HTTP/1.1[\r][\n] 562 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.print(String) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[]) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[], int, int) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addUserAgentRequestHeaders(HttpState,
Re: getting through a proxy server
Also, preemptive authentication is covered in more detail at http://jakarta.apache.org/commons/httpclient/authentication.html. Mike Madeleine Wright wrote: Hi. Thanks for all the suggestions. I tried replacing client.getHostConfiguration()..with method.getHostConfiguration butit didn't seem to make any difference. I changed method back to client and retried and for the second attempt it did authenticate me - but not for the first. Initially I had this: retryhandler.setRetryCount(3); but then I changed the 3 to 1. Again the first try was refused but the second got through. What I would like to understand is which host configuration is being accessed by client.getHostConfiguration().., the proxy host, the ultimate destination or me?? I was using a logger - and I'm appending the output with the retry at 1 (not that it's any shorter!). Is there something in the order of the code that causes a refusal the first time around that gets fixed the second time? Currently my code (comments stripped out) looks like this: public class MyHttpClient { private static String url = http://www.uct.ac.za/;; public static void main(String[] args) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.getHostConfiguration().setProxy(, ); Credentials creds = new UsernamePasswordCredentials(, ); client.getState().setProxyCredentials(, cache.ru.ac.za, creds); Logger logger = Logger.getLogger(MyHttpClient.class); BasicConfigurator.configure(); logger.info(Entering application.); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRequestSentRetryEnabled(false); retryhandler.setRetryCount(1); method.setMethodRetryHandler(retryhandler); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(Method failed: + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); } catch (IOException e) { System.err.println(Failed to download file.); e.printStackTrace(); } finally { method.releaseConnection(); } } } The error log follows. Thanks so much. Madeleine 468 [main] INFO MyHttpClient - Entering application. 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HttpMethod) 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState) 515 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.open() 547 [main] DEBUG org.apache.commons.httpclient.HttpConnection - HttpConnection.setSoTimeout(0) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.execute(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Execute loop try 1 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.processRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Attempt number 1 to process request 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String) 562 [main] DEBUG httpclient.wire.header - GET http://www.uct.ac.za/ HTTP/1.1[\r][\n] 562 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.print(String) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[]) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[], int, int) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Adding Host request header 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection) 593 [main] DEBUG org.apache.commons.httpclient.HttpState - enter HttpState.getCookies() 593 [main] DEBUG org.apache.commons.httpclient.cookie.CookieSpec - enter CookieSpecBase.match(String, int,
Re: getting through a proxy server
Hi, Mike. Thanks so much. That solved it! I originally had the ..setAuthenticationPreemptive(true)..bit but had taken it out because it didn't seem to work earlier. The explanations were really helpful too. This is an incredibly helpful list! Madeleine Michael Becke wrote: Hi Madeleine, The first request fails because the credentials are not sent on the first method execution. This is for two reasons. One, because the proxy credentials have been specified with a particular realm. HttpClient does not know that a URL is protected by a particular realm until is tries and fails. Also, HttpClient by default does not include credentials in requests except when challenged or when preemptive authentication has been turned on. You should be able to fix this problem by doing the following: // use a null realm client.getState().setProxyCredentials(null, cache.ru.ac.za, creds); // enable preemptive authentication client.getState().setAuthenticationPreemptive(true); Mike - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
DO NOT REPLY [Bug 31606] New: - Access to SO_TIMEOUT for open connections
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT http://issues.apache.org/bugzilla/show_bug.cgi?id=31606. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://issues.apache.org/bugzilla/show_bug.cgi?id=31606 Access to SO_TIMEOUT for open connections Summary: Access to SO_TIMEOUT for open connections Product: Commons Version: 3.0 Alpha 2 Platform: All OS/Version: All Status: NEW Severity: Enhancement Priority: Other Component: HttpClient AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] 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 { ... } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: redirect problem in HttpClient
Zulfi HttpRecoverableException: Software caused connection abort: recv failed usually means that the connection was closed on the server side while HttpClient was still reading the response. The is more likely to be the server side problem. What exactly do you mean by occasionally HttpClient does not send the request body. Does it throw an exception, or blocks, or something else? Oleg On Fri, 2004-10-08 at 19:53, Zulfi Umrani wrote: I am getting the following exception for redirect responses from HttpClient. Attached is the log from HttpClient. I know that HttpClient does not support redirect directly, hence we have written some code to handle that. The problem seems to be that, occasionally HttpClient does not send the request body though it writes out the Content-Length header. If you send the same request one after another by starting a new JVM for each request, such as running a client from commandline, you will see that, it sends the request body for a few times and then it does not send it once and then it starts to send it again. This behavior keeps repeating. Below is the request sent out by HttpClient and response received by it, captured through a tunnel. I will appreciate if someone can explain the behavior. Exception in thread main java.rmi.RemoteException: java.net.SocketException: S oftware caused connection abort: recv failed; nested exception is: org.apache.commons.httpclient.HttpRecoverableException: java.net.SocketE xception: Software caused connection abort: recv failed at com.sssw.jbroker.web.ServiceException.mapToRemote(ServiceException.ja va:92) at hello.HelloBinding_Stub.sayHello(HelloBinding_Stub.java:85) at hello.Client.main(Client.java:25) Caused by: org.apache.commons.httpclient.HttpRecoverableException: java.net.Sock etException: Software caused connection abort: recv failed at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB ase.java:1965) at org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMetho dBase.java:2659) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j ava:1093) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:675) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:558) Request going out from HttpClient: POST /services/hello HTTP/1.1 SOAPAction: http://www.hello/sayHello; Content-Type: text/xml; charset=utf-8 Connection: keep-alive User-Agent: Jakarta Commons-HttpClient/2.0final Host: 840serv7:54892 Content-Length: 421 Response received by HttpClient: HTTP/1.1 307 redirected Set-Cookie: dispatch-http-rt=840serv7:80; path=/; Content-Length: 0 Location: http://840serv7:80/services/hello Thanks, Zulfi __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: redirect problem in HttpClient
Zulfi, My only guess is that this is a thread synchronization related problem, as the problem appears to be irregular. How do you set the request body? As an InputStream? How do you set the content length? Explicitly or as CONTENT_LENGTH_AUTO? Can it be that the input stream is exhausted before HttpClient has a chance to send its content across the wire? Can you send me the context/wire log for the HTTP transaction in question? Oleg On Fri, 2004-10-08 at 22:10, Zulfi Umrani wrote: Hi Oleg, Yes, the connection is closed by the server. But it is closed because the HttpClient did not send it the request BODY. The problem is that occasionally HttpClient does not send the request as I described. For a few times, it does send the request and then it just doesnt send it, but only once. And then it is back to sending request body. The server tries to read the body but can not, hence it closes the connection for the reuqest which had no body and had Content-Length header value 1. I have sent you the reuqest in error from the tunnel. Looks like it sent the Content-Length header, but not the body of the request. Hope this helps, Zulfi [EMAIL PROTECTED] 10/8/2004 12:46:04 PM Zulfi HttpRecoverableException: Software caused connection abort: recv failed usually means that the connection was closed on the server side while HttpClient was still reading the response. The is more likely to be the server side problem. What exactly do you mean by occasionally HttpClient does not send the request body. Does it throw an exception, or blocks, or something else? Oleg On Fri, 2004-10-08 at 19:53, Zulfi Umrani wrote: I am getting the following exception for redirect responses from HttpClient. Attached is the log from HttpClient. I know that HttpClient does not support redirect directly, hence we have written some code to handle that. The problem seems to be that, occasionally HttpClient does not send the request body though it writes out the Content-Length header. If you send the same request one after another by starting a new JVM for each request, such as running a client from commandline, you will see that, it sends the request body for a few times and then it does not send it once and then it starts to send it again. This behavior keeps repeating. Below is the request sent out by HttpClient and response received by it, captured through a tunnel. I will appreciate if someone can explain the behavior. Exception in thread main java.rmi.RemoteException: java.net.SocketException: S oftware caused connection abort: recv failed; nested exception is: org.apache.commons.httpclient.HttpRecoverableException: java.net.SocketE xception: Software caused connection abort: recv failed at com.sssw.jbroker.web.ServiceException.mapToRemote(ServiceException.ja va:92) at hello.HelloBinding_Stub.sayHello(HelloBinding_Stub.java:85) at hello.Client.main(Client.java:25) Caused by: org.apache.commons.httpclient.HttpRecoverableException: java.net.Sock etException: Software caused connection abort: recv failed at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB ase.java:1965) at org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMetho dBase.java:2659) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j ava:1093) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:675) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:558) Request going out from HttpClient: POST /services/hello HTTP/1.1 SOAPAction: http://www.hello/sayHello; Content-Type: text/xml; charset=utf-8 Connection: keep-alive User-Agent: Jakarta Commons-HttpClient/2.0final Host: 840serv7:54892 Content-Length: 421 Response received by HttpClient: HTTP/1.1 307 redirected Set-Cookie: dispatch-http-rt=840serv7:80; path=/; Content-Length: 0 Location: http://840serv7:80/services/hello Thanks, Zulfi __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: redirect problem in HttpClient
Hi Oleg, I am setting the request body as InputStream, but I do set the Content-Length header as well. I do print out the bytes for body as string before I call executeMethod and I do see the body being printed even for the transaction in question. The InputStream for body is created out of those bytes. I have enabled full wire(header and content) + context logging by setting the following properties. Log is once again attahced for the transaction in question. Let me know if I have to set some other property as well. System.setProperty(org.apache.commons.logging.Log, org.apache.commons.logging.impl.SimpleLog); System.setProperty(org.apache.commons.logging.simplelog.showdatetime, true); System.setProperty(org.apache.commons.logging.simplelog.log.httpclient.wire, debug); System.setProperty(org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient, debug); Thanks, Zulfi [EMAIL PROTECTED] 10/8/2004 1:25:07 PM Zulfi, My only guess is that this is a thread synchronization related problem, as the problem appears to be irregular. How do you set the request body? As an InputStream? How do you set the content length? Explicitly or as CONTENT_LENGTH_AUTO? Can it be that the input stream is exhausted before HttpClient has a chance to send its content across the wire? Can you send me the context/wire log for the HTTP transaction in question? Oleg On Fri, 2004-10-08 at 22:10, Zulfi Umrani wrote: Hi Oleg, Yes, the connection is closed by the server. But it is closed because the HttpClient did not send it the request BODY. The problem is that occasionally HttpClient does not send the request as I described. For a few times, it does send the request and then it just doesnt send it, but only once. And then it is back to sending request body. The server tries to read the body but can not, hence it closes the connection for the reuqest which had no body and had Content-Length header value 1. I have sent you the reuqest in error from the tunnel. Looks like it sent the Content-Length header, but not the body of the request. Hope this helps, Zulfi [EMAIL PROTECTED] 10/8/2004 12:46:04 PM Zulfi HttpRecoverableException: Software caused connection abort: recv failed usually means that the connection was closed on the server side while HttpClient was still reading the response. The is more likely to be the server side problem. What exactly do you mean by occasionally HttpClient does not send the request body. Does it throw an exception, or blocks, or something else? Oleg On Fri, 2004-10-08 at 19:53, Zulfi Umrani wrote: I am getting the following exception for redirect responses from HttpClient. Attached is the log from HttpClient. I know that HttpClient does not support redirect directly, hence we have written some code to handle that. The problem seems to be that, occasionally HttpClient does not send the request body though it writes out the Content-Length header. If you send the same request one after another by starting a new JVM for each request, such as running a client from commandline, you will see that, it sends the request body for a few times and then it does not send it once and then it starts to send it again. This behavior keeps repeating. Below is the request sent out by HttpClient and response received by it, captured through a tunnel. I will appreciate if someone can explain the behavior. Exception in thread main java.rmi.RemoteException: java.net.SocketException: S oftware caused connection abort: recv failed; nested exception is: org.apache.commons.httpclient.HttpRecoverableException: java.net.SocketE xception: Software caused connection abort: recv failed at com.sssw.jbroker.web.ServiceException.mapToRemote(ServiceException.ja va:92) at hello.HelloBinding_Stub.sayHello(HelloBinding_Stub.java:85) at hello.Client.main(Client.java:25) Caused by: org.apache.commons.httpclient.HttpRecoverableException: java.net.Sock etException: Software caused connection abort: recv failed at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB ase.java:1965) at org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMetho dBase.java:2659) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j ava:1093) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:675) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav a:558) Request going out from HttpClient: POST /services/hello HTTP/1.1 SOAPAction: http://www.hello/sayHello; Content-Type: text/xml; charset=utf-8 Connection: keep-alive User-Agent: Jakarta Commons-HttpClient/2.0final Host: 840serv7:54892 Content-Length: 421 Response received by HttpClient: HTTP/1.1 307 redirected Set-Cookie: dispatch-http-rt=840serv7:80; path=/;
DO NOT REPLY [Bug 31607] New: - Catch SocketTimeoutException not InterruptedIOException
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT http://issues.apache.org/bugzilla/show_bug.cgi?id=31607. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://issues.apache.org/bugzilla/show_bug.cgi?id=31607 Catch SocketTimeoutException not InterruptedIOException Summary: Catch SocketTimeoutException not InterruptedIOException Product: Commons Version: 3.0 Alpha 2 Platform: All OS/Version: Other Status: NEW Severity: Blocker Priority: Other Component: HttpClient AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] There are a couple of places where you're catching InterruptedIOException that should catch SocketTimeoutException instead. For example, from HttpConnection: protected boolean isStale() { boolean isStale = true; if (isOpen) { // the connection is open, but now we have to see if we can read it // assume the connection is not stale. isStale = false; try { if (inputStream.available() == 0) { try { socket.setSoTimeout(1); inputStream.mark(1); int byteRead = inputStream.read(); if (byteRead == -1) { // again - if the socket is reporting all data read, // probably stale isStale = true; } else { inputStream.reset(); } } finally { socket.setSoTimeout(this.params.getSoTimeout()); } } } catch (InterruptedIOException e) { // aha - the connection is NOT stale - continue on! Here the catch of InterruptedIOException is intended to happen when inputStream.read() terminates due to the socket.setSoTimeout() time being reached. However, it could also occur because Thread.interrupt() has been called, in which case continue on is not what should happen, instead, the request should terminate. There are legitimate reasons why someone might want to interrupt the httpclient code, for example, httpclient does not provide a hard timeout on the total length of time a request may take, including connecting, sending the request, and receiving the complete response, so to enforce a hard timeout it is necessary to run the request in a worker thread and interrupt it if it hasn't completed before the timeout expires (the technique used in your TimeoutController class). Note that SocketTimeoutException was added in 1.4. For compatibility with older jdk versions, the code can catch InterruptedIOException and use getClass() to see whether it is a SocketTimeoutException. There are probably other places in the code where InterruptedIOException is caught and interpreted as a socket timeout, and where Thread.interrupt() will not have the proper effect of causing the request to terminate ASAP, but I'm not familiar enough with the code to find them all. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]