Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String array comparison 4 56
jsp CRUD operations with and without prepared statement also hibernatge 1 49
Java Inheritance super keyword use 8 71
Java regex 5 21
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

737 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