Posted By:
j_gray
Posted On:
Thursday, April 17, 2003 02:06 PM
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 try to connect to the URL that i read in from the header of the first page, 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&
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 try to connect to the URL that i read in from the header of the first page, 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);
//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, and then use a header field containing a URL to redirect to another URL without throwing a SocketException. Thanks in advance for your help Java gurus!
<<Less