10 Replies Latest reply on Mar 21, 2002 4:50 AM by tom_doehler

    getting dom from session bean fails

    tom_doehler

      Hi,

      i try to get an DOM - object from a simple session bean. I used jaxp with xerces implementation. The session bean creates a simple dom document, and adds one element to it. The session bean has a method getXml() , which returns the xml document. If i call the getXml() from a client , i get the following error:

      snip -----

      java.lang.NullPointerException
      at org.apache.xerces.dom.ParentNode.readObject(ParentNode.java:964)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java:2213)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1410)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2262)
      at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
      at org.apache.xerces.dom.ParentNode.readObject(ParentNode.java:956)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java:2213)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1410)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      at java.rmi.MarshalledObject.get(MarshalledObject.java:138)
      at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericProxy.java:357)
      at org.jboss.ejb.plugins.jrmp.interfaces.StatelessSessionProxy.invoke(StatelessSessionProxy.java:123)
      at $Proxy1.getDoc(Unknown Source)

      snap -----

      I have tried the same sample on a different application server and it works fine there. Does anyone have an idea how to fix this ?

        • 1. Re: getting dom from session bean fails

          Have you changed JBoss to use xerces? It uses crimson
          by default.

          The method you are using isn't portable between
          DOM implementations.
          I'm not even sure crimson implements serializable?

          Look at the jaxp FAQ for more information
          http://java.sun.com/xml/jaxp/faq.html

          Regards,
          Adrian

          • 2. Re: getting dom from session bean fails
            tom_doehler

            Hi,

            thank you for your answer. I configured jboss to us the xerces/xalan implementation: i use the following lines in run.bat :

            set JBOSS_CLASSPATH=%JBOSS_CLASSPATH%;../lib/xerces.jar;../lib/xalan.jar

            set JAXP=-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
            set JAXP=%JAXP% -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
            set JAXP=%JAXP% -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl

            This should tell jboss to use the xerces implementation, right? I also replaced the xerces.jar in catalina/common/lib with the same version that is in jboss/lib/ext .

            I still cant figure out what i did wrong.

            Does anyone have further suggestions ??

            Thanks a lot.

            Bye Tom

            • 3. Re: getting dom from session bean fails

              Do you have an error on the server side.
              Have a look in log/server.log

              Regards,
              Adrian

              • 4. Re: getting dom from session bean fails
                tom_doehler

                Hi,

                I have tried another thing: i wrote a second session bean, that calls the same method from the first session bean, and evereything works fine: the method returns the correct Document. Maybe this is a classpath problem, could it be that catalina uses another Implementation than jboss ?

                Bye tom

                • 5. Re: getting dom from session bean fails

                  I think Tomcat uses xerces.
                  I would expect a ClassCastException if the problem
                  was on the Tomcat side. i.e. the object reaches Tomcat
                  but it is the wrong class.

                  The NullPointerException suggests either a
                  Serialization problem on the server side or a coding
                  error.

                  Have you tried printing the class name on the server side
                  to make sure it is a xerces implementation?

                  Regards,
                  Adrian

                  • 6. Re: getting dom from session bean fails
                    tom_doehler

                    Hi,

                    I used JBuilders remote debugger to verify that both (the ejb and the servlet) use the org.apache.xerces.dom.DocumentImpl - Object. They do. I checked the Xerces-J 2.0 apidocs to see if this object implements java.io.serializable, and it does. So there should be no problem getting this document thru a remote call.

                    here are some code - snipplets:

                    My session bean ,,XmlTesterBean'' , has the following business-method that returns the DOM - Object :

                    public Document getDoc() throws RemoteException{
                    DocumentBuilderFactory dbf;
                    DocumentBuilder db ;
                    Document doc ;
                    Element main;

                    try{
                    System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                    "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
                    dbf = new DocumentBuilderFactory();
                    db = dbf.newDocumentBuilder() ;
                    }catch(ParserConfigurationException pce){
                    throw new RemoteException("Error Creating XML-Parser: " + pce.getMessage() );
                    }
                    doc = db.newDocument() ;
                    main = doc.createElement("TestElement");
                    doc.appendChild(main) ;

                    return doc;
                    }

                    This method is called from an servlet as shown below:
                    //tester is an remote reference for XmlTesterBean
                    Document doc = (Document) tester.getDoc() ;

                    If the servlet tries to call this method, i get the following exception (in jboss.log) :

                    [ERROR,Default] java.lang.NullPointerException
                    [ERROR,Default] at $Proxy30.getDoc(Unknown Source)
                    [ERROR,Default] at com.jbossdemo.webapp.ArticleViewServlet.doGet(Article
                    ViewServlet.java:88)
                    [ERROR,Default] at javax.servlet.http.HttpServlet.service(HttpServlet.ja
                    va:740)
                    [ERROR,Default] at javax.servlet.http.HttpServlet.service(HttpServlet.ja
                    va:853)
                    [ERROR,Default] at org.apache.catalina.core.ApplicationDispatcher.invoke
                    (ApplicationDispatcher.java:679)
                    [ERROR,Default] at org.apache.catalina.core.ApplicationDispatcher.doForw
                    ard(ApplicationDispatcher.java:431)
                    [ERROR,Default] at org.apache.catalina.core.ApplicationDispatcher.forwar
                    d(ApplicationDispatcher.java:355)
                    [ERROR,Default] at com.jbossdemo.webapp.FrontController.doGet(FrontContr
                    oller.java:180)
                    [ERROR,Default] at javax.servlet.http.HttpServlet.service(HttpServlet.ja
                    va:740)
                    [ERROR,Default] at javax.servlet.http.HttpServlet.service(HttpServlet.ja
                    va:853)
                    [ERROR,Default] at org.apache.catalina.core.ApplicationFilterChain.inter
                    nalDoFilter(ApplicationFilterChain.java:247)
                    [ERROR,Default] at org.apache.catalina.core.ApplicationFilterChain.doFil
                    ter(ApplicationFilterChain.java:193)
                    [ERROR,Default] at org.apache.catalina.core.StandardWrapperValve.invoke(
                    StandardWrapperValve.java:243)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:566)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invoke(Stan
                    dardPipeline.java:472)
                    [ERROR,Default] at org.apache.catalina.core.ContainerBase.invoke(Contain
                    erBase.java:943)
                    [ERROR,Default] at org.apache.catalina.core.StandardContextValve.invoke(
                    StandardContextValve.java:201)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:566)
                    [ERROR,Default] at org.apache.catalina.valves.CertificatesValve.invoke(C
                    ertificatesValve.java:246)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:564)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invoke(Stan
                    dardPipeline.java:472)
                    [ERROR,Default] at org.apache.catalina.core.ContainerBase.invoke(Contain
                    erBase.java:943)
                    [ERROR,Default] at org.apache.catalina.core.StandardContext.invoke(Stand
                    ardContext.java:2344)
                    [ERROR,Default] at org.apache.catalina.core.StandardHostValve.invoke(Sta
                    ndardHostValve.java:164)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:566)
                    [ERROR,Default] at org.apache.catalina.valves.ErrorDispatcherValve.invok
                    e(ErrorDispatcherValve.java:170)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:564)
                    [ERROR,Default] at org.apache.catalina.valves.ErrorReportValve.invoke(Er
                    rorReportValve.java:170)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:564)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invoke(Stan
                    dardPipeline.java:472)
                    [ERROR,Default] at org.apache.catalina.core.ContainerBase.invoke(Contain
                    erBase.java:943)
                    [ERROR,Default] at org.apache.catalina.core.StandardEngineValve.invoke(S
                    tandardEngineValve.java:163)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(
                    StandardPipeline.java:566)
                    [ERROR,Default] at org.apache.catalina.core.StandardPipeline.invoke(Stan
                    dardPipeline.java:472)
                    [ERROR,Default] at org.apache.catalina.core.ContainerBase.invoke(Contain
                    erBase.java:943)
                    [ERROR,Default] at org.apache.catalina.connector.http.HttpProcessor.proc
                    ess(HttpProcessor.java:1011)
                    [ERROR,Default] at org.apache.catalina.connector.http.HttpProcessor.run(
                    HttpProcessor.java:1106)
                    [ERROR,Default] at java.lang.Thread.run(Thread.java:484)

                    It seems like jboss can't marshall the DOM - Object. If i call getDoc() from another session bean, it returns the DOM - Object without any errors. I'm not sure , but maybe this can be because jboss recognizes that this is a local call and returns the reference without marshalling (?).

                    I tried the same sample in another application server, and there it works properly.

                    Does anyone have an idea how to fix that ?

                    Bye tom

                    • 7. Re: getting dom from session bean fails

                      From your original stack trace, it isn't using
                      local optimizations.

                      http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/Attic/GenericProxy.java?annotate=1.11

                      line 357 is where you get the failure, it doesn't even
                      think it is local.
                      So it is using a different copy of the ContainerRemote class.

                      Which version of JBoss/Tomcat are you using? How is it
                      configured? How have you packaged things?

                      This should still work when it is remote. Can you
                      try an example with a simpler value object?

                      Regards,
                      Adrian

                      • 8. Re: getting dom from session bean fails
                        tom_doehler

                        Hi ,

                        > line 357 is where you get the failure, it doesn't
                        > even
                        > think it is local.
                        > So it is using a different copy of the
                        > ContainerRemote class.

                        right, what I have posted is the sample where i try to call the business - method from a servlet. This should be a ordinary remote call.

                        I use JBoss 2.4.4/Tomcat 4.0.1 bundle. I have packaged the application into 1 ear:

                        1 jar-file for the enterprise beans
                        1 war-file for the web-application

                        these both together are in a EAR file, which I put into jboss /deploy directory. ´

                        Xerces-J 2.0 comes with a TestTool , which checks for the environment settings of the application. I used this TestTool from within a jsp , and it reported that everything is set up correctly.

                        Should i post the output from that TestTool? I even checked the mailing list archives at xml.apache.org , but there are no bugs or errors reported for this problem.

                        Bye Tom

                        • 9. Re: getting dom from session bean fails

                          I found this bug report about document serialization.

                          http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=6632

                          Do you have the fixed version?

                          Regards,
                          Adrian

                          • 10. Re: getting dom from session bean fails
                            tom_doehler

                            Hi,

                            it lookes like it was the xerces bug. I tried my sample bean with xerces-j 1.4 , and evereything works fine.

                            Thank you.

                            Bye Tom