File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes how to set JSESSIONID to second request,which is getting from first respone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how to set JSESSIONID to second request,which is getting from first respone" Watch "how to set JSESSIONID to second request,which is getting from first respone" New topic
Author

how to set JSESSIONID to second request,which is getting from first respone

mika singh
Greenhorn

Joined: Aug 22, 2011
Posts: 9
Hi,

I am able to create a connection using HttpUrlConnection and getting JSessionID. After that I set that value in request header like
connection.addRequestProperty("Cookie", session); here session is JSESSIONID=D1EA46859B6BC9C488A7A29F5AEE2521;
But it is throwing
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
Exception. Please let me know, how to set JSESSIONID to sencond request.
Thanks in Advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

You don't need to do anything yourself, except start using a CookieHandler. Even that is really easy:
That's enough for simple solutions. It will use an in-memory CookieStore, and a CookiePolicy.ACCEPT_ORIGINAL_SERVER as the CookiePolicy. You can change both if you want or need to; for instance, a custom CookieStore implementation that uses the file system or a database to store the cookies, and CookiePolicy.ACCEPT_ALL to accept all cookies.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to set JSESSIONID to second request,which is getting from first respone