<!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="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">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 3.1 Embedded EJBContainer in AS
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/ALRubinger">Andrew Rubinger</a> in <i>EJB 3.0 Development</i> - <a href="http://community.jboss.org/message/542619#542619">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I'm tracking integration of the Embedded EJB3 "EJBContainer" APIs into AS here:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="https://jira.jboss.org/jira/browse/JBAS-7964">https://jira.jboss.org/jira/browse/JBAS-7964</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The task for the "embedded" component is:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="https://jira.jboss.org/jira/browse/EJBTHREE-2083">https://jira.jboss.org/jira/browse/EJBTHREE-2083</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We now have a passing test in my development branch of AS.&#160; It:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li>Deploys a Servlet into AS</li><li>Issues an HTTP request to the Servlet</li><li>Servlet then starts a new EJBContainer and deploys a ShrinkWrap archive into it (which is a JBoss-specific extension)</li><li>Looks up the EJB proxy using EJBContainer.getContext() and invokes upon it</li><li>Returns the result to the caller</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Pending is still to split the ShrinkWrap-specific stuff out into an extension module, but it proves we're on the way to something working from inside AS.&#160; It's essentially spec API wrappers to our existing runtime.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="http://anonsvn.jboss.org/repos/jbossas/branches/TEMP_EJB3_EMBEDDABLE_JBAS-7964/embedded/src/test/java/org/jboss/jbossas/embedded/testsuite/servlet/EmbeddedEjbCallingServlet.java">http://anonsvn.jboss.org/repos/jbossas/branches/TEMP_EJB3_EMBEDDABLE_JBAS-7964/embedded/src/test/java/org/jboss/jbossas/embedded/testsuite/servlet/EmbeddedEjbCallingServlet.java</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre>/*<br/> * JBoss, Home of Professional Open Source.<br/> * Copyright 2009, Red Hat Middleware LLC, and individual contributors<br/> * as indicated by the @author tags. See the copyright.txt file in the<br/> * distribution for a full listing of individual contributors.<br/>&#160; *<br/> * This is free software; you can redistribute it and/or modify it<br/> * under the terms of the GNU Lesser General Public License as<br/> * published by the Free Software Foundation; either version 2.1 of<br/> * the License, or (at your option) any later version.<br/> *<br/> * This software is distributed in the hope that it will be useful,<br/> * but WITHOUT ANY WARRANTY; without even the implied warranty of<br/> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br/> * Lesser General Public License for more details.<br/> *<br/> * You should have received a copy of the GNU Lesser General Public<br/> * License along with this software; if not, write to the Free<br/> * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA<br/> * 02110-1301 USA, or see the FSF site: http://www.fsf.org.<br/> */<br/>package org.jboss.jbossas.embedded.testsuite.servlet;<br/><br/>import java.io.IOException;<br/>import java.util.HashMap;<br/>import java.util.Map;<br/>import java.util.logging.Logger;<br/><br/>import javax.ejb.embeddable.EJBContainer;<br/>import javax.naming.Context;<br/>import javax.naming.NamingException;<br/>import javax.servlet.ServletException;<br/>import javax.servlet.http.HttpServlet;<br/>import javax.servlet.http.HttpServletRequest;<br/>import javax.servlet.http.HttpServletResponse;<br/><br/>import org.jboss.ejb3.embedded.api.JBossEJBContainer;<br/>import org.jboss.jbossas.embedded.testsuite.ejb3.slsb.OutputBean;<br/>import org.jboss.jbossas.embedded.testsuite.ejb3.slsb.OutputLocalBusiness;<br/>import org.jboss.shrinkwrap.api.ShrinkWrap;<br/>import org.jboss.shrinkwrap.api.spec.JavaArchive;<br/><br/>/**<br/> * Servlet which forwards calls upon an EJB<br/> * via the {@link EJBContainer} API.<br/> *<br/> * @author &lt;a href="mailto:andrew.rubinger@jboss.org"&gt;ALR&lt;/a&gt;<br/> * @version $Revision: $<br/> */<br/>public class EmbeddedEjbCallingServlet extends HttpServlet<br/>{<br/><br/>&#160;&#160; //-------------------------------------------------------------------------------------||<br/>&#160;&#160; // Class Members ----------------------------------------------------------------------||<br/>&#160;&#160; //-------------------------------------------------------------------------------------||<br/><br/>&#160;&#160; /**<br/>&#160;&#160;&#160; * Logger<br/>&#160;&#160;&#160; */<br/>&#160;&#160; private static final Logger log = Logger.getLogger(EmbeddedEjbCallingServlet.class.getName());<br/><br/>&#160;&#160; /**<br/>&#160;&#160;&#160; * serialVersionUID<br/>&#160;&#160;&#160; */<br/>&#160;&#160; private static final long serialVersionUID = 1L;<br/><br/>&#160;&#160; /**<br/>&#160;&#160;&#160; * Content type to use in forwarding<br/>&#160;&#160;&#160; */<br/>&#160;&#160; private static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain";<br/><br/>&#160;&#160; //-------------------------------------------------------------------------------------||<br/>&#160;&#160; // Overridden Implementations ---------------------------------------------------------||<br/>&#160;&#160; //-------------------------------------------------------------------------------------||<br/><br/>&#160;&#160; /**<br/>&#160;&#160;&#160; * Returns the value {@link OutputLocalBusiness#OUTPUT} by invoking via an EJB<br/>&#160;&#160;&#160; * <br/>&#160;&#160;&#160; * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)<br/>&#160;&#160;&#160; */<br/>&#160;&#160; @Override<br/>&#160;&#160; protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; IOException<br/>&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160; // Log<br/>&#160;&#160;&#160;&#160;&#160; log.info("Request: " + request);<br/><br/>&#160;&#160;&#160;&#160;&#160; // Set the content-type to text<br/>&#160;&#160;&#160;&#160;&#160; response.setContentType(CONTENT_TYPE_TEXT_PLAIN);<br/><br/>&#160;&#160;&#160;&#160;&#160; // Create the EJB Container<br/>&#160;&#160;&#160;&#160;&#160; final Map&lt;String, String&gt; ejbContainerProps = new HashMap&lt;String, String&gt;();<br/>&#160;&#160;&#160;&#160;&#160; ejbContainerProps.put(EJBContainer.MODULES, ""); // Deploy no modules and do no scanning by default<br/>&#160;&#160;&#160;&#160;&#160; final JBossEJBContainer ejbContainer = (JBossEJBContainer) EJBContainer.createEJBContainer(ejbContainerProps);<br/><br/>&#160;&#160;&#160;&#160;&#160; // Define the EJB JAR<br/>&#160;&#160;&#160;&#160;&#160; final JavaArchive archive = ShrinkWrap.create("outputSlsb.jar", JavaArchive.class).addClasses(OutputBean.class,<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OutputLocalBusiness.class);<br/><br/>&#160;&#160;&#160;&#160;&#160; // Deploy the JAR<br/>&#160;&#160;&#160;&#160;&#160; ejbContainer.deploy(archive);<br/><br/>&#160;&#160;&#160;&#160;&#160; // Look up the EJB<br/>&#160;&#160;&#160;&#160;&#160; final Context context = ejbContainer.getContext();<br/>&#160;&#160;&#160;&#160;&#160; final OutputLocalBusiness bean;<br/>&#160;&#160;&#160;&#160;&#160; try<br/>&#160;&#160;&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bean = (OutputLocalBusiness) context.lookup(OutputLocalBusiness.JNDI_NAME);<br/>&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160; catch (final NamingException e)<br/>&#160;&#160;&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException("Could not find bean proxy at " + OutputLocalBusiness.JNDI_NAME, e);<br/>&#160;&#160;&#160;&#160;&#160; }<br/><br/>&#160;&#160;&#160;&#160;&#160; // Invoke<br/>&#160;&#160;&#160;&#160;&#160; final String value = bean.getOutput();<br/><br/>&#160;&#160;&#160;&#160;&#160; // Undeploy<br/>&#160;&#160;&#160;&#160;&#160; ejbContainer.undeploy(archive);<br/><br/>&#160;&#160;&#160;&#160;&#160; // Shut down EJBContainer<br/>&#160;&#160;&#160;&#160;&#160; ejbContainer.close();<br/><br/>&#160;&#160;&#160;&#160;&#160; // Write out<br/>&#160;&#160;&#160;&#160;&#160; log.info("Got value from EJB: " + value);<br/>&#160;&#160;&#160;&#160;&#160; response.getWriter().write(value);<br/>&#160;&#160; }<br/>}<br/></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>S,</p><p>ALR</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/542619#542619">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB 3.0 Development at <a href="http://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>