I try to connect to an web application with my JWS application.
I have to use session tracking and therefore I have to read and write the
SessionId.
Every time I try to set the cookie for SessionId get this Exception:
java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:2095)
This is my code:
try
{
URL url = new URL( "http:\\www....." );
conn = ( HttpURLConnection ) url.openConnection();
//!!!!!!!!!!!!!!!!!!!!!!!!!! this is line throws the exception!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
conn.setRequestProperty( "Cookie", "JSESSIONID=aswx12ff3G222c_f" );
conn.connect();
BufferedInputStream inBuf = new BufferedInputStream( conn.getInputStream() );
InputStreamReader inStReader = new InputStreamReader( inBuf, "ISO-8859-1" );
char[] buffer = new char[ 1024 ];
int nbytes;
// Read and write the Data
while ( ( nbytes = inStReader.read( buffer ) ) != -1 )
{
strReturn = strReturn.concat( String.valueOf( buffer, 0, nbytes ) );
}
}
catch ( MalformedURLException e )
{
e.printStackTrace();
}
catch ( IOException ex )
{
ex.printStackTrace();
}
finally
{
conn.disconnect();
}
return strReturn;