dcsimg
"Socket closed" when trying to open DataInputStream!?!
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   j_gray
Posted On:   Friday, April 18, 2003 07:20 AM

i have some java client code that uses URLConnection with JSSE (System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol") to establish an SSL connection to a secure server. After i connect to the secure server i need to read a header field (redirectURL) into my code. I can do all of this no problem, but when i connect to the URL that i read in from the header of the first page and try to create a DataInputStream, i get a "java.net.SocketException: Socket closed" message back in my Java Console. here's the applicable code: System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); System.setPr   More>>

i have some java client code that uses URLConnection with JSSE (System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol") to establish an SSL connection to a secure server. After i connect to the secure server i need to read a header field (redirectURL) into my code. I can do all of this no problem, but when i connect to the URL that i read in from the header of the first page and try to create a DataInputStream, i get a "java.net.SocketException: Socket closed" message back in my Java Console.

here's the applicable code:

			

System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");


System.setProperty("javax.net.debug", "all");


db.recycle();


byte b;


URL sourceURL = new URL(theurl);


File destinationFile = new File(fileName);


String userPassword = theUsername + ":" + thePassword;


String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());


URLConnection uc = sourceURL.openConnection();


uc.setRequestProperty ("Authorization", "Basic " + encoding);


String headfield = uc.getHeaderField(5);


//the value of the header field that I capture is "https://query.lotus.com/@@4WzQw4cAxGBGwuA87*rNhwcAWFByCRoA/psptreseller/bin/pspt_rsel.cgi"


//System.out.println(headfield);


String nexturlstring = headfield; //this is the redirect URL string


URL nextURL = new URL(nexturlstring);


//System.out.println("pre next connect");


URLConnection nextuc = nextURL.openConnection();


nextuc.setRequestProperty ("Authorization", "Basic " + encoding);



System.out.println("get datainputstream");



//HERE'S WHERE THE EXCEPTION IS THROWN!!!


DataInputStream dataIn = new DataInputStream(nextuc.getInputStream());

System.out.println("get dataoutputstream");


DataOutputStream dataOut = new DataOutputStream(new FileOutputStream(destinationFile));



I'm not a heavy Java programmer, so there may be a simple solution that I'm overlooking. So, in a nutshell, can you create an SSL connection to a server, read in a header field containing a URL from the first secure page & then redirect to that URL without throwing a SocketException. Thanks in advance for your help Java gurus!

   <<Less
About | Sitemap | Contact