users@glassfish.java.net

Re: Access EJB 3 Local Interface from servlet

From: <glassfish_at_javadesktop.org>
Date: Wed, 19 Aug 2009 05:58:19 PDT

OK here's the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID" version="2.5">
        <display-name>ticcWeb</display-name>
        <!-- Servlets -->
        <servlet>
                <servlet-name>TiccService</servlet-name>
                <servlet-class>com.ticc.server.TiccServiceImpl</servlet-class>
        </servlet>
        <servlet-mapping>
                <servlet-name>TiccService</servlet-name>
                <url-pattern>/com.ticc.Ticc/ticc</url-pattern>
        </servlet-mapping>

        <!-- Welcome files -->
        <welcome-file-list>
                <welcome-file>Ticc.html</welcome-file>
                <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>

        <!-- EJB -->
        <ejb-local-ref>
                <ejb-ref-name>ejb/Ticc</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <local-home></local-home>
                <local>com.ticc.beans.Ticc</local>
        </ejb-local-ref>
</web-app>

Both the index.jsp and the Servlet use the ServiceLocator to obtain the Bean:
Ticc ticc = ServiceLocator.get().getTiccBean();

ServiceLocator method:
        public Ticc getTiccBean() {
                Ticc ticc = null;
                try {
                        InitialContext ctx = new InitialContext();
                        ticc = (Ticc) ctx.lookup("java:comp/env/ejb/Ticc");
                } catch (Exception e) {
                        String cause = (e.getCause() != null) ? e.getCause().getMessage() : " (no cause available)";
                        log.severe("Exception: " + e.getMessage() + ", " + cause);
                }
                return ticc;
        }

There's an Invocation Exception when I try to access Ticc.html, but index.jsp is displayed correctly.
[Message sent by forum member 'encey' (encey)]

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