<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Ejb not found on http session timeout
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/alexdev">Aliaksandr Stsiapanay</a> in <i>EJB3 Development</i> - <a href="https://community.jboss.org/message/761124#761124">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi everybody!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a problem of getting ejb local reference in Http session listener in method #sessionDestroyed(HttpSessionEvent)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>There is code snippet below:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>@WebListener</em></p><p><em>public class SessionCleanUpListener implements HttpSessionListener {</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; /**</em></p><p><em>&#160;&#160;&#160;&#160; * @see HttpSessionListener#sessionCreated(HttpSessionEvent)</em></p><p><em>&#160;&#160;&#160;&#160; */</em></p><p><em>&#160;&#160;&#160; public void sessionCreated(HttpSessionEvent arg0) {</em></p><p><em>&#160;&#160;&#160; }</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; /**</em></p><p><em>&#160;&#160;&#160;&#160; * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)</em></p><p><em>&#160;&#160;&#160;&#160; */</em></p><p><em>&#160;&#160;&#160; public void sessionDestroyed(HttpSessionEvent arg0) {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceLocator.getInstance().getWorkflowMessageManagerBean().removeNotPersistentItems(arg0.getSession().getId());</em></p><p><em>&#160;&#160;&#160; }</em>&#160;&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>}</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ServiceLocator is a utility class to obtain ejb reference.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>public class ServiceLocator {</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; private final static String JNDI_NAME_WORKFLOW_MESSAGE_MANAGER_BEAN = "java:app/EDI_EJB/WorkflowMessageManagerBean";</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; private final static ServiceLocator SERVICE_LOCATOR = new ServiceLocator();</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; private final Context context;</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; private ServiceLocator() {</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context = new InitialContext();</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (NamingException e) {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException(e);</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; }</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; public static ServiceLocator getInstance() {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return SERVICE_LOCATOR;</em></p><p><em>&#160;&#160;&#160; }</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160; public WorkflowMessageManagerBeanLocal getWorkflowMessageManagerBean() {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (WorkflowMessageManagerBeanLocal) context.lookup(JNDI_NAME_WORKFLOW_MESSAGE_MANAGER_BEAN);</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (NamingException e) {</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException(e);</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; </em></p><p><em>&#160;&#160;&#160; }</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>}</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When session timeout is triggered I got following exception in jboss console:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>13:39:52,179 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/edi]] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Session event listener threw exception: java.lang.RuntimeException: javax.naming.NameNotFoundException: java:app/EDI_EJB/WorkflowMessageManagerBean</p><p> at com.nvcm.edi.web.factory.ServiceLocator.getWorkflowMessageManagerBean(ServiceLocator.java:82) [classes(inlove)</p><p> at com.nvcm.edi.web.listener.SessionCleanUpListener.sessionDestroyed(SessionCleanUpListener.java:26) [classes(inlove)</p><p> at org.apache.catalina.session.StandardSession.expire(StandardSession.java:690) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:585) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:390) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:375) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1316) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610) [jbossweb-7.0.13.Final.jar(inlove)</p><p> at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590) [jbossweb-7.0.13.Final.jar(inlove) </p><p> at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_05]</p><p>Caused by: javax.naming.NameNotFoundException: java:app/EDI_EJB/WorkflowMessageManagerBean</p><p> at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:121)</p><p> at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)</p><p> at javax.naming.InitialContext.lookup(Unknown Source) [rt.jar:1.7.0_05]</p><p> at com.nvcm.edi.web.factory.ServiceLocator.getWorkflowMessageManagerBean(ServiceLocator.java:80) [classes(inlove)</p><p> ... 11 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We use Java 1.6, jboss-as-7.1.1.Final, Ejb 3 on our project.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Please any help?</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/761124#761124">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2030">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>