blob: 9c6f301274833236f8c7b04f2d830acd57e9044b [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<!-- $PAGETITLE -->
<TITLE>OpenEJB - Embedded and Remotable</TITLE>
<LINK href="http://openejb.apache.org/all.css" rel="stylesheet" type="text/css">
<!--[if IE]><link rel="stylesheet" type="text/css" media="screen, projection" href="openejb.apache.org/ie.css"><![endif]-->
<LINK rel="SHORTCUT ICON" href="http://openejb.apache.org/images/favicon.ico">
<SCRIPT language="JavaScript" src="http://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=OPENEJB&title=functions.js" type="text/javascript"></SCRIPT>
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
</HEAD>
<BODY>
<!-- Delay the loading of the external javascript file needed for labels (as it takes too long to load and visibly holds loading of the page body) -->
<!-- To do this without javascript errors over undefined functions, we need to declare stubs here (that are overrided later by the proper implementations) -->
<SCRIPT language="JavaScript" type="text/javascript">
function doAddLabel(hideTextfieldAfterAddParam)
{
// stub
}
function onAddLabel()
{
// stub
}
function showLabelsInput()
{
// stub
}
</SCRIPT>
<A name="top"></A>
<TABLE class="frameTable" cellpadding="0" cellspacing="0" border="0">
<TR class="Row1">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row2">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3" id="breadcrumbs">
<!-- $TOP_NAV_BAR -->
<A href="index.html" title="Index">Index</A> | <A href="news.html" title="News">News</A> | <A href="faq.html" title="FAQ">FAQ</A> | <A href="download.html" title="Download">Download</A> | <A href="mailing-lists.html" title="Mailing Lists">Lists</A> | <SPAN class="nobr"><A href="http://issues.apache.org/jira/browse/OPENEJB" title="Visit page outside Confluence" rel="nofollow">Issues<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN>
</TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
<TR class="Row3">
<TD class="Col1"><IMG alt="" class="Row3Img" id="thinLine" src="http://openejb.apache.org/images/line_sm.gif"></TD>
<TD class="Col2"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row4">
<TD class="Col1">
<SPAN id="Navigation">
<H3><A name="Navigation-Overview"></A>Overview</H3>
<UL class="alternate" type="square">
<LI><A href="index.html" title="Index">Home</A></LI>
<LI><A href="news.html" title="News">News</A></LI>
<LI><A href="faq.html" title="FAQ">FAQ</A></LI>
<LI><A href="download.html" title="Download">Download</A></LI>
<LI><A href="../OPENEJBx30/examples.html" title="Examples">OPENEJBx30:Examples</A></LI>
<LI><A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A></LI>
<LI><A href="source-code.html" title="Source Code">Source Code</A></LI>
</UL>
<H3><A name="Navigation-General"></A>General</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJBx30/deploy-tool.html" title="Deploy Tool">Deployment</A></LI>
<LI><A href="../OPENEJBx30/startup.html" title="Startup">Startup</A></LI>
<LI><A href="validation-tool.html" title="Validation Tool">Validation</A></LI>
<LI><A href="webadmin.html" title="Webadmin">Webadmin</A></LI>
</UL>
<H3><A name="Navigation-Configuration"></A>Configuration</H3>
<UL class="alternate" type="square">
<LI><A href="configuration.html" title="Configuration">General</A></LI>
<LI><A href="../OPENEJBx30/deployments.html" title="Deployments">Deployments</A></LI>
<LI><A href="containers.html" title="Containers">Containers</A></LI>
</UL>
<H3><A name="Navigation-Servers"></A>Servers</H3>
<UL class="alternate" type="square">
<LI><A href="local-server.html" title="Local Server">Local</A></LI>
<LI><A href="remote-server.html" title="Remote Server">Remote</A></LI>
</UL>
<H3><A name="Navigation-Integrations"></A>Integrations</H3>
<UL class="alternate" type="square">
<LI><A href="tomcat.html" title="Tomcat">Tomcat</A></LI>
<LI><A href="geronimo.html" title="Geronimo">Geronimo</A></LI>
<LI><A href="webobjects.html" title="WebObjects">WebObjects</A></LI>
</UL>
<H3><A name="Navigation-Community"></A>Community</H3>
<UL class="alternate" type="square">
<LI><A href="team.html" title="Team">Team</A></LI>
<LI><A href="articles.html" title="Articles">Articles</A></LI>
<LI><A href="annoyances.html" title="Annoyances">Annoyances</A></LI>
<LI><SPAN class="nobr"><A href="index.html" title="Visit page outside Confluence" rel="nofollow">Wiki<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI>
<LI><SPAN class="nobr"><A href="irc://irc.freenode.net/#openejb" title="Visit page outside Confluence" rel="nofollow">IRC<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI>
</UL>
<H3>
<A name="Navigation-Feeds"></A>
Feeds
</H3>
<UL class="feeds">
<LI>
<A href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">Site</A>
</LI>
<LI><A href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">News</A>
</LI>
</UL>
</SPAN>
</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<TABLE id="PageHeader" border="0" width="100%">
<TR>
<TD>
<A href="http://openejb.org/">
<IMG hspace="0" src="http://openejb.apache.org/images/logo_openejb.gif" vspace="0">
</A>
</TD>
<TD align="right">
<A href="http://www.apache.org/">
<IMG src="http://www.apache.org/images/asf-logo.gif" width="258" height="66">
</A>
</TD>
</TR>
<TR>
<TD id="page_title">
<!-- $TITLE -->
Embedded and Remotable
</TD>
<TD align="right">
<BR><BR>
<!-- Google CSE Search Box Begins -->
<FORM id="searchbox_010475492895890475512:_t4iqjrgx90" action="http://www.google.com/cse">
<INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
<INPUT type="hidden" name="cof" value="FORID:0">
<INPUT name="q" type="text" size="25">
<INPUT type="submit" name="sa" value="Search">
</FORM>
<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>
<!-- Google CSE Search Box Ends -->
</TD>
</TR>
</TABLE>
<P>
<!-- $BODY -->
<DIV id="PageContent">
<H1><A name="EmbeddedandRemotable-Overview"></A>Overview</H1>
<P>This example shows how to use OpenEJB3's remoting capabilities in an embedded scenario.</P>
<P>The basic recipe is the same for a standard embedded scenario but with these added
ingreditents:</P>
<UL>
<LI><B>openejb.embedded.remotable</B> property</LI>
<LI><B>openejb-ejbd</B> jar</LI>
</UL>
<P>While creating the InitialContext, pass in the openejb.embedded.remotable property with
the value of &quot;true&quot;. When this is seen by the LocalInitialContextFactory, it will boot up
the Server ServiceManager in the VM which will in turn look for ServerServices in the
classpath.</P>
<P>Provided you have the openejb-ejbd jar in your classpath along with it's dependencies
(openejb-server, openejb-client, openejb-core), then those services will be brought online
and remote clients will be able to connect into your vm and invoke beans.</P>
<P>If you want to add more ServerServices such as the http version of the ejbd protocol you'd
simply add the openejb-httpejbd jar to your classpath. A number of ServerServices are
available currently:</P>
<UL>
<LI>openejb-ejbd</LI>
<LI>openejb-http</LI>
<LI>openejb-telnet</LI>
<LI>openejb-derbynet</LI>
<LI>openejb-hsql</LI>
<LI>openejb-activemq</LI>
</UL>
<P>To run the example simply type:</P>
<P> $ mvn clean install</P>
<TABLE cellpadding="5" width="85%" cellspacing="8px" class="noteMacro" border="0" align="center"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>
<P>If your goal is simply to unit test beans with remote interfaces, this is <B>not</B> the right example for you. The LocalInitialContextFactory completely supports remote interfaces and all spec required pass-by-value (serialization) semantics without the need for network sockets. This example shows the use of OpenEJB in an embedded environment where connection <B>outside</B> the <BR>
vm is required.</P></TD></TR></TABLE>
<H1><A name="EmbeddedandRemotable-TheCode"></A>The Code</H1>
<P>For this example we have a simple Stateful bean called TelephoneBean as defined below. As a simple way of demonstrating the state we have to methods: speak and listen. You call <EM>speak</EM> and pass in some text, then you call <EM>listen</EM> to get your answer.</P>
<H5><A name="EmbeddedandRemotable-bean"></A>bean</H5>
An error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/main/java/org/apache/openejb/examples/telephone/TelephoneBean.java. The system administrator has been notified.
<H5><A name="EmbeddedandRemotable-businessinterface"></A>business interface</H5>
An error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/main/java/org/apache/openejb/examples/telephone/Telephone.java. The system administrator has been notified.
<TABLE cellpadding="5" width="85%" cellspacing="8px" class="tipMacro" border="0" align="center"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B class="strong">EJB3 Notes</B><BR>
<P>The bean class uses the annotation <B>@Remote</B> but does not specify a list of interfaces as is normally required. Per EJB3 rules, if the bean implements exactly <B>one business interface</B> it may use @Remote with no other values and that business interface is then implied to be a remote business interface. The same rule applies to identical usage of @Local.</P>
<P>The critical thing to know is that if you add another interface the rules change and require that you specify both interfaces in the @Remote annotation as in @Remote({Telephone.class, SecondInterface.class}).</P></TD></TR></TABLE>
<H1><A name="EmbeddedandRemotable-Embedding"></A>Embedding</H1>
<P>We're going to embed OpenEJB3 into a plain JUnit TestCase as a simple means of demonstrating the remote capabilities. We'll do the embedding in our test setUp method, then will make two test methods: </P>
<UL class="alternate" type="square">
<LI>one for invoking the bean's remote interface via the <B>LocalInitialContextFactory</B> which goes straight against the embedded container system</LI>
<LI>one for invoking the bean's remote interface via the <B>RemoteInitialContextFactory</B> which connects to a Socket and communicates to the embedded container system over the ejbd protocol.</LI>
</UL>
<H4><A name="EmbeddedandRemotable-setUp"></A>setUp</H4>
An error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java. The system administrator has been notified.
<H4><A name="EmbeddedandRemotable-LocalInitialContextFactory%3Amakinginvmcallstoaremotebusinessinterface"></A>LocalInitialContextFactory: making in-vm calls to a remote business interface</H4>
An error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java. The system administrator has been notified.
<H4><A name="EmbeddedandRemotable-RemoteInitialContextFactory%3Amakingnetworkedcallstoaremotebusinessinterface"></A>RemoteInitialContextFactory: making networked calls to a remote business interface</H4>
<P>This is the part you would want to do in apps that are running a different VM than the one in which the ejb container is embedded. These &quot;client&quot; VMs need only have the the <B>openejb-client jar</B> in their classpath and connect to OpenEJB via the RemoteInitialContextFactory like any other remote EJB client.</P>
An error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java. The system administrator has been notified.
<H1><A name="EmbeddedandRemotable-Mavensetup"></A>Maven setup</H1>
<P>Nice thing about maven2 is it has test-only dependencies.
This guarantees that non of your runtime code is dependent
on any OpenEJB classes.</P>
<P>You need this dep or no clients will be able to connect
over the ejbd protocol to the embedded ejb container.</P>
<P>Notice the other examples use 'openejb-core' and this one
uses 'openejb-ejbd'. If you wanted to make more protocols
available, you simply have to add deps to them and they'll
get picked up in the classpath automatically.</P>
<DIV class="code"><DIV class="codeContent">
<PRE class="code-xml"><SPAN class="code-tag">&lt;dependency&gt;</SPAN>
<SPAN class="code-tag">&lt;groupId&gt;</SPAN>org.apache.openejb<SPAN class="code-tag">&lt;/groupId&gt;</SPAN>
<SPAN class="code-tag">&lt;artifactId&gt;</SPAN>openejb-ejbd<SPAN class="code-tag">&lt;/artifactId&gt;</SPAN>
<SPAN class="code-tag">&lt;version&gt;</SPAN>3.0.0-SNAPSHOT<SPAN class="code-tag">&lt;/version&gt;</SPAN>
<SPAN class="code-tag">&lt;scope&gt;</SPAN>test<SPAN class="code-tag">&lt;/scope&gt;</SPAN>
<SPAN class="code-tag">&lt;/dependency&gt;</SPAN></PRE>
</DIV></DIV>
<H1><A name="EmbeddedandRemotable-Running"></A>Running</H1>
<P>Running the example is fairly simple, just run:</P>
<P>$ cd telephone-stateful<BR>
$ mvn clean install</P>
<P>Which should create output like the following.</P>
<DIV class="preformatted"><DIV class="preformattedContent">
<PRE>[OPENEJB:INFO] Scanning for projects...
[OPENEJB:INFO] ----------------------------------------------------------------------------
[OPENEJB:INFO] Building OpenEJB :: Examples :: Telephone Stateful Pojo
[OPENEJB:INFO] task-segment: [OPENEJB:clean, install]
[OPENEJB:INFO] ----------------------------------------------------------------------------
[OPENEJB:INFO] [clean:clean]
[OPENEJB:INFO] Deleting directory /Users/dblevins/work/openejb3/examples/telephone-stateful/target
[OPENEJB:INFO] Deleting directory /Users/dblevins/work/openejb3/examples/telephone-stateful/target/classes
[OPENEJB:INFO] Deleting directory /Users/dblevins/work/openejb3/examples/telephone-stateful/target/test-classes
[OPENEJB:INFO] [resources:resources]
[OPENEJB:INFO] Using default encoding to copy filtered resources.
[OPENEJB:INFO] [compiler:compile]
Compiling 2 source files to /Users/dblevins/work/openejb3/examples/telephone-stateful/target/classes
[OPENEJB:INFO] [resources:testResources]
[OPENEJB:INFO] Using default encoding to copy filtered resources.
[OPENEJB:INFO] [compiler:testCompile]
Compiling 1 source file to /Users/dblevins/work/openejb3/examples/telephone-stateful/target/test-classes
[OPENEJB:INFO] [surefire:test]
[OPENEJB:INFO] Surefire report directory: /Users/dblevins/work/openejb3/examples/telephone-stateful/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.apache.openejb.examples.telephone.TelephoneTest
log4j:WARN No appenders could be found for logger (OpenEJB).
log4j:WARN Please initialize the log4j system properly.
Apache OpenEJB 3.0-incubating-SNAPSHOT build: 20061228-01:59
http://incubator.apache.org/openejb
23:04:38,699 INFO [Startup] Found EjbModule in classpath: /Users/dblevins/work/openejb3/examples/telephone-stateful/target/classes
23:04:39,625 WARN [Startup] No ejb-jar.xml found assuming annotated beans present
23:04:39,658 WARN [OPENEJB:OpenEJB] Auto-deploying ejb TelephoneBean: EjbDeployment(deployment-id=TelephoneBean, container-id=Default Stateful Container)
23:04:39,659 WARN [OPENEJB:OpenEJB] Auto-creating a container for bean TelephoneBean: Container(type=STATEFUL, id=Default Stateful Container)
23:04:39,678 INFO [Startup] Loaded Module: /Users/dblevins/work/openejb3/examples/telephone-stateful/target/classes
23:04:40,140 INFO [Startup] OpenEJB ready.
OpenEJB ready.
** Starting Services **
NAME IP PORT
ejbd 0.0.0.0 4201
admin thread 0.0.0.0 4200
-------
Ready!
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.899 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[OPENEJB:INFO] [jar:jar]
[OPENEJB:INFO] Building jar: /Users/dblevins/work/openejb3/examples/telephone-stateful/target/telephone-stateful-1.0-SNAPSHOT.jar
[OPENEJB:INFO] [install:install]
[OPENEJB:INFO] Installing /Users/dblevins/work/openejb3/examples/telephone-stateful/target/telephone-stateful-1.0-SNAPSHOT.jar to ...
[OPENEJB:INFO] ------------------------------------------------------------------------
[OPENEJB:INFO] BUILD SUCCESSFUL
[OPENEJB:INFO] ------------------------------------------------------------------------
[OPENEJB:INFO] Total time: 11 seconds
[OPENEJB:INFO] Finished at: Thu Dec 28 23:04:41 PST 2006
[OPENEJB:INFO] Final Memory: 19M/254M
[OPENEJB:INFO] ------------------------------------------------------------------------
</PRE>
</DIV></DIV>
</DIV>
</P>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">
</TD>
</TR>
<TR class="Row5">
<TD class="Col1">&nbsp;</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<BR>
<BR>
<IMG width="100%" height="1" src="http://openejb.apache.org/images/line_light.gif">
<TABLE width="100%">
<TR>
<TD>
<SPAN class="bodyGrey">
<SMALL>
<NOTICE><!-- $FOOTER -->
Apache OpenEJB is an project of The Apache Software Foundation (ASF)
</NOTICE>
<BR>
Site Powered by
<A href="http://atlassian.com/">Atlassian</A>
<A href="http://atlassian.com/confluence/">Confluence</A>
.
</SMALL>
</SPAN>
</TD>
<TD align="right">
<A style="color:#999;font-size:small;font-weight:normal;" href="http://cwiki.apache.org/confluence/pages/editpage.action?spaceKey=OPENEJB&title=Embedded%20and%20Remotable">[ edit ]</A>
</TD>
</TR>
</TABLE>
<BR>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
</TABLE>
<!-- Needed for composition plugin -->
<!-- delay the loading of large javascript files to the end so that they don't interfere with the loading of page content -->
<SPAN style="display: none">
<SCRIPT type="text/javascript" language="JavaScript" src="http://cwiki.apache.org/confluence/labels-javascript"></SCRIPT>
<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript">
_uacct = "UA-2717626-1";
urchinTracker();
</SCRIPT>
</SPAN>
</BODY>
</HTML>