users@glassfish.java.net

Re: problem accessing remote ejb and a strange fact

From: <glassfish_at_javadesktop.org>
Date: Fri, 22 Jun 2007 01:26:16 PDT

Hi,

here I post the code and three cases.

I recall that my purpose is to use a bean in a servlet; the bean i want to use has a dependency on another bean.



---------
THE CODE
---------

1) EJB_MODULE - FIRST BEAN [this bean is used in servlet, has a remote interface, has a dependency on another bean and its business method return a string]

/*
 * MyRemoteBean.java
 *
 * Created on June 21, 2007, 9:43 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.mydomain.beans;

import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author emilio
 */
@Stateless(mappedName="ejb/myMappedName")
public class MyRemoteBean implements MyRemoteRemote {

    // COMMENT OR UNCOMMENT IN ORDER TO USE REMOTE OR LOCAL INTERFACE BEAN; CURRENTLY WE USE LOCAL INTERFACE BEAN

    //_at_EJB
    //private MySecondRemoteRemote mySecondRemoteBean; // remote interface

    @EJB
    private MyLocalLocal myLocalBean; // local interface
    
    /** Creates a new instance of MyRemoteBean */
    public MyRemoteBean() {
    }

    public String myBusinessMethod() {
        //TODO implement myBusinessMethod
        return "Goodbye cruel world " + addPart();
    }
    
    private String addPart() {
        return myLocalBean.myLocalBusinessMethod(); // call local bean business method
        // return mySecondRemoteBean.mySecondBusinessMethod();
    }
}

2) EJB_MODULE - SECOND BEAN [this bean has a local interface and its business method return a string]

/*
 * MyLocalBean.java
 *
 * Created on June 21, 2007, 9:44 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.mydomain.beans;

import javax.ejb.Stateless;

/**
 *
 * @author emilio
 */
@Stateless
public class MyLocalBean implements MyLocalLocal {
    
    /** Creates a new instance of MyLocalBean */
    public MyLocalBean() {
    }

    public String myLocalBusinessMethod() {
        //TODO implement myLocalBusinessMethod
        return "I'm leaving you today... Goodbye, goodbye, goodbye...";
    }
}

3) EJB_MODULE - THIRD BEAN [this bean has a remote interface and its business method return a string]

/*
 * MySecondRemoteBean.java
 *
 * Created on June 21, 2007, 11:00 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.mydomain.beans;

import javax.ejb.Stateless;

/**
 *
 * @author emilio
 */
@Stateless
public class MySecondRemoteBean implements MySecondRemoteRemote {
    
    /** Creates a new instance of MySecondRemoteBean */
    public MySecondRemoteBean() {
    }

    public String mySecondBusinessMethod() {
        //TODO implement mySecondBusinessMethod
        return "I'm leaving you today... Goodbye, goodbye, goodbye...";
    }
}

4) WEB APPLICATION - SERVLET

/*
 * MyServlet.java
 *
 * Created on June 21, 2007, 10:01 PM
 */

package com.mydomain.servlets;

import com.mydomain.beans.MyRemoteRemote;
import java.io.*;
import java.net.*;
import javax.ejb.EJB;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author emilio
 * @version
 */
public class MyServlet extends HttpServlet {

    @EJB(name="aName", mappedName="corbaname:iiop:localhost:3700#ejb/myMappedName") // HARDCODED MAPPING
    private MyRemoteRemote myRemoteBean; // FIRST REMOTE BEAN HERE
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        /* TODO output your page here
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet MyServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet MyServlet at " + request.getContextPath () + "</h1>");
        out.println("</body>");
        out.println("</html>");
         */
        out.print(myRemoteBean.myBusinessMethod()); // RESULT STRING HERE
        out.close();
    }
    
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    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";
    }
}

5) WEB APPLICATION - WEB.XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.mydomain.servlets.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>




------------
THREE CASES
------------

1) FIRST CASE --> I'VE DEPLOYED EJB MODULE AND WEB APPLICATION SEPARATELY; THE FIRST BEAN HAS A DEPENDENCY ON THE SECOND BEAN (LOCAL INTERFACE)
I commented these lines in the first bean

...
    //_at_EJB
    //private MySecondRemoteRemote mySecondRemoteBean; // remote interface
...

In this case something didn't work; I was not able to deploy the web application.

++++++++++ APP SERV ERROR:

An error has occurred.
Deploying application in domain failed; Error loading deployment descriptors for module [MyWebApplication] -- Cannot resolve reference Unresolved Ejb-Ref com.mydomain.beans.MyRemoteBean/myLocalBean_at_jndi: @null_at_com.mydomain.beans.MyLocalLocal_at_Session@null Error loading deployment descriptors for module [MyWebApplication] -- Cannot resolve reference Unresolved Ejb-Ref com.mydomain.beans.MyRemoteBean/myLocalBean_at_jndi: @null_at_com.mydomain.beans.MyLocalLocal_at_Session@null

++++++++++ VERIFICATION RESULTS:


         ---------------------------
         STATIC VERIFICATION RESULTS
         ---------------------------

        
         ----------------------------------
         NUMBER OF FAILURES/WARNINGS/ERRORS
         ----------------------------------
         # of Failures : 1
         # of Warnings : 0
         # of Errors : 0

         -----------------------------
         RESULTS FOR WEB-RELATED TESTS
         -----------------------------
        
         --------------
         FAILED TESTS :
         --------------
        
         Test Name : tests.web.WebArchiveClassesLoadable
         Test Assertion : All classes in this Web Archive are loadable excluding classes used in JSPs. The test AllJSPsMustBeCompilable takes care of reporting non portable errors in JSP classes. Please refer to JavaEE 5 Specification Section #8.1.2 for further information.
         Test Description : For [ /home/emilio/GlassfishV1/glassfish/domains/domain1/applications/j2ee-modules/WebClient ]

Failed to find following classes:
[
        com.mailbeans.katanga.entities.Folder,
        com.mailbeans.katanga.util.RetrievalParameters
]

referenced in the following call stack :

        at com.mailbeans.katanga.retrieval.ejb.RetrievalRemote
        at com.mydomain.presentation.MyServlet


Please either bundle the above mentioned classes in the application or use optional packaging support for them.

        
          ----------------------------------
          END OF STATIC VERIFICATION RESULTS
          ----------------------------------
    

++++++++++ APP SERV COMPLETE LOG:

HERE I'VE DEPLOYED THE .ear

          ---------------------------
          STATIC VERIFICATION RESULTS
          ---------------------------

        
         ----------------------------------
         NUMBER OF FAILURES/WARNINGS/ERRORS
         ----------------------------------
         # of Failures : 0
         # of Warnings : 0
         # of Errors : 0
        
          ----------------------------------
          END OF STATIC VERIFICATION RESULTS
          ----------------------------------
    |#]

[#|2007-06-22T08:58:35.775+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.tools.avk.tools.verifier|_ThreadID=13;_ThreadName=Thread-25;|No errors found in the archive.|#]

[#|2007-06-22T08:58:35.964+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=13;_ThreadName=Thread-25;|deployed with moduleid = MyEnterpriseApplication|#]

[#|2007-06-22T08:58:37.713+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.core.transaction|_ThreadID=14;_ThreadName=Thread-24;3700;|JTS5014: Recoverable JTS instance, serverId = [3700]|#]

[#|2007-06-22T08:58:37.775+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.core|_ThreadID=14;_ThreadName=Thread-24;|About to load the system app: MEjbApp|#]

[#|2007-06-22T08:58:38.550+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.core.classloading|_ThreadID=14;_ThreadName=Thread-24;MEjbApp;|LDR5010: All ejb(s) of [MEjbApp] loaded successfully!|#]

[#|2007-06-22T08:58:38.552+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.core|_ThreadID=14;_ThreadName=Thread-24;|About to load the system app: __ejb_container_timer_app|#]

[#|2007-06-22T08:58:39.074+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.container.ejb|_ThreadID=14;_ThreadName=Thread-24;jdbc/__TimerPool;|EJB5109:EJB Timer Service started successfully for datasource [jdbc/__TimerPool]|#]

[#|2007-06-22T08:58:39.074+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.core.classloading|_ThreadID=14;_ThreadName=Thread-24;__ejb_container_timer_app;|LDR5010: All ejb(s) of [__ejb_container_timer_app] loaded successfully!|#]

[#|2007-06-22T08:58:39.209+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.container.ejb|_ThreadID=14;_ThreadName=Thread-24;|**RemoteBusinessJndiName: ejb/myMappedName; remoteBusIntf: com.mydomain.beans.MyRemoteRemote|#]

[#|2007-06-22T08:58:39.235+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.container.ejb|_ThreadID=14;_ThreadName=Thread-24;|**RemoteBusinessJndiName: com.mydomain.beans.MySecondRemoteRemote; remoteBusIntf: com.mydomain.beans.MySecondRemoteRemote|#]

[#|2007-06-22T08:58:39.260+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.core.classloading|_ThreadID=14;_ThreadName=Thread-24;MyEnterpriseApplication;|LDR5010: All ejb(s) of [MyEnterpriseApplication] loaded successfully!|#]



*** AFTER ENTERPRISE APPLICATION HAS BEEN LOADED SUCCESSFULLY, I STARTED WEB APPLICATION DEPLOYMENT ***



[#|2007-06-22T08:58:53.665+0100|WARNING|sun-appserver-pe9.0|org.apache.coyote.tomcat5.CoyoteRequest|_ThreadID=15;_ThreadName=httpWorkerThread-4848-0;_RequestID=c3b1c1e6-ca88-4fde-9cbf-0a8bb30ee7fa;|Unable to set character encoding UTF-8 because request parameters have already been read, or ServletRequest.getReader() has been called|#]

[#|2007-06-22T08:58:56.074+0100|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=16;_ThreadName=Thread-32;_RequestID=ce3932a3-1b3b-43a1-9da1-a0695c114a75;|Cannot resolve reference Unresolved Ejb-Ref com.mydomain.beans.MyRemoteBean/myLocalBean_at_jndi: @null_at_com.mydomain.beans.MyLocalLocal_at_Session@null|#]

[#|2007-06-22T08:58:56.079+0100|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=16;_ThreadName=Thread-32;_RequestID=ce3932a3-1b3b-43a1-9da1-a0695c114a75;|Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Error loading deployment descriptors for module [MyWebApplication] -- Cannot resolve reference Unresolved Ejb-Ref com.mydomain.beans.MyRemoteBean/myLocalBean_at_jndi: @null_at_com.mydomain.beans.MyLocalLocal_at_Session@null
        at com.sun.enterprise.deployment.backend.Deployer.loadDescriptors(Deployer.java:362)
        at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:395)
        at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:155)
        at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:160)
        at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
        at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
        at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
        at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
        at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
        at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
        at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)
Caused by: java.lang.RuntimeException: Cannot resolve reference Unresolved Ejb-Ref com.mydomain.beans.MyRemoteBean/myLocalBean_at_jndi: @null_at_com.mydomain.beans.MyLocalLocal_at_Session@null
        at com.sun.enterprise.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:405)
        at com.sun.enterprise.deployment.WebBundleDescriptor.visit(WebBundleDescriptor.java:1408)
        at com.sun.enterprise.deployment.archivist.WebArchivist.validate(WebArchivist.java:175)
        at com.sun.enterprise.deployment.archivist.ApplicationArchivist.openArchive(ApplicationArchivist.java:777)
        at com.sun.enterprise.deployment.archivist.ApplicationArchivist.openArchive(ApplicationArchivist.java:731)
        at com.sun.enterprise.deployment.backend.Deployer.loadDescriptors(Deployer.java:327)
        ... 10 more
|#]











2) SECOND CASE --> I'VE DEPLOYED EJB MODULE AND WEB APPLICATION SEPARATELY; THE FIRST BEAN HAS A DEPENDENCY ON THE THIRD BEAN (REMOTE INTERFACE)
I commented these lines in the first bean

...
    //_at_EJB
    //private MyLocalLocal myLocalBean; // local interface
...

and uncommented

...
    @EJB
    private MySecondRemoteRemote mySecondRemoteBean; // remote interface
...

In this case no problem occurred. I was able to deploy web application and all worked fine.










3) THIRD CASE --> I ADDED WEB APPLICATION IN .EAR AS A WEB MODULE OF THE SAME ENTERPRISE APPLICATION; THE FIRST BEAN HAS A DEPENDENCY ON THE SECOND BEAN (LOCAL INTERFACE)
In this case no problem occurred. I was able to deploy the enterprise application and all worked fine.
[Message sent by forum member 'emilioremogna' (emilioremogna)]

http://forums.java.net/jive/thread.jspa?messageID=223481