Solved

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

Posted on 2004-10-11
3
1,718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

688 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