How to share a single http session across multiple http posts
Hi, I have a need where I need to do multiple separate posts to a URL but need all the posts to share the same session context. I am able to do the initial login to a URL successfully as shown below. It is unclear to me how to reuse any instances or set some parameters to make sure that all subsequent posts are for the same session. The behavior I need is approximately like that of a browser. Can someone provide any pointers ? Sincerely, -Mohsin ps: My webserver is running jetty4.2.19 on WinXP under jdk1.4.2 HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, http); httpClient.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); NameValuePair msgTransaction = new NameValuePair(XML, LOGIN_XML); PostMethod postMethod = new PostMethod(SERVER_URL); postMethod.setRequestHeader(Content-type, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE); postMethod.setUseExpectHeader(true); postMethod.setHttp11(false); postMethod.addParameter(msgTransaction); try { int statusCode = httpClient.executeMethod(postMethod); String response = new String(postMethod.getResponseBody(), postMethod.getResponseCharSet()); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } finally { postMethod.releaseConnection(); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to share a single http session across multiple http posts
Hi, Never mind my email. I was posting to an incorrect URL that is why, I was not able to share sessions with any subsequent posts, using the same httpclient instance. Sincerely, -Mohsin -Original Message- From: Beg, Mohsin [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 13, 2004 1:22 AM To: '[EMAIL PROTECTED]' Subject: How to share a single http session across multiple http posts Hi, I have a need where I need to do multiple separate posts to a URL but need all the posts to share the same session context. I am able to do the initial login to a URL successfully as shown below. It is unclear to me how to reuse any instances or set some parameters to make sure that all subsequent posts are for the same session. The behavior I need is approximately like that of a browser. Can someone provide any pointers ? Sincerely, -Mohsin ps: My webserver is running jetty4.2.19 on WinXP under jdk1.4.2 HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, http); httpClient.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); NameValuePair msgTransaction = new NameValuePair(XML, LOGIN_XML); PostMethod postMethod = new PostMethod(SERVER_URL); postMethod.setRequestHeader(Content-type, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE); postMethod.setUseExpectHeader(true); postMethod.setHttp11(false); postMethod.addParameter(msgTransaction); try { int statusCode = httpClient.executeMethod(postMethod); String response = new String(postMethod.getResponseBody(), postMethod.getResponseCharSet()); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } finally { postMethod.releaseConnection(); } - 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]
UTF-8 Encoding Enquiry
Hi~! Thanks in advance for those who will be looking into my problem. I am having difficulty in sending chinese characters via postmethod. // Create an instance of HttpClient HttpClient httpclient = new HttpClient(); // Create a method instance PostMethod postmethod = new PostMethod(url); // Assign parameters into post method Iterator it = paramList.keySet().iterator(); while (it.hasNext()) { String paramName = (String) it.next(); postmethod.addParameter(paramName, new String(((String) paramList.get(paramName)).getBytes(UTF-8),UTF-8)); } With the above codes I succeeded in sending out the postmethod with the list of parameters. But all chinese characters become ? upon received by back-end. Therefor I add this: // Set request header - character set postmethod.setRequestHeader(Content-Type, text/plain; charset=utf-8); With the above lines added, the back-end server could receive the postmethod request but can only find an empty parameter list. The back-end server is indeed a servlet resided on websphere 5 server. The codes to get the one of the parameter is: request.setCharacterEncoding(UTF-8); String inXMLMessage = (String) request.getParameter(xmlmessage); Since the parameter list become empty the above method failed. Therefore I switched to another method - to get the entire request body with input stream and added the following codes: if (inXMLMessage == null) inXMLMessage = getXMLMessageFromInputStream (request.getInputStream()); .. public String getXMLMessageFromInputStream (InputStream requestIS) { String XMLMessage = ; try { InputStreamReader isr = new InputStreamReader(requestIS, UTF-8); BufferedReader r = new BufferedReader(isr); XMLMessage = r.readLine(); XMLMessage = URLDecoder.decode(XMLMessage); XMLMessage = XMLMessage.substring(11); } catch (Exception ex) {...} return XMLMessage; } With the above I succeeded to get the parameter I want, i.e. an xml message, from the input stream, but the entire message are escaped, that is space and tab become +, become %3C, etc. Thaz why I need to use URLDecoder . But the worst part is that all chinese charaters become weird codes like aelig;cedil;not;egrave;copy;brvbar;, which should be in traditional chinese. I am really at my wits end as to what is happening here. Would somebody throw a light upon my proble? A thousand thanks in advance! Regards Ramiel Fong - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: UTF-8 Encoding Enquiry
Ramiel, I think you came pretty close. Two things require minor corrections (1) Content-Type HTTP POST per default uses so called URL encoding when submitting HTML forms. Setting the content type to 'text/plain' may cause some web servers to misinterpret the request parameters Try this instead postmethod.setRequestHeader( Content-Type, application/x-www-form-urlencoded; charset=utf-8); (2) Request parameters This operation is completely redundant new String(((String) paramList.get(paramName)).getBytes(UTF-8),UTF-8) As far as I understand it produces exactly the same Unicode string // Assign parameters into post method Iterator it = paramList.keySet().iterator(); while (it.hasNext()) { String paramName = (String) it.next(); postmethod.addParameter(paramName, paramList.get(paramName)); } HttpClient will do all the charset conversion for you. Just make sure the charser attribute of the Content-Type is set For details please refer to the HttpClient encoding guide http://jakarta.apache.org/commons/httpclient/charencodings.html Hope this helps Oleg On Wed, 2004-10-13 at 13:22, Ramiel Fong wrote: Hi~! Thanks in advance for those who will be looking into my problem. I am having difficulty in sending chinese characters via postmethod. // Create an instance of HttpClient HttpClient httpclient = new HttpClient(); // Create a method instance PostMethod postmethod = new PostMethod(url); // Assign parameters into post method Iterator it = paramList.keySet().iterator(); while (it.hasNext()) { String paramName = (String) it.next(); postmethod.addParameter(paramName, new String(((String) paramList.get(paramName)).getBytes(UTF-8),UTF-8)); } With the above codes I succeeded in sending out the postmethod with the list of parameters. But all chinese characters become ? upon received by back-end. Therefor I add this: // Set request header - character set postmethod.setRequestHeader(Content-Type, text/plain; charset=utf-8); With the above lines added, the back-end server could receive the postmethod request but can only find an empty parameter list. The back-end server is indeed a servlet resided on websphere 5 server. The codes to get the one of the parameter is: request.setCharacterEncoding(UTF-8); String inXMLMessage = (String) request.getParameter(xmlmessage); Since the parameter list become empty the above method failed. Therefore I switched to another method - to get the entire request body with input stream and added the following codes: if (inXMLMessage == null) inXMLMessage = getXMLMessageFromInputStream (request.getInputStream()); .. public String getXMLMessageFromInputStream (InputStream requestIS) { String XMLMessage = ; try { InputStreamReader isr = new InputStreamReader(requestIS, UTF-8); BufferedReader r = new BufferedReader(isr); XMLMessage = r.readLine(); XMLMessage = URLDecoder.decode(XMLMessage); XMLMessage = XMLMessage.substring(11); } catch (Exception ex) {...} return XMLMessage; } With the above I succeeded to get the parameter I want, i.e. an xml message, from the input stream, but the entire message are escaped, that is space and tab become +, become %3C, etc. Thaz why I need to use URLDecoder . But the worst part is that all chinese charaters become weird codes like aelig;cedil;not;egrave;copy;brvbar;, which should be in traditional chinese. I am really at my wits end as to what is happening here. Would somebody throw a light upon my proble? A thousand thanks in advance! Regards Ramiel Fong - 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]
DO NOT REPLY [Bug 31607] - 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 --- Additional Comments From [EMAIL PROTECTED] 2004-10-13 20:31 --- The patch appears to be correct. But I haven't had time to check through the entire execution path of the code I'm using. And I haven't had a chance to contrive a test scenario. But it does look good enough for alpha, thanks! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
DO NOT REPLY [Bug 31680] - DefaultHttpParamsFactory.getDefaultParams() is not thread safe
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=31680. 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=31680 DefaultHttpParamsFactory.getDefaultParams() is not thread safe --- Additional Comments From [EMAIL PROTECTED] 2004-10-13 20:37 --- Yes, calling createParams() twice is ok. This is a bug about assigning to a reference variable which is shared between threads without using synchronization. That can have what the Java Language Specification Chapter 17 calls surprising consequences. Thanks for synchronizing it. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]