Applet/Servlet/serialized objects/HTTPS/Intranet problem

We've got a Webapplication with[b] applets on the client and servlets on the server side.The Applet send serialized Objects over HTTPS (SSL) to the servlet. The servlet does some business logic and send the answer the same way back.
In all our tests and in the most cases the application works without any problems.
But in some Intranet environments we get occasionally (not definitely reproducable) the following error:
<Oct 1, 2004 8:26:00 AM>  [AnmeldenService] {Service-readThreadAks-AnmeldenServiceThread}
java.io.EOFException: Expecting code
at java.io.ObjectInputStream.peekCode(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at com.dsh.egb.aks.betrieb.rclt.service.ServiceThread$2.run(ServiceThread.java:222)
at java.lang.Thread.run(Unknown Source)Has anybody an idea how to further analyse this problem?
Thanks,
Mark
We use JRE/JDK 1.3.1_10.

Here some more Information about our environment:
Server: Apache 1.3.26 / Openssl 0.9.6d /WinNT 4.0 /HTTP Redirect to Tomcat 4.0.1/ JDK1.3.1_10/ WinNT 4.0
Client: Plugin 1.3.1_10/Internet Explorer 6.0 (SSL)/Win NT 4.0

Similar Messages

  • Applet-servlet communication, object serialization, problem

    hi,
    I encountered a problem with tomcat 5.5. Grazing the whole web i didn't find any solution (some guys are having the same problem but they also got no useful hint up to now). The problem is as follows:
    I try to build an applet-servlet communication using serialized objects. In my test scenario i write a serialized standard java object (e.g. a String object) onto the ObjectOutputStream of the applet/test-application (it doesn't matters wheter to use the first or the latter one for test cases) and the doPost method of the servlet reads the object from the ObjectInputStream. That works fine. But if i use customized objects (which should also work fine) the same code produces an classnotfound exception. When i try to read and cast the object:
    TestMessage e = (TestMessage)objin.readObject();
    java.lang.ClassNotFoundException: TestMessage
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    ...That seems strange to me, because if i instantiate an object of the same customized class (TestMessage) in the servlet code, the webappclassloader doesn't have any problems loading and handling the class and the code works fine!
    The class is located in the web-inf/classes directory of the application. I've already tried to put the class (with and without the package structure) into the common/classes and server/classes directory, but the exception stays the same (I've also tried to build a jar and put it in the appropriate lib directories).
    I've also tried to catch a Throwable object in order to get information on the cause. But i get a "null" value (the docu says, that this will may be caused by an unknown error).
    I've also inspected the log files intensively. But they gave me no hint. Until now I've spend a lot of time on searching and messing around but i always get this classnotfound exception.
    I hope this is the right place to post this problem and i hope that there is anyone out there who can give me some hint on solving this problem.
    Kindly regards,
    Daniel

    hi, thanks for the reply,
    all my classes are in the web-inf/classes of the web-app and have an appropriate package structure. thus the TestMessage class is inside a package.
    i tried some names for the testclass but it didn't matter. the exception stays the same. I also tried to put the jar in the common/lib but the problem stays.
    Well the problem with loaded classes: As i mentioned in the post above i can instantiate an object of TestMessage in the code without any problems (so the classloader of my webapp should know the class!!)
    only when reading from the objectinputstream the classloader doesn't seem to know the class?? maybe theres a parent classloader resposible for that and doesn't know the class?
    strange behaviour...
    p.s. sending the same object from the servlet to the client works well
    regards
    daniel
    Message was edited by:
    theazazel

  • How to Obtain Applet -servlet communication through https protocol

    We are trying to use https protocol.
    First I will explain Our Architecture. We are using JRun 3.0
    as servlet engine. We are using iplanet as a webserver.
    There are two iplanet webservers.
    There is a firewall between two iPlanet servers. i.e, one webserver
    is outside the firewall. JRun is communicating with inside iplannett
    webserver and inside iplannett webserver is communicating with
    outside iplannet server.
    If we are trying to run the application with
    this firewall, our applet is not loading,
    but the servlets and jsp pages are all working fine.
    Without the firewall, everything is working fine.
    The applet is also working fine.
    But, with the firewall, our applet is not loading.
    We are using JRE 1.3 as java plug-in.
    What is the problem so that the applet is not loading.
    and How to resolve this? can anybody give suggestion in this regard?
    Thanks in advance.

    No, I am not getting any security exception for the applet, but I am getting the following exception when working with HTTPS. The same application works fine with the default HTTP protocol
    java.net.UnknownServiceException: Input from HTTPS not expected until OutputStream is closed
         at sun.plugin.protocol.https.BrowserHttpsURLConnection.getInputStream(Unknown Source)
         at JBSchedulerXNew.initReceiveAppointmentData(JBSchedulerXNew.java:122)
         at JBSchedulerXNew.initReceiveAppointmentData(JBSchedulerXNew.java:92)
         at JBSchedulerXNewDemo.init(JBSchedulerXNewDemo.java:110)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

  • How to do Applet/Servlet permanent interactive connection

    Hi, I'm modifying an Instant Messaging Application originally implemented under the Applet client/standalone-server scheme that I'm implementing now under the Applet/Servlet scheme using HTTP Tunneling with Object Serialization. But this yet don't work correctly because the connection's flows are closed ever after a Servlet's response to a client request (in this moment are close the connection's flows). I'm using flows of type ObjectInputStream and ObjectOutputStream using Object Serialization with HTTP Tunneling.
    this is part of the connection code in the servlet side:
    public void doGet (HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException{
    doPost( request, response);
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException{
    is = new ObjectInputStream(
    new BufferedInputStream(request.getInputStream()));
    try{  
    response.setStatus(HttpServletResponse.SC_OK);
    out = new ObjectOutputStream (
    new BufferedOutputStream (response.getOutputStream ()));
    out.writeObject("OK");
    out.flush();
    // Send the input and output flows to the Thread the Handle the client Connection
    newUser(is, out);
    } catch(Exception ex){
    System.err.println("Exc1: "+ex.toString());
    ex.printStackTrace();
    Run Method to read client request:
    public void run() {
    SocketData sd;
    while ((sd = readObject()) != null) {                               
    sd.performAction(this);
    close();
    After a servlet response in the readObject() method the input flow is closed in the reader request of clients and the connection between the applet (client) and servlet is lost.
    How to can implement a smarter HTTP Tunneling with permanent interactive connection beetween the Applet and Servlet such as in the Applet /server Standalone connection using TCP/IP Socket connection.
    Is possible the use of TCP/IP Sockets in the implementation of HTTP Tunneling with Object Serialization in the Applet/Servlet permanent interactive communication scheme?
    some links or code samples?
    Please show me the ligth.
    Thanks greatly a smarter help.

    I'm not sure that I fully understand your problem, but HTTP is a stateless protocol. That means request-response pairs are completely separated from each other.
    You should ask yourself if you really need to use HTTP and a servlet or if a raw TCP/IP communication would be a better approach to your problem.

  • Applet-Servlet Communication problem EOFException

    Hi! i´ve been searching and searching through forums because it seems this problem is very common, but none of the solutions i´ve seen so far suits me, so i´m here looking for some help because i´ve been stuck one week with this. First of all sorry if my english isn´t the best... i´m a bit rusty...
    Well, i had some code that worked perfectly, but i needed to perform some changes because i needed the servlet to send more info to the applet, and here started the problems, when i made the changes it started to throw EOFException when i was trying to read the InputStream, and furthermore when i came back to the original code it started to throw the exception in the same place too
    So here i am... don´t know what to do now and i entrust to you to give me some tips.
    Here comes some code. This is the original code, the one that runned but it doesn´t run right now
    Applet:
    public ListasComponentesSeleccionables cargarListasComponentes( ) throws IOException, ClassNotFoundException {
              String serv = "/Desaladora/cargarListasComponentesApplet.do";
              String host = Principal.documentBase.getHost( );
              URL direccion = new URL( "http", host, 8080, serv );
              // Create conection
              URLConnection connection = direccion.openConnection( );
              connection.setDoInput( true ); 
              connection.setDoOutput( true );
              connection.setUseCaches( false );
              connection.setRequestProperty( "Content-Type", "application/x-java-serialized-object" );
              ObjectOutputStream output;
              output = new ObjectOutputStream( connection.getOutputStream( ) );
              output.writeObject( new Boolean(true) );
              output.flush( );
              output.close( );
              ObjectInputStream input = new ObjectInputStream( connection.getInputStream( ) ); //<-- Here is the problem
              ListasComponentesSeleccionables response = new ListasComponentesSeleccionables( );
              response = ( ListasComponentesSeleccionables ) input.readObject( );
              return response;
         }Servlet:
    ublic class CargarListasComponentesAppletAction extends Action {
    public ActionForward execute(     ActionMapping mapping,
                                                     ActionForm form,
                                                     HttpServletRequest request,
                                                     HttpServletResponse response )
                            throws ServletException, IOException, Exception  {
              InitialContext context = new InitialContext();
              SensorManagerService sensor_service;
              ActuatorManagerService actuator_service;
              Globals.LOGGER_SECURITY.debug( "Entering ACTION 'CargarListasComponentesAppletAction'" );
              response.setContentType("application/x-java-serialized-object");
              try
                   ObjectInputStream bufferentrada = new ObjectInputStream(request.getInputStream());
                   Boolean peticionOK = (Boolean)bufferentrada.readObject();
                   ObjectOutputStream buffersalida = new ObjectOutputStream(response.getOutputStream());
                   sensor_service = ( SensorManagerService ) context.lookup( "desaladora/SensorManagerServiceBean/local" );
                   ArrayList<AlarmConnectedSensorDTO> sensorList = sensor_service.findAllSensorsToAlarms();
                   actuator_service = ( ActuatorManagerService ) context.lookup( "desaladora/ActuatorManagerServiceBean/local" );
                   ArrayList<AlarmConnectedActuatorDTO> actuatorList = actuator_service.findAllActuatorsToAlarms();
                   buffersalida.writeObject( crearListasSeleccionables(sensorList, actuatorList) );
                   buffersalida.flush();
              catch(Exception e)
                   System.out.println("Error en la trasmision de datos");
              return null;
         private ListasComponentesSeleccionables crearListasSeleccionables(ArrayList<AlarmConnectedSensorDTO> sensorList,
                    ArrayList<AlarmConnectedActuatorDTO> actuatorList) {
              Vector<Integer> vectorSensores = new Vector<Integer>();
              Vector<Integer> vectorActuadores = new Vector<Integer>();
              for(AlarmConnectedSensorDTO sensor : sensorList) {
                   vectorSensores.add(sensor.getIdSensor( ));
              for(AlarmConnectedActuatorDTO actuator : actuatorList) {
                   vectorActuadores.add(actuator.getIdActuator( ));
              ListasComponentesSeleccionables listasComponentesSeleccionables =
                                  new ListasComponentesSeleccionables(vectorSensores, vectorActuadores);
              return listasComponentesSeleccionables;
    }i´ve been running some test in another computer, and this code simply works, but it doesn´t work in the machine i usually work.
    Maybe someway the stream get corrupt? the info i´ve been trying to send and started throwing the exception may still be in the stream? I don´t know what to think right now.
    Hope someone has any idea, thankyou.

    I dont see the problem. However, I suggest you change this;
    System.out.println("Error en la trasmision de datos"); t
    to e.printStackTrace() to see what it is doing when it stops working.
    I also suggest peppering your code with System.out.println() statements to see what it is doing just before stopping.
    Also, try your code with a brand new file with only a few characters in it. If it works, add to it some of your originial file content until it stops working. This way, you can determine if its the file size that is causing the crash or something in the file content. If all else fails, study java I/O and try some other way to read/write the file. You can also try a different browser. If it works, its the browser. Still having problems? Create a new project with a simple applet and file read/write program and get that working. That way, all the other stuff in your original project isn't in the way.

  • Big Problem in Applet-Servlet Communication-(Help)

    I wrote an method to send serialized objects from Applet to Servlet,
    the method is as following:
    private ObjectInputStream postObjects (URL servlet, Serializable objs[], String sessionID) throws Exception {
    ObjectInputStream in = null;
    ObjectOutputStream out = null;
    try{
    URLConnection con = servlet.openConnection();
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type","application/x-java-serialized-object");
    con.setAllowUserInteraction(false);
    con.setRequestProperty("Cookie", sessionID);
    out = new ObjectOutputStream(con.getOutputStream());
    int numObjects = objs.length;
    for(int x = 0; x < numObjects; x++){
    out.writeObject(objs[x]);
    out.flush();
    out.close();
    in = new ObjectInputStream(con.getInputStream());
    }catch(Exception e){
    e.printStackTrace(System.err);
    throw e;
    }finally{
    return in;
    when I call this method, I got the following error message in Applet console,
    my platform is Salaris 5.8 + iPlanet 6.0.
    java.io.EOFException
         at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2150)
         at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2619)
         at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:726)
         at java.io.ObjectInputStream.<init>(ObjectInputStream.java:251)
         at com.shinewave.lms.core.client.ServletProxy.postObjects(ServletProxy.java:255)
         at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:76)
         at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
    java.lang.NullPointerException
         at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:77)
         at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
    java.lang.NullPointerException
         at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:82)
         at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
    Please help me to solve this problem, thank you very much.

    Hi..
    Sorry abt this. But I was hoping if u could help out on this..
    I am trying to implement a applet to servlet communication...
    wherin the servlet would read data from the database... and send it back to the applet which gets displayed on the applet...
    But the problem is that the applet is not able to establish a connection with the servlet..
    I am also using another supportive class whose object is basically passed from the servlet to the applet..
    could u help me..
    below is the piece of code...
    APPLET:
    import java.net.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class TestApplet extends JApplet implements ActionListener
         JButton btnLoad;
         JTextField tfEmpno, tfFname, tfLname, tfSalary;
         URL url;
    private String webServerStr = null;
    private String hostName = "sandy";
    private int port = 8085;
    private String servletPath = "/jdbcTest.DBDetailsServlet";     
    public TestApplet()
         super();
    // suppress Warning Message
    getRootPane().putClientProperty"defeatSystemEventQueueCheck",Boolean.TRUE);
         public void actionPerformed(ActionEvent ae)
              if(btnLoad.getText().equals("Load"))
                   if(loadData())
                        btnLoad.setText("Save");
              else
                   btnLoad.setText("Load");
    //               saveData();
         public void init()
              setBackground(Color.pink);
              tfEmpno = new JTextField(10);
              tfFname = new JTextField(10);
              tfLname = new JTextField(10);
              tfSalary= new JTextField(10);
              JPanel panel = new JPanel();
              panel.setLayout(new FlowLayout());
              panel.add(tfEmpno);
              panel.add(tfFname);
              panel.add(tfLname);
              panel.add(tfSalary);
              getContentPane().add(panel, BorderLayout.CENTER);
              JPanel bottom = new JPanel(new FlowLayout());
              btnLoad = new JButton("Load");
              btnLoad.addActionListener(this);
              bottom.add(btnLoad);
              getContentPane().add(bottom, BorderLayout.SOUTH);
         public boolean loadData()
              try
         System.out.println("Web Server host name: " + hostName);
         webServerStr = "http://" + hostName + ":" + port + servletPath;
         System.out.println("Web String full = " + webServerStr);
                   String servletGET = webServerStr + "?"
         + URLEncoder.encode("UserOption") + "="
         + URLEncoder.encode("AppletDisplay");     
    //               url = new URL(getCodeBase(),"http://sandy:8080/servlet/jdbcTest.DBDetailsServlet");
                   System.out.println("Complete Servlet Url => " + servletGET);
                   url = new URL(servletGET);
                   URLConnection con = url.openConnection();
                   con.setUseCaches(false); // Turn off caching.
                   InputStream in = con.getInputStream();
                   System.out.println("\nsuccess ....... con.getInputStream() ");
                   ObjectInputStream ois = new ObjectInputStream(in);
                   System.out.println("\nsuccess ....... new ObjectInputStream(in) ");
                   Object object = ois.readObject();
                   System.out.println("\nGot the object from servlet...");
                   if(object != null)
                        System.out.println("\nObject NOT null ...");
                        ArrayList result = (ArrayList) object;
                        jdbcTest.EmployeeValue empval = (jdbcTest.EmployeeValue) result.get(0);
                        tfEmpno.setText(""+empval.getEmp_no());
                        tfFname.setText(empval.getFname());
                        tfLname.setText(empval.getLname());
                        tfSalary.setText(""+empval.getSalary());
                        System.out.println("\nObject processed " + result);
                        repaint();
                   return true;
              catch(Exception e)
                   e.printStackTrace();
                   System.out.println("\n\n loadData()=> E X C E P T I O N : " + e + "\n");
                   return false;               
         public void saveData()
              //yet to be implemented..
    SERVLEt:
    package jdbcTest;
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class DBDetailsServlet extends HttpServlet
         public void doGet(HttpServletRequest req,HttpServletResponse res )throws ServletException, IOException
              System.out.println("\nInside the doGet()\n");
              ArrayList results = getDetails();
              ObjectOutputStream oos = new ObjectOutputStream(res.getOutputStream());
              oos.writeObject(results);
         public void doPost(HttpServletRequest req,HttpServletResponse res )throws ServletException, IOException
              System.out.println("\nInside the doPost()\n");
              doGet(req,res);
         public ArrayList getDetails()
              try
                   System.out.println("\nServlet : inside GetDetails...");
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:odbc:SandyDSN","","");
                   java.sql.Statement stmt = con.createStatement();
                   System.out.println("\n Statement created..");
                   java.sql.ResultSet rs = stmt.executeQuery("SELECT * FROM EMP WHERE EMP_NO = 222");
                   System.out.println("\n Query Executed...");
                   ArrayList results = new ArrayList();
                   while(rs.next())
                        EmployeeValue empval = new EmployeeValue();
                        empval.setEmp_no(rs.getLong("EMP_NO"));
                        empval.setFname(rs.getString("FNAME"));
                        empval.setLname(rs.getString("LNAME"));
                        empval.setSalary(rs.getLong("SALARY"));
                        results.add(empval);
                   System.out.println("\n Resultset Obtained...");
                   stmt.close();
                   con.close();
                   return results;
              catch(Exception e)
                   System.out.println("Error while retreiving details....." + e);
                   return null;
         public boolean saveDetails(EmployeeValue empval)
              try
                   return true;
              catch(Exception e)
                   System.out.println("Error while updating details....." + e);
                   return false;
    The utility class EMployeeValue is as below:
    package jdbcTest;
    import java.io.*;
    class EmployeeValue implements Serializable
         private long emp_no;
         private String fname;
         private String lname;
         private long salary;
         public EmployeeValue()
              super();
         public EmployeeValue(long eno, String fn, String ln,long sal)
              super();
              setEmp_no(eno);
              setFname(fn);
              setLname(ln);
              setSalary(sal);
         public long getEmp_no()
              return emp_no;
         public java.lang.String getFname()
              return fname;
         public java.lang.String getLname()
              return lname;
         public long getSalary()
              return salary;
         public void setEmp_no(long newEmp_no)
              emp_no = newEmp_no;
         public void setFname(java.lang.String newFname)
              fname = newFname;
         public void setLname(java.lang.String newLname)
              lname = newLname;
         public void setSalary(long newSalary)
              salary = newSalary;

  • Applet Servlet Comm. Problem

    Dear friends,
    i have an applet that sends a serialized object to the servlet,the Servlet creates another object and passes it back to the applet.
    Everything works fine, till i read the object with:
    ObjectInputStream objInputStream = new ObjectInputStream(in);
            show("got object input stream");
             chart = new ChartPanel((JFreeChart)objInputStream.readObject());At this point, i got nothing back.Instead i get a "null"returned on my Java Console.
    From JBuilder it works fine
    Here is the code
    //This is called from the applet in order to load a chart in a panel
    private JPanel getChartFromServlet(Object[] parameters) throws Throwable {
      ChartPanel chart=null;
      String server;
       try {
    ///////////////////////create URL Connection to SERVLET
        if (this.remoteServerMode) {
          this.show("http://10.30.1.38:8080/AppletToServlet/DbServlet");
           server="http://10.30.1.38:8080/AppletToServlet/DbServlet";
         else {
           server="http://localhost:8083/DbServlet";
         //SEND DATA TO SERVLET
         URLConnection servletCon=this.getServletConnection(server);
         // servletCon.setRequestProperty("Content-Type","application/octet-stream");
          //send the query parameters  using serialization
           ObjectOutputStream out=new ObjectOutputStream(servletCon.getOutputStream());
           out.writeObject( parameters);
           out.flush();
           out.close();
           this.show("Finish with send to servlet");
           //GET DATA FROM SERVLET
           InputStream in=servletCon.getInputStream();
           show("got input stream");
           ObjectInputStream objInputStream = new ObjectInputStream(in);
            show("got object input stream");
             chart = new ChartPanel((JFreeChart)objInputStream.readObject());
             show("got chart");
            objInputStream.close();
            in.close();
            chart.setPreferredSize(new Dimension(734, 370));
       catch (Exception ex) {
         System.err.println("Exception caught");
         this.show(ex.getMessage());
         this.show(ex.getMessage());
         System.err.println(ex.getMessage());
         ex.printStackTrace(System.err);
       throw new Exception( ex.getCause());
    return chart;
    //Servlet Side Code
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
          ServletException, IOException {
        ObjectInputStream inputStreamFromApplet=null;
        Object[] queryParams;
      JFreeChart chart=null;
        try {
          response.setContentType("application/x-java-serialized-object");
          //////////////////////////READ INPUT//////////////////////////////////////
          InputStream in=request.getInputStream();
          inputStreamFromApplet=new ObjectInputStream(in);
          //Read applet's serialised object passed in Input Stream
          queryParams = (Object[]) inputStreamFromApplet.readObject();
          //do something with serialized object
          chart=getRequestedChart(queryParams);
          //////////////////////////WRITE OUTPUT////////////////////////////////////
          //open an output stream
          ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
          //write to output stream
          out.writeObject(chart);
          out.flush();
          //close output stream
          out.close();
        catch (Exception ex) {
          ex.printStackTrace();
          System.err.println(ex.getMessage());
      }Do you have any ideas?
    Apart from the null value,i saw also some SocketException
    Is there a security issue involved?Both Servlet and Applet come from the same ip.
    Thank you very much in advance,
    Chris

    A Chart constructor takes as an arg a JFreeChart.
    Chart is a JComponent so i cannot serialize it.
    That's why the servlet passes a JFreechart object and
    the applet constructs a chart from it.
    I cast the object to a jfreechart and pass it to the constructor of the chart.
    The strange thing also is that, wghile initially with a non perfectly designed UI,everything worked fine but when i modified the applet's UI ,problems started...
    Something with serialization and versions of classes?

  • Continuously send serialized objects from servlet

    Hi,
    I'm trying to write a servlet that, once activated, will continuously send objects back to a thread in the client. I'm hoping someone can point me in the right direction. This code works fine if you take out the while(true){...} loops.
    After doing a bit more research, I discovered the OutputObjectStream should be .reset() in order to reset the object map. I tried doing this before the .flush() with no success. The servlet continues to spew out objects, but the client side doesn't even see the first one, hanging on the in = DataInputStream(connection.getInputStream()) line.
    Servlet code:
    public class testStream extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    int[] somedata = new int [1];
    somedata [0] = 1000;
    String contentType =
    "application/x-java-serialized-object";
    response.setContentType(contentType);
    ObjectOutputStream out =
    new ObjectOutputStream(response.getOutputStream());
    while (true) {
    try {
    out.writeObject(somedata );
    System.out.println("Sent " + somedata [0]);
    somedata [0]++;
    } catch(Exception ie) {}
    out.flush();
    Thread.yield();
    out.close(); // unreachable if while loop in place
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    Applet side code:
    * <P>
    * Taken from Core Servlets and JavaServer Pages
    * from Prentice Hall and Sun Microsystems Press,
    * http://www.coreservlets.com/.
    * � 2000 Marty Hall; may be freely used or adapted.
    public class testStream implements Runnable {
    private boolean isDone = false;
    private URL dataURL;
    public testStream(String urlSuffix, URL currentPage) {
    try {
    // Only the URL suffix need be supplied, since
    // the rest of the URL is derived from the current page.
    String protocol = currentPage.getProtocol();
    String host = currentPage.getHost();
    int port = currentPage.getPort();
    dataURL = new URL(protocol, host, port, urlSuffix);
    Thread imageRetriever = new Thread(this);
    imageRetriever.start();
    } catch(MalformedURLException mfe) {
    System.err.println("Bad URL");
    isDone = true;
    public void run() {
    try {
    retrieveImage();
    } catch(IOException ioe) {
    isDone = true; // will never get hit
    public boolean isDone() { // meaningless now with infinite loop
    return(isDone);
    private void retrieveImage() throws IOException {
    URLConnection connection = dataURL.openConnection();
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDefaultUseCaches (false);
    connection.setRequestProperty("Content-Type", "application/x-java-serialized-object");
    ObjectInputStream in = null;
    try {
    in = new ObjectInputStream(connection.getInputStream());
    } catch (Exception pe) { System.err.println(pe); }
    while (true) {
    // loop forever requesting data
    try {
    // The return type of readObject is Object, so
    // I need a typecast to the actual type.
    int[] someData = (int[]) in.readObject();
    System.err.println(someData[0]);
    } catch(ClassNotFoundException cnfe) {
    System.err.println("received NULL");
    Thread.yield();

    try this: move out.flush() upwards directly after the out.writeObject().
    robert

  • Applet-Servlet with RMI or HTTP? : for a web based network monitoring tool.

    Hi,
    I need help to make a decision to choose an implementation technique for a tool that I am creating.
    I am creating a utility to display a table of RX and TX bandwidth information in real time from a network device X
    onto a client's web browser.
    I have a JTable based applet to display bandwidth information. However I am running this as a standalone applet. I want
    to create a web based solution (applet/servlet model) to make life easier for the end user.
    As for displaying the bandwidth information, I am using Runtime.exec() function to remote execute commands using ssh/rsh.
    This not only seems to impose a lot of process and network latency overhead, but also seems impractical from a
    security point of view, hence I need a real client/server model to have efficient and secure serialized data transfer across
    the network (through HTTP etc) between the client's web browser and X.
    X has a web server running on it. It essentially is a Linux box (CentOS). I can create a JNLP definition to launch an applet
    from X onto a remote client's web browser. The real problem is: what is the most efficient way to go about the
    servlet implementation? Is it wise to use HTTP get/post? or RMI is the way to go?
    Also I'd appreciate suggestion on any different approaches than what I have in mind above.
    Thanks,
    Rajiv

    Thanks for your time, but I cannot make a front-end in C. It has to be in JSP (or in ASP but I haven't tried yet to program in VBA).
    So that is why I am asking what is the best way of attaching a JSP front-end to the given API.
    PS: Why should I code a .dll to provide a JNI interface for the api? Isn't the JNI interface capable of doing such?

  • Serialized Objects and Servlets

    I'm having a lot of trouble accessing a serialized object and displaying it in a servlet. I get the following exception:
    java.io.StreamCorruptedException: Type code out of range, is -84
    Can anyone help me out here?

    OK... here's some of the code I'm using...
    public Object readObject()
    throws IOException, ClassNotFoundException
              oin = new ObjectInputStream(fin);
              Object obj = oin.readObject();
              oin.close();
              return obj;
    public void writeObject(Object data)
    throws IOException
              oout = new ObjectOutputStream(fout);
              oout.writeObject(data);
              oout.close();
    Essentially, my servlet creates and instance of an ObjectManager class. This ObjectManager then tries to execute the readObject method above.
    The whole process comes to a grinding halt at this point:
    Object obj = oin.readObject();
    I think this problem has to do with the way that I'm trying to access the file to which I have serialized my object. The problem is that I can't think of any other way to do it. Here's how I am currently referencing the file that holds my serialized object:
    File theFile = new File("Serialized.dat");
    FileInputStream fin = new FileInputStream(theFile);
    I've never attempted anything like this before and I suspect I'm way off in my approach. I really appreciate your willingness to help me out.

  • Applet  + Serialized Object + PDF == ??

    I have an applet that serializes a transport bean to a servlet on tomcat, based on the contents of the bean, the servlet makes a PDF that I want to display on the browser.
    I had thought that if I simply set the response MIME type and return the binary data, the browser would know what to do. Silly me, but I forgot that in this case the applet is the one in control, not the browser. The browser screen just sits there. At least this is what I am guessing...
    Here is the code that I use to send the serialized object :
        public InputStream sendPostMessage (Properties args) throws IOException
            String argString = "";  // default
            if (args != null)
                argString = toEncodedString (args);  // notice no "?"
            URLConnection con = servlet.openConnection ();
            // Prepare for both input and output
            con.setDoInput (true);
            con.setDoOutput (true);
            // Turn off caching
            con.setUseCaches (false);
            // Work around a Netscape bug
            con.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
            // Send headers
            sendHeaders (con);
            // Write the arguments as post data
            DataOutputStream out = new DataOutputStream (con.getOutputStream ());
            out.writeBytes (argString);
            out.flush ();
            out.close ();
            return con.getInputStream ();
        }Here is the question...
    Given the fact that I am serializing an object to the servlet, and that the applet is sitting there.. Is there a way to make the Browser display the PDF?
    I have my doubts about ShowDocument(URL) as I am generating the PDF on the fly without using a temporary file. (Jasper reports) In addition, aren't there sandbox issues on the server side for creating a file?
    Any other ideas?

    I think that IS what I will have to do but, I was hoping to use the PDF binary stream coming directly from the servlet.
    I guess this isn't possible?

  • Applet servlet communication problem

    applet can receive data but cannot send data to the servlet (i.e. the servlet does not receive anything).
    Listed below are the codes
    //applet
    ObjectOutputStream objStream = null;
            URL url = new URL(getCodeBase(), "/JSP/readAppletServlet");
            URLConnection con= url.openConnection();
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setUseCaches(false);
            con.setDefaultUseCaches(false);
            con.setRequestProperty ("Content-Type", "application/x-java-serialized-object");
           try{
               objStream = new ObjectOutputStream(con.getOutputStream());
               String s = "i come from APPLET";
               objStream.writeObject(s);
               objStream.flush();
               objStream.close();
           }catch(Exception ex){
    //servlet
    public class readAppletServlet extends HttpServlet {
        /** Initializes the servlet.
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        /** Destroys the servlet.
        public void destroy() {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            java.io.FileOutputStream asdf = new java.io.FileOutputStream(new java.io.File("C:\\13579.txt"));
            InputStream in = request.getInputStream();
            ObjectInputStream inputFromApplet = null;
            String s = " you cannot call servlet ar!!!! try again";
            try{
                inputFromApplet = new ObjectInputStream(in);
                s = inputFromApplet.readObject().toString();
                in.close();
            }catch(Exception ex){
            asdf.write(s.getBytes("US-ASCII"));
            asdf.close();
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
    }

    As a (future) programmer the first thing you should learn is never just say "it doesn't work"
    That's what first line support is for to get info out of "dumb" users who don't know better.
    I suggested some code changes but you haven't re posted any code.
    You think it might be the applet but I don't see any exception nor a trace from the applet.
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)

  • Problem in Applet Servlet communication in cluster

              Our new production server has been configured with
              clusters very recently.The application is running fine if and only if one instance
              of weblogic is running.The application has two applets that communicate through a
              servlet and the servlet is hosted by both the WL servers in the cluster.
              Please consider the following scenario :
              1. JSP#1(having embedded tag for Applet#1) is served by, say, WLInstance#1.
              2. JSP#2(having embedded tag for Applet#2) is served by, say, WLInstance#2.
              3. Applet#1 is loaded by BrowserInstance#1.
              4. Applet#2 is loaded by BrowserInstance#2.
              The way I understand applet-servlet communication is as follows :
              The servlets are invoked through the url-pattern specified in web.xml - if the applet
              is making use of a certain url-pattern that is mapped to servlet, then the call from
              that applet will
              eventually invoke a servlet on any of the two instances till a session is established,
              at which point all subsequent requests from the same browser window/frame will go
              to the servlet hosted on the instance where the http session was created.
              (Please correct me, if I am wrong.)
              So, Applet#1 will always talk to the servlet hosted by WLInstance#1 and Applet#2
              will always talk to the servlet hosted by WLInstance#2.
              In our case, the servlet is maintaining data structures to store all the messages
              sent by diffterent instances of Applets.
              The applets periodically polls the messages from those data structures.Once the messages
              are polled, those are deleted from
              the data structures.
              As there are two different instances of the servlet, Applet#1 never gets messages
              posted by Applet#2.
              Is there a way to make this data structure global to both the servlet instances?
              Thanks and best regards,
              Subir Das
              

              "Subir Das" <[email protected]> wrote:
              >So, Applet#1 will always talk to the servlet hosted by WLInstance#1 and
              >Applet#2
              >will always talk to the servlet hosted by WLInstance#2.
              This statement is not entirely true.
              Suppose WLInstance#1 were to be brought down (for whatever reason), Applet#1 will
              then talk to servlet hosted by WLInstance#2.
              Server pinning could be modified by different load balancing algorithms, configurable
              via containers (or hardware).
              So don't count on which servlet instance your applet is going to be served by.
              Instead consider to give a second look into the design of the servlet data structure
              (object):
              1.Read from data store, if it has been persisted.
              2.If the data is client related then consider sticking the data into session, which
              would then replicate to other WL instances.
              3.Stateless EJB in a cluster ? Don' know much about this(yet).
              My 2 cents..Good luck.
              Rama
              

  • Problem with serialized objects and JWS

    My JWS launched application fails when loading a serialized object that has been instatiated from a class not contained in the signed jar-file. Does anyone know why this happens and if there is some workaround for the problem?

    Where is the class contained then?

  • FileUpload problem: InputStream does not contain a serialized object

    Hi All,
    I'm using the FileUpload component in a JSPDynPage and the htmlb component seems to work fine but I cannot read the file (InputStream). I get the following error(IOException): "InputStream does not contain a serialized object".
    Please let me know what is wrong with my code. This is a part of the code I used:
    public FileInputStream sourceFileInput;
    public ObjectInputStream input;
    FileUpload fu;
    fu = (FileUpload) this.getComponentByName("myFileUpload");
    IFileParam fileParam = ((FileUpload) getComponentByName("myFileUpload")).getFile();
    File f       = fileParam.getFile();
    file         = fu.getFile().getFile();
    absolutepath = fu.getFile().getFile().getAbsolutePath();
    this.sourceFileInput = new FileInputStream(file);
    input = new ObjectInputStream(sourceFileInput);
    The last line of code seems to generate te error.

    Hi,
    I have found the answers, thank you both.
    (I included the examle code. Perhaps of some use to someone.)
    FileUpload fu;
    fu = null;
    fu = (FileUpload) this.getComponentByName("myFileUpload");
    //       this is the temporary file
    if (fu != null) {
         IFileParam fileParam = ((FileUpload) getComponentByName("myFileUpload")).getFile();
         if (fileParam != null) {
              // get info about this file and create a FileInputStream
              File f = fileParam.getFile();
              if (f != null) {
                   try {
                        fis = new FileInputStream(f);
                   // process exceptions opening files
                   catch (FileNotFoundException ex) {
                        myBean.setMessage(
                             "1" + f + ex.getLocalizedMessage());
                   isr = new InputStreamReader(fis);
                   br = new BufferedReader(isr);
    String textLine = "";
    do {
         try {
              textLine = (String) br.readLine();
         } catch (IOException e) {
              myBean.setMessage(
                   "1" + e.getLocalizedMessage());
         // Jco append table & put data into the record
         // (I_FILE is the table with txt data that is sent to the RFC)
         I_FILE.appendRow();     
         I_FILE.setValue(textLine, "REC");                              
    } while (textLine != null);

Maybe you are looking for

  • A question about ActionListener and MouseListener

    Hi, my question here is when we should implement a MouseListener and when we should use ActionListener instead. I know ActionEvent is fired when a action performed, for instance, a button was pressed down, but I think by implementing a MouseListener,

  • How Move PSE Catalog/Photos From Old to New Computer?

    I have Photoshop Album 2.0 on my existing Windows computer, with 2200 photos, many of which are tagged and/or edited. I recently bought PSE 4.0 and installed it on my new Windows computer. Please give advice re: 1)how to move or copy my photo and PSA

  • User Exit-Prod Order Release

    Hi all! Is there any user exit available at the time of the production order release? I found only one exit but it is triggered only when the components of BOM are batch managed. thanks a lot

  • Issues upgrading VI from LV 5.1 to 7.1/ binary file

    We recently upgraded from LabVIEW 5.1.1 to 7.1 and noticed a problem with the integrated Read/Write File VI. A measurement VI which saved data in binary form seemed to compile and run under 7.1 without problems. But when saving data the files can no

  • Opening website in dreamweaver

    Hello. I have my website on two computers at work. Everything got wiped out on one computer after a virus clean-up. So, I reloaded dreamweaver and copied all files back onto the computer. Now, when I open dreamweaver, my website is not listed under l