Solved

Unexpected end of file from server error when trying to connect to https URL

Posted on 2004-10-11
3
1,616 Views
Last Modified: 2012-06-27
I have an application which was using MS JVM. Now this has been migrated and moved to Sun JRE 1.4.2_04.

The JRun server (ver. 4, updater 3) is behind a reverse proxy called WebSeal that receives the https requests from the client and converts into an internal request and vice versa.

When the client sends a request to the server, the process fails atleast once in five tries with the following exception.

java.net.SocketException: Unexpected end of file from server
            at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
            at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
            at sun.net.www.protocol.https.PluginDelegateHttpsURLConnection.getInputStream(Unknown Source)
            at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
            at AccountListApp.AccountListApplet.send(AccountListApplet.java:480)
            at AccountListApp.AccountGrid.getLookupDetail(AccountGrid.java:9188)
            at AccountListApp.AccountGrid.DisplayFormatter(AccountGrid.java:6718)
            at AccountListApp.AccountGrid.findSpecialNew(AccountGrid.java:12269)
            at AccountListApp.AccountGrid.setCurrentAccount(AccountGrid.java:7739)
            at AccountListApp.AccountListApplet.start(AccountListApplet.java:1350)
            at sun.applet.AppletPanel.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)


We use a proxy called WebSeal (from IBM) that converts all https requests to internal requests to the JRun server. SSL-enabling is done at WebSeal and not in JRun server.

From the attached code block where the problem comes. We use a generic URL object to communicate.We do not see any relevant exceptions at the server level.

public String send(String str_request) {

             noOfRequests++;
             ObjectOutputStream outputToServlet = null;
             try {
                   System.gc();
                   // connect to the servlet
                   //Fill in appropriate URL depending on the webserver where its hosted
                   gridServlet = new URL(str_servletURL);
                   servletConnection = gridServlet.openConnection();
                   // inform the connection that we will send output and accept input
                   servletConnection.setDoInput(true);
                   servletConnection.setDoOutput(true);

                   // Don't use a cached version of URL connection.
                   servletConnection.setUseCaches (false);
                   servletConnection.setDefaultUseCaches (false);

                   // Specify the content type that we will send binary data
                   servletConnection.setRequestProperty ("Content-Type", "application/octet-stream");

             }catch (Exception e){
                   System.out.println("Send :" + e);
             }

            // System.out.println("sending Request");

             try {
                   System.gc();
                   // send the student object to the servlet using serialization
                   outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
                  //System.out.println("created stream");
                   // serialize the object
                   outputToServlet.writeObject(str_request);
                   //System.out.println("sendMethod: request = " + str_request);
                   outputToServlet.flush();
                  //System.out.println("flushed stream");
                   outputToServlet.close();

             }catch(Exception e){
                   System.out.println("send: exception 1: " + e);
             }

             String gridResponse = "";

             ObjectInputStream inputFromServlet = null;

             //System.out.println("b4 try ");
             String str_temp = "" ;
             try {

                   System.gc();
                   inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
                    //System.out.println("created input stream");

                    respVector = (Vector)inputFromServlet.readObject();
                           inputFromServlet.close() ;
                    //System.out.println("responseVector = " + respVector);
                    //System.out.println("responseVector befor loop::");
                    for (int i=0; i<respVector.size(); i++){

                          gridResponse  += (String)respVector.elementAt(i);
                    }
        str_temp = (String)respVector.elementAt(0) ;
        if(str_temp.equals("SESSION_EXPIRED")){
          showErrorURL("0", "SESSION_EXPIRED", "SIGNON_RQV1");
        }

             } catch(Exception e){
                    System.out.println("send: exception 2: " + e);
                    e.printStackTrace();
                    System.out.println("required exception");

             }
             System.gc();
            //System.out.println("str_response:"+gridResponse);
             return gridResponse;

        }

Server Details:
---------------
Windows 2000 Server
JRun 4 Updater 2
JDK 1.4.2

Client Details:
---------------
Windows 2000 Professional SP4
Internet Explorer 6.0 SP1
JRE (plug-in) 1.4.2_04

Test Case:
----------
With the code above, it is quite straight forward to simulate the problem. The request fails atleast once in 5 times.
0
Comment
Question by:msoumya
3 Comments
 
LVL 2

Accepted Solution

by:
gen718 earned 500 total points
ID: 12282679
First you need to determine the size of the serialized object you wish to send to the servlet.
Then you add  
             
      servletConnection.setRequestProperty ("Content-Length", Integer.toString(serialized_object_size));

after the Content-Type setRequestProperty call.  This prevents unexpected end-of-data errors from the server when dealing with binary data (as found with the writeObject call).

To get the size of a serialized object, you can serialize the object to a byte stream, then get a byte array from the stream, then get the length of the array.

Check out http://www.churchillobjects.com/c/13029.html.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question