Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 75
array11 challenge 16 50
Impossible to extract MSI from new JAVA releases 2 37
Java Jpanels and Jframe 8 19
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

763 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

10 Experts available now in Live!

Get 1:1 Help Now