Hello all,

I'm having problems trying to write a HttpTunnel for java objects in Tomcat.
For some reason I'm getting a ClassCastException. I don't understand this.
I've even tried forcing it as you can see in my code below. The exception
that i'm getting is not very clear and i can't put my finger on it.

I have attached the exception from Apache/Tomcat and the code for the tunnel
at the bottom of this email. If you can help I would be very grateful.

Regards,
Stuart Stephen

----------------------------------------------------------------------------
----

Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error

----------------------------------------------------------------------------
----

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error)
that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: TestTunnel
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:820)
        at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:615)
        at
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java
:396)
        at
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:201)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
        at
org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:2
46)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164
)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
        at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:170)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170
)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
        at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:163)
        at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:371)
        at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:424)
        at java.lang.Thread.run(Unknown Source)

-----------------------

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletException.*;
import javax.servlet.UnavailableException.*;
import java.lang.Exception.*;
import java.io.*;
import java.util.*;
import java.net.*;

public class TestTunnel extends Thread {

  // applet connections
  ObjectOutputStream objOut = null;
  ObjectInputStream objIn = null;

  // chatserver connections
  Socket socket = null;
  ObjectOutputStream sockObjOut = null;
  ObjectInputStream sockObjIn = null;

  ToApplet app = null;
  ToServer ser = null;

  protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException  {
    try {
      // get data stream from applet
      System.err.println("start of servlet");

      objIn = new ObjectInputStream(req.getInputStream());
      objOut = new ObjectOutputStream(res.getOutputStream());

      // create socket to chat server and the streams
      socket = new Socket("127.0.0.1", 3000);
      sockObjOut = new ObjectOutputStream(socket.getOutputStream());
      sockObjIn = new ObjectInputStream(socket.getInputStream());

      app = new ToApplet((TestTunnel)this);
      ser = new ToServer((TestTunnel)this);

      System.err.println("end of servlet");
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  public void destroy() {
    try {
      objIn.close();
      objOut.close();
      sockObjIn.close();
      sockObjOut.close();
      socket.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  private class ToApplet extends Thread {
    TestTunnel parent = null;

    public ToApplet(TestTunnel parent) {
      try {
        this.parent = parent;
        this.start();
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }

    public void run() {
      try {
        Object obj = null;
        while((obj=parent.sockObjIn.readObject())!=null) {
          write(obj);
        }
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }

    public void write(Object msg) {
      try {
        parent.objOut.writeObject(msg);
        parent.objOut.flush();
        parent.objOut.reset();
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }
  }

  private class ToServer extends Thread {
    TestTunnel parent = null;

    public ToServer(TestTunnel parent) {
      try {
        this.parent = parent;
        this.start();
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }

    public void run() {
      try {
        Object obj = null;
        while((obj=parent.objIn.readObject())!=null) {
          write(obj);
        }
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }

    public void write(Object msg) {
      try {
        parent.sockObjOut.writeObject(msg);
        parent.sockObjOut.flush();
        parent.sockObjOut.reset();
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }
  }
}



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to