Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.net.SocketException: Unexpected end of file from server  RSS feed

 
Priyanka Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a service running on Websphere 5.1 which uses IBM JSSE.
On the client side, I am using JDK1.3 with JSSE1.0.3.

I am testing with old JDK because our customer is currently running JDK1.3 version.

I am using URLTunnelReader sample from JDK and I get this error

Exception in thread "main" java.net.SocketException: Unexpected end of file from server
at com.sun.net.ssl.internal.www.protocol.https.HttpClient.b(DashoA12275)
at com.sun.net.ssl.internal.www.protocol.https.HttpClient.a(DashoA12275)

I am going through a proxy .

String url = "https://myserver.com"
BufferedInputStream bInputStream = null;

System.setProperty("https.proxyHost",proxyHost);
System.setProperty("https.proxyPort",proxyPort);

URL verisign = new URL(url);
URLConnection urlc = verisign.openConnection(); //from secure site
if(urlc instanceof com.sun.net.ssl.HttpsURLConnection){
System.out.println("INSTANCE OF HTTPSURLCONNECTION");
((com.sun.net.ssl.HttpsURLConnection)urlc).setSSLSocketFactory
(new SSLTunnelSocketFactory proxyHost,proxyPort));
}


com.sun.net.ssl.HttpsURLConnection httpconn = (com.sun.net.ssl.HttpsURLConnection)urlc;

httpconn.setRequestMethod("POST");
System.out.println("POST method set");
OutputStream outputStream =new ByteArrayOutputStream();
byte[] inputBuffer = new byte[4096];
bInputStream = new BufferedInputStream(httpconn.getInputStream());


The Unexpected end of file from server is thrown on line httpconn.getInputStream());


Please Suggest what is causing this problem.

Thanks,
Priya
 
Hamed Khan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I searched the entire posts and forums especially SUN forums and didn't find any suitable answer for this problem. After some debugging I found the issue (at least mine) and since my account on sun has been disables (why? I don't know) I post my experience here

You should send the Repose headers before writing into the OutputStream in server side:

inputStream.close();

final Headers headers = httpExchange.getResponseHeaders();
headers.add("Content-Type", "application/octet-stream");

output = httpExchange.getResponseBody();
httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 10l);

...........
output.write(array);

..............
output.close();



The second parameter for .sendResponseHeaders methos is the total message length which you are going to send to the client.


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!