<!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;">
    Lookup and invoke a _local_ EJB via a remote EJB by a remote client
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/virtuellesnugat">Matthias M.</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/742757#742757">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 there,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm new to the jboss AS and the EJB. The book I've read doesn't help me, since the new JNDI naming changes so much.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>But during the last days I've managed to setup the server, deploy some remote stateful and stateless session beans. But now I'm trying something different:</p><ul><li style="text-align: start;">Local stateless session bean named "TimeBean", with it's interface "ITimeLocal"</li><li style="text-align: start;">Remote stateless session bean named "CallerBean", with it's interface "ICallerRemote"</li><li style="text-align: start;">and a remote Client named "CallerClientBean"</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;"><strong>ITimeLocal</strong></p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>package</b></font> test.jboss.umweg.server.local;
&#160;
<font color="navy"><b>import</b></font> javax.ejb.Local;
&#160;
@Local
<font color="navy"><b>public</b></font> <font color="navy"><b>interface</b></font> ITimeLocal <font color="navy">{</font>
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>long</b></font> getTime();
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>TimeBean</strong></p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>package</b></font> test.jboss.umweg.server.local;
&#160;
<font color="navy"><b>import</b></font> java.util.Date;
&#160;
<font color="navy"><b>import</b></font> javax.ejb.Local;
<font color="navy"><b>import</b></font> javax.ejb.Stateless;
&#160;
@Stateless
@Local(ITimeLocal.class)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> TimeBean <font color="navy"><b>implements</b></font> ITimeLocal <font color="navy">{</font>
&#160;
&#160;&#160;&#160; @Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>long</b></font> getTime() <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>new</b></font> Date().getTime();
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So that's just the local bean. It was deployed successfully and the JNDI Bindings where created.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The call from the CallerClientBean to the CallerBean works fine (I tested with "return 0").</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>But when I tried the real call it wouldn't work:</p><p>Extracted from <strong>CallerBean</strong></p><pre class="jive-pre"><code class="jive-code jive-java">@Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>long</b></font> askTime() <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">// lookup and invoke Local Bean, return time</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Context context = getInitialContext();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ITimeLocal szb = (ITimeLocal) context.lookup(getJndiName());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>long</b></font> time = szb.getTime();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"Time: "</font> + time);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> time;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (NamingException e) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">// TODO Auto-generated catch block</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> 0;
&#160;&#160;&#160; <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I build the <strong>InitialContext</strong> like this (<em>though I didn't set a "jboss-ejb-client.properties" on server side, <strong>maybe that's a problem</strong></em>):</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>private</b></font> InitialContext getInitialContext() <font color="navy"><b>throws</b></font> NamingException <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160; Hashtable p = <font color="navy"><b>new</b></font> Hashtable();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; p.put(Context.URL_PKG_PREFIXES, <font color="red">"org.jboss.ejb.client.naming"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>new</b></font> InitialContext(p);
&#160;&#160;&#160; <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And I tried two different<strong> JNDI</strong> names:</p><ul><li style="text-align: start;">the same I've been building the other ones:<br/>ejb:/TimeBean//TimeBean!test.jboss.umweg.server.local.ITimeLocal</li><li style="text-align: start;">and the global JNDI binding I got from the deploy:<br/>java:global/TimeBean/TimeBean!test.jboss.umweg.server.local.ITimeLocal</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;">But I guess my main-problem is, that I'm not aware of howto call a local bean. And I couldn't find anything really helpful. I didn't post the Exceptions (first runtime, the illegalState), but I bet my faults are obvious to most people here <span> :) </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;">Thanks!!</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/742757#742757">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>