Solved

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

Posted on 2004-10-11
3
1,573 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now