1 Reply Latest reply on Nov 11, 2002 1:01 PM by mschoning

    Problem in Tomcat Servlet calling JBoss EJB running on a dif

    gsorce

      Scenario:

      ***** Client Development Machine
      Win2K prof.
      NetBeans IDE 3.4
      Tomcat 4.0 (integrated in NetBeans)
      JDK 1.3.1

      ***** Server EJB Container
      Linux RedHat 7.1
      JDK 1.3.1
      jboss-3.0.3_tomcat-4.1.12

      ***** Test Application
      Very simple, look at http://www.adwanted.com/jboss/ for details

      - Only 1 Stateless Session Bean (com.web_tomorrow.interest.InterestBean),
      implementing just a simple method:

      public double calculateCompoundInterest(double principle,
      double rate, double periods) {
      System.out.println ("Someone called `calculateCompoundInterest!'");
      return principle * Math.pow(1+rate, periods) - principle;
      }

      - Compiled and deployed using NetBeans (very useful the JAR Recipe!). Copied
      the jar file on the Linux server. All works fine!

      - Tested with a simple Java Client:

      System.setProperty("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url", "ewlpasrv1");
      InitialContext jndiContext = new InitialContext();
      Object ref = jndiContext.lookup("examples/Interest");
      InterestHome home = (InterestHome)
      PortableRemoteObject.narrow (ref, InterestHome.class);
      Interest interest = home.create();
      System.out.println
      ("Interest on 1000 units, at 10% per period, compounded over 2 periods
      is:");
      System.out.println (interest.calculateCompoundInterest (1000, 0.10, 2));

      No error reported.

      ***** PROBLEM

      We made a simple Servlet (look at the bottom of this document...), similar
      to the client.
      - we created a Web Module using netbeans
      - we copied jboss client jar files under (...)\tomcat404\lib
      - we copied the app's deployment jar file under (...)\WEB-INF\lib
      Running the servlet from NetBeans IDE (using internal Tomcat), here is the
      result:

      Servlet interface to EJB
      Calling EJB...
      Got context
      Got reference
      Got Home Interface
      java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
      java.net.SocketException: Connection aborted by peer: JVM_recv in socket input stream read
      (the full error stack is listed at the end of this mail).


      Any idea?
      Thanx in advance
      Giuseppe Sorce
      ITALY

      ----------------- Error -------------------------
      Apache Tomcat/4.0.4 - 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.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
      java.net.SocketException: Connection reset by peer: JVM_recv in socket
      input stream read
      java.net.SocketException: Connection reset by peer: JVM_recv in socket
      input stream read
      at java.net.SocketInputStream.socketRead(Native Method)
      at java.net.SocketInputStream.read(SocketInputStream.java:86)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:186)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:204)
      at java.io.ObjectInputStream.peekCode(ObjectInputStream.java:1550)
      at
      java.io.ObjectInputStream.skipToEndOfBlockData(ObjectInputStream.java:1480)
      at
      java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:927)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2263)
      at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1412)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2263)
      at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1412)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      at
      sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:212)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
      at
      org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProx
      y.java:129)
      at
      org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:108)
      at
      org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77
      )
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
      at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:198)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      at $Proxy0.create(Unknown Source)
      at org.apache.jsp.index$jsp._jspService(index$jsp.java:87)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at
      org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet$JspServletWrapper
      .service(IDEJspServlet.java:173)
      at
      org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.serviceJspFile(ID
      EJspServlet.java:246)
      at
      org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.service(IDEJspSer
      vlet.java:339)
      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:190)
      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.StandardContext.invoke(StandardContext.java:2347)
      at
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
      )
      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:468)
      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
      :174)
      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.connector.http.HttpProcessor.process(HttpProcessor.java:
      1027)
      at
      org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125
      )
      at java.lang.Thread.run(Thread.java:484)


      ----------------- ejb Servlet --------------------
      /**
      * This Servlet provides a user interface to an Enterprise Java Bean.
      * The example EJB described in the jBoss documentation at
      * <http://jboss.org/> calculates compound interest. This servlet
      * is based on Hello.java, distributed with Apache JServ.
      * This servlet will call the Interest EJB, passing it a few
      * parameters. The EJB will return a result, which the servlet
      * will display to the Web client.
      */
      import java.io.*;

      // Servlet stuff
      import javax.servlet.*;
      import javax.servlet.http.*;

      // EJB stuff
      import javax.naming.*;
      import java.util.Hashtable;
      import javax.rmi.PortableRemoteObject;
      import com.web_tomorrow.interest.*;


      /public class ejb extends HttpServlet {
      /**
      * Handle the GET and HEAD methods by building a simple web page.
      * HEAD is just like GET, except that the server returns only the
      * headers (including content length) not the body we write.
      */
      public void doGet (HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {

      PrintWriter out;
      String title = "Servlet interface to EJB";

      // set content type and other response header fields first
      response.setContentType("text/html");

      // then write the data of the response
      out = response.getWriter();

      out.println("");
      out.println(title);
      out.println("<BODY bgcolor=\"#FFFFFF\">");
      out.println("<H1>" + title + "</H1>");
      out.println("<H2>Calling EJB...</H2>");

      /**
      This simple servlet tests the `Interest' Enterprise JavaBean which is
      implemented in the package `com.web_tomorrow.interest'. For this to
      work, the Bean must be deployed on an EJB server.

      IMPORTANT If you want to test this in a real client-server
      configuration, this class goes on the client; the URL of the naming
      provider specifed in the class must be changed from `localhost:1099'
      to the URL of the naming service on the server
      */

      // Set up the naming provider; this may not always be necessary,
      depending
      // on how your Java system is configured.
      System.setProperty("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url",
      "ewlpasrv1");

      // Enclosing the whole process in a single `try' block is not an ideal
      way
      // to do exception handling, but I don't want to clutter the program up
      // with catch blocks
      try {
      // Get a naming context
      InitialContext jndiContext = new InitialContext();
      out.println("Got context");

      // Get a reference to the Interest Bean
      Object ref = jndiContext.lookup("examples/Interest");
      out.println("Got reference");

      // Get a reference from this to the Bean's Home interface
      InterestHome home = (InterestHome)
      PortableRemoteObject.narrow (ref, InterestHome.class);
      out.println("Got Home Interface");

      // Create an Interest object from the Home interface
      Interest interest = home.create();
      out.println("Got Interest Object from the Home interface");

      // call the calculateCompoundInterest() method to do the calculation
      out.println ("Interest on 1000 units, at 10% per period, " +
      "compounded over 2 periods is:");
      out.println (interest.calculateCompoundInterest (1000, 0.10, 2));
      } catch(Exception e) {
      out.println(e.toString());
      }

      out.println("");
      out.close();
      }
      }


      --
      To unsubscribe, e-mail: <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
      For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>

        • 1. Re: Problem in Tomcat Servlet calling JBoss EJB running on a
          mschoning

          I am running tomcat 4.04 calling an EJB on JBOSS 3.0.4.

          I am using jboss-all.jar instead of jboss.jar I don't know if that makes a difference here (I need it for webservices).

          This code works for me:

          Hashtable props = new Hashtable();
          props.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          props.put(InitialContext.PROVIDER_URL, "jnp://server3:1099");
          InitialContext ic = new InitialContext(props);

          TestEjbHome home = (TestEjbHome) PortableRemoteObject.narrow(ic.lookup(TestEjbHome.JNDI_NAME),TestEjbHome.class);
          TestEjb myBean = home.create();