Modified:
websites/staging/openejb/trunk/content/resource-ref-for-datasource.html
==============================================================================
--- websites/staging/openejb/trunk/content/resource-ref-for-datasource.html
(original)
+++ websites/staging/openejb/trunk/content/resource-ref-for-datasource.html Mon
Jul 11 02:31:36 2011
@@ -2,7 +2,7 @@
<HTML>
<HEAD>
<!-- $PAGETITLE -->
- <title>resource-ref for DataSource</title>
+ <title></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]-->
@@ -130,7 +130,7 @@
<TR>
<TD id="page_title">
<!-- $TITLE -->
- resource-ref for DataSource
+
</TD>
<TD align="right">
@@ -152,14 +152,11 @@
<P>
<!-- $BODY -->
<DIV id="PageContent">
- <p><a name="resource-refforDataSource-Viaannotation"></a></p>
+ <h1>Via annotation</h1>
-<h1>Via annotation</h1>
+<pre><code>package org.superbiz.refs;
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style: solid;"><B>Usable by EJB, Interceptor, Servlet,
Filter, or Listener</B></DIV><DIV class="codeContent panelContent">
- package org.superbiz.refs;</p>
-
-<pre><code>import javax.annotation.Resource;
+import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.sql.DataSource;
@@ -172,44 +169,33 @@ public class MyDataSourceRefBean impleme
private DataSource myBarDataSource;
public void someBusinessMethod() throws Exception {
- if (myBarDataSource == null) throw new
-</code></pre>
-
-<p>NullPointerException("myBarDataSource not injected");</p>
+ if (myBarDataSource == null) throw new
NullPointerException("myBarDataSource not injected");
-<pre><code> // Both can be looked up from JNDI as well
- InitialContext context = new InitialContext();
- DataSource fooDataSource = (DataSource)
+ // Both can be looked up from JNDI as well
+ InitialContext context = new InitialContext();
+ DataSource fooDataSource = (DataSource)
context.lookup("java:comp/env/myFooDataSource");
+ DataSource barDataSource = (DataSource)
context.lookup("java:comp/env/org.superbiz.refs.MyDataSourceRefBean/myBarDataSource");
+ }
+}
</code></pre>
-<p>context.lookup("java:comp/env/myFooDataSource");
- DataSource barDataSource = (DataSource)
-context.lookup("java:comp/env/org.superbiz.refs.MyDataSourceRefBean/myBarDataSource");
- }
- }</p>
-
-<p><a name="resource-refforDataSource-Viaxml"></a></p>
-
<h1>Via xml</h1>
-<p>The above @Resource annotation usage is 100% equivalent to the following
-xml.</p>
+<p>The above @Resource annotation usage is 100% equivalent to the following
xml.</p>
-<p>{code:xml|title=ejb-jar.xml or web.xml}
-<resource-ref>
- <res-ref-name>myFooDataSource</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
-</resource-ref>
-<resource-ref></p>
-
-<p><res-ref-name>org.superbiz.refs.MyDataSourceRefBean/myBarDataSource</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <injection-target></p>
-
-<p><injection-target-class>org.superbiz.refs.MyDataSourceRefBean</injection-target-class>
- <injection-target-name>myBarDataSource</injection-target-name>
- </injection-target>
-</resource-ref></p>
+<pre><code><resource-ref>
+ <res-ref-name>myFooDataSource</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+</resource-ref>
+<resource-ref>
+
<res-ref-name>org.superbiz.refs.MyDataSourceRefBean/myBarDataSource</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ <injection-target>
+
<injection-target-class>org.superbiz.refs.MyDataSourceRefBean</injection-target-class>
+
<injection-target-name>myBarDataSource</injection-target-name>
+ </injection-target>
+</resource-ref>
+</code></pre>
</DIV>
</P>
Modified: websites/staging/openejb/trunk/content/securing-a-web-service.html
==============================================================================
--- websites/staging/openejb/trunk/content/securing-a-web-service.html
(original)
+++ websites/staging/openejb/trunk/content/securing-a-web-service.html Mon Jul
11 02:31:36 2011
@@ -241,12 +241,11 @@ the same as if you would use a common ja
<properties>
wss4j.in.action = UsernameToken
wss4j.in.passwordType = PasswordDigest
+ wss4j.in.passwordCallbackClass=org.superbiz.calculator.CustomPasswordHandler
+</properties>
+[...]
</code></pre>
-<p>wss4j.in.passwordCallbackClass=org.superbiz.calculator.CustomPasswordHandler
- </properties>
- [...]</p>
-
<p>In order to recover WSS4J properties both for input and output, we use
naming conventions.
Each property is made of </p>
@@ -277,16 +276,15 @@ Each property is made of </p>
<properties>
wss4j.in.action = UsernameToken
wss4j.in.passwordType = PasswordDigest
+
wss4j.in.passwordCallbackClass=org.superbiz.calculator.CustomPasswordHandler
+ </properties>
+ </web-service-security>
+ </session>
+ ...
+ </enterprise-beans>
+</openejb-jar>
</code></pre>
-<p>wss4j.in.passwordCallbackClass=org.superbiz.calculator.CustomPasswordHandler
- </properties>
- </web-service-security>
- </session>
- ...
- </enterprise-beans>
- </openejb-jar></p>
-
<p><a name="SecuringaWebService-Requestsentbytheclient."></a></p>
<h4>Request sent by the client.</h4>
@@ -308,35 +306,27 @@ Transfer-Encoding: chunked
524
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
- <wsse:Security
+ <wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
soap:mustUnderstand="1">
+ <wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
+wsu:Id="UsernameToken-22402238"
+xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+ <wsse:Username
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">jane</wsse:Username>
+ <wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"
+xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">tf7k3a4GREIt1xec/KXVmBdRNIg=</wsse:Password>
+ <wsse:Nonce
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">cKhUhmjQ1hGYPsdOLez5kA==</wsse:Nonce>
+ <wsu:Created
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2009-04-14T20:16:26.203Z</wsu:Created>
+ </wsse:UsernameToken>
+ </wsse:Security>
+ </soap:Header>
+ <soap:Body>
+ <ns1:sum xmlns:ns1="http://superbiz.org/wsdl">
+ <arg0>4</arg0>
+ <arg1>6</arg1>
+ </ns1:sum>
+ </soap:Body>
+</soap:Envelope>
</code></pre>
-<p>xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
-soap:mustUnderstand="1">
- <wsse:UsernameToken
-xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
- wsu:Id="UsernameToken-22402238"
-
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
- <wsse:Username
-xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">jane</wsse:Username>
- <wsse:Password
-Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"
-
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">tf7k3a4GREIt1xec/KXVmBdRNIg=</wsse:Password>
- <wsse:Nonce
-xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">cKhUhmjQ1hGYPsdOLez5kA==</wsse:Nonce>
- <wsu:Created
-xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2009-04-14T20:16:26.203Z</wsu:Created>
- </wsse:UsernameToken>
- </wsse:Security>
- </soap:Header>
- <soap:Body>
- <ns1:sum xmlns:ns1="http://superbiz.org/wsdl">
- <arg0>4</arg0>
- <arg1>6</arg1>
- </ns1:sum>
- </soap:Body>
- </soap:Envelope></p>
-
<p><a name="SecuringaWebService-Theresponsereturnedfromtheserver."></a></p>
<h4>The response returned from the server.</h4>
@@ -369,51 +359,39 @@ CallbackHandler. Once you have done this
this:</p>
<pre><code>public class CustomPasswordHandler implements CallbackHandler {
- public void handle(Callback[]
-</code></pre>
-<p>callbacks) throws IOException, UnsupportedCallbackException {
- WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]
-;</p>
-
-<pre><code> if(pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
- // TODO get the password from the users.properties if possible
- pc.setPassword("waterfall");
+ public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
- } else if(pc.getUsage() == WSPasswordCallback.DECRYPT) {
- pc.setPassword("serverPassword");
+ if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
+ // TODO get the password from the users.properties if possible
+ pc.setPassword("waterfall");
- } else if(pc.getUsage() == WSPasswordCallback.SIGNATURE) {
- pc.setPassword("serverPassword");
+ } else if (pc.getUsage() == WSPasswordCallback.DECRYPT) {
- }
-
- if ((pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN)
- || (pc.getUsage() ==
-</code></pre>
-
-<p>WSPasswordCallback.USERNAME_TOKEN_UNKNOWN)) {</p>
+ pc.setPassword("serverPassword");
-<pre><code> SecurityService securityService = SystemInstance.get()
- .getComponent(SecurityService.class);
- Object token = null;
- try {
- securityService.disassociate();
+ } else if (pc.getUsage() == WSPasswordCallback.SIGNATURE) {
- token = securityService.login(pc.getIdentifer(),
-</code></pre>
-
-<p>pc.getPassword());
- securityService.associate(token);</p>
+ pc.setPassword("serverPassword");
-<pre><code> } catch (LoginException e) {
- e.printStackTrace();
- throw new SecurityException("wrong password");
- } finally {
}
- }
+ if ((pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) ||
(pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN)) {
+ SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
+ Object token = null;
+ try {
+ securityService.disassociate();
+
+ token = securityService.login(pc.getIdentifer(),
pc.getPassword());
+ securityService.associate(token);
+
+ } catch (LoginException e) {
+ e.printStackTrace();
+ throw new SecurityException("wrong password");
+ }
+ }
}
}
</code></pre>
Modified: websites/staging/openejb/trunk/content/service-locator.html
==============================================================================
--- websites/staging/openejb/trunk/content/service-locator.html (original)
+++ websites/staging/openejb/trunk/content/service-locator.html Mon Jul 11
02:31:36 2011
@@ -169,31 +169,27 @@ start with this basic class that has a b
common prefix to be optionally applied to the beginning of all lookup
strings.</p>
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style: solid;"><B>MyLocator.java</B></DIV><DIV
class="codeContent panelContent">
- public class MyLocator {
- private final Context context;</p>
+<pre><code>public class MyLocator {
+ private final Context context;
-<pre><code> public MyLocator() throws NamingException {
- this(null);
+ public MyLocator() throws NamingException {
+ this(null);
}
public MyLocator(String commonPrefix) throws NamingException {
- Properties properties = new Properties();
- properties.put(Context.INITIAL_CONTEXT_FACTORY,
-</code></pre>
-
-<p>"org.apache.openejb.client.RemoteInitialContextFactory");
+ Properties properties = new Properties();
+ properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
properties.put(Context.PROVIDER_URL, "ejbd://localhost:4201/");
this.context = new InitialContext(properties);
- }</p>
-
-<pre><code> public Object lookup(String name) {
- try {
- if (commonPrefix != null) name = commonPrefix + "/" +name;
- return context.lookup(name);
- } catch (NamingException e) {
- throw new IllegalArgumentException(e);
}
+
+ public Object lookup(String name) {
+ try {
+ if (commonPrefix != null) name = commonPrefix + "/" +name;
+ return context.lookup(name);
+ } catch (NamingException e) {
+ throw new IllegalArgumentException(e);
+ }
}
}
</code></pre>
@@ -300,11 +296,11 @@ in a JNDI tree that's a bit more human r
- {ejbClass.simpleName}/{interfaceClass.simpleName}</p>
<pre><code>public <T> T lookup(Class ejbClass, Class<T> type) {
- return (T) lookup(ejbClass.getSimpleName() + "" +
+ return (T) lookup(ejbClass.getSimpleName() + "" + type.getSimpleName());
+}
</code></pre>
-<p>type.getSimpleName());
- }</p>
+<p>and</p>
<pre><code>MyLocator locator = new MyLocator();
Widget widget = locator.lookup(RedWidgetBean.class, Widget.class);
Modified: websites/staging/openejb/trunk/content/singleton-beans.html
==============================================================================
--- websites/staging/openejb/trunk/content/singleton-beans.html (original)
+++ websites/staging/openejb/trunk/content/singleton-beans.html Mon Jul 11
02:31:36 2011
@@ -227,16 +227,15 @@ put @Lock(READ) on their bean class, thu
<p>The locking modes of Container-Managed Concurrency map directly to the *<a
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html">java.util.concurrent.ReadWriteLock</a>
* API which looks like this:</p>
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style:
solid;"><B>java.util.concurrent.ReadWriteLock</B></DIV><DIV class="codeContent
panelContent">
- public interface ReadWriteLock {
- /**
- * Returns the lock used for reading.
- *
- * @return the lock used for reading.
- */
- Lock readLock();</p>
+<pre><code>public interface ReadWriteLock {
+ /**
+ * Returns the lock used for reading.
+ *
+ * @return the lock used for reading.
+ */
+ Lock readLock();
-<pre><code> /**
+ /**
* Returns the lock used for writing.
*
* @return the lock used for writing.
@@ -272,10 +271,9 @@ to acquire the read or write lock. This
class or individual methods. The annotation maps directly to the <a
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/Lock.html">java.util.concurrent.locks.Lock</a>
interface.</p>
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style:
solid;"><B>java.util.concurrent.locks.Lock</B></DIV><DIV class="codeContent
panelContent">
- public interface Lock {</p>
+<pre><code>public interface Lock {
-<pre><code> /**
+ /**
* Blocks (potentially) forever
*
* @AccessTimout with a value of -1
@@ -374,21 +372,21 @@ annotation "just in case" and should onl
<p>Singletons can be declared in the ejb-jar.xml as follows:</p>
-<p>{code:xml|title=META-INF/ejb-jar.xml}
-<ejb-jar>
- <enterprise-beans>
- <session>
- <ejb-name>MySingletonBean</ejb-name>
- <ejb-class>org.superbiz.MySingletonBean</ejb-class>
- <session-type>Singleton</session-type>
- <load-on-startup/>
- <depends-on>
- <ejb-name>SingletonFoo</ejb-name>
- <ejb-name>SingletonBar</ejb-name>
- </depends-on>
- </session>
- </enterprise-beans>
-</ejb-jar></p>
+<pre><code><ejb-jar>
+ <enterprise-beans>
+ <session>
+ <ejb-name>MySingletonBean</ejb-name>
+ <ejb-class>org.superbiz.MySingletonBean</ejb-class>
+ <session-type>Singleton</session-type>
+ <load-on-startup/>
+ <depends-on>
+ <ejb-name>SingletonFoo</ejb-name>
+ <ejb-name>SingletonBar</ejb-name>
+ </depends-on>
+ </session>
+ </enterprise-beans>
+</ejb-jar>
+</code></pre>
</DIV>
</P>
Modified: websites/staging/openejb/trunk/content/spring-and-openejb-3.0.html
==============================================================================
--- websites/staging/openejb/trunk/content/spring-and-openejb-3.0.html
(original)
+++ websites/staging/openejb/trunk/content/spring-and-openejb-3.0.html Mon Jul
11 02:31:36 2011
@@ -2,7 +2,7 @@
<HTML>
<HEAD>
<!-- $PAGETITLE -->
- <title>Spring and OpenEJB 3.0</title>
+ <title></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]-->
@@ -130,7 +130,7 @@
<TR>
<TD id="page_title">
<!-- $TITLE -->
- Spring and OpenEJB 3.0
+
</TD>
<TD align="right">
@@ -152,224 +152,184 @@
<P>
<!-- $BODY -->
<DIV id="PageContent">
- <p>{note}OpenEJB 3.1 and later users should refer to the <a
href="spring.html">Spring</a>
- page.{note}
-<a name="SpringandOpenEJB3.0-BootstrappingOpenEJBinSpring"></a></p>
+ <p>{note}OpenEJB 3.1 and later users should refer to the [Spring]
page.{note}</p>
<h1>Bootstrapping OpenEJB in Spring</h1>
-<p>If you wish to use OpenEJB inside Spring you can do so pretty easily.
-Include OpenEJB and its dependencies in your classpath as you would in a
-plain embedded scenario then add a custom factory like the following:</p>
-
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style: solid;"><B>OpenEjbFactoryBean.java</B></DIV><DIV
class="codeContent panelContent">
- public class OpenEjbFactoryBean implements
-org.springframework.beans.factory.FactoryBean {</p>
+<p>If you wish to use OpenEJB inside Spring you can do so pretty easily.
Include OpenEJB and its dependencies in your classpath as you would in a plain
embedded scenario then add a custom factory like the following:</p>
-<pre><code> private Properties properties = new Properties();
+<pre><code>public class OpenEjbFactoryBean implements
org.springframework.beans.factory.FactoryBean {
- public OpenEjbFactoryBean() {
- properties.put(Context.INITIAL_CONTEXT_FACTORY,
-</code></pre>
+ private Properties properties = new Properties();
-<p>"org.apache.openejb.client.LocalInitialContextFactory");
- }</p>
+ public OpenEjbFactoryBean() {
+ properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
+ }
-<pre><code> public Properties getJndiEnvironment() {
- return properties;
+ public Properties getJndiEnvironment() {
+ return properties;
}
public void setJndiEnvironment(Properties properties) {
- this.properties.putAll(properties);
+ this.properties.putAll(properties);
}
public Object getObject() {
- try {
- return new InitialContext(properties);
- } catch (NamingException e) {
- throw new RuntimeException(e);
- }
+ try {
+ return new InitialContext(properties);
+ } catch (NamingException e) {
+ throw new RuntimeException(e);
+ }
}
public Class getObjectType(){
- return Context.class;
+ return Context.class;
}
boolean isSingleton() {
- return true;
+ return true;
}
}
</code></pre>
<p>And include that at the top of your spring xml file as follows:</p>
-<p>{code:xml|title=top of spring xml}
-<bean id="OpenEjbContext" class="org.acme.OpenEjbFactoryBean">
- <property name="jndiEnvironment">
- <props>
- <prop key="myDs">new://Resource?type=DataSource</prop>
- <prop key="myDs.JdbcDriver">com.mysql.jdbc.Driver</prop>
- <prop
-key="myDs.JdbcUrl">jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true</prop>
- <prop key="myDs.UserName">root</prop>
- <prop key="myDs.Password"></prop>
- </props>
- </property>
-</bean></p>
-
-<pre><code>The value of <props> is meant to be illustrative of the kinds
of properties
+<pre><code><bean id="OpenEjbContext" class="org.acme.OpenEjbFactoryBean">
+ <property name="jndiEnvironment">
+ <props>
+ <prop key="myDs">new://Resource?type=DataSource</prop>
+ <prop key="myDs.JdbcDriver">com.mysql.jdbc.Driver</prop>
+ <prop
key="myDs.JdbcUrl">jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true</prop>
+ <prop key="myDs.UserName">root</prop>
+ <prop key="myDs.Password"></prop>
+ </props>
+ </property>
+</bean>
</code></pre>
-<p>you can pass into OpenEJB. It's possible to create any number of
-datasources, topics, queues, containers and more this way.</p>
-
-<pre><code>Just as with Unit Testing, OpenEJB will find and automatically
deploy all
-</code></pre>
+<p>The value of <props> is meant to be illustrative of the kinds of properties
you can pass into OpenEJB. It's possible to create any number of datasources,
topics, queues, containers and more this way.</p>
-<p>the EJB beans it [finds in the classpath|Application discovery via the
classpath]
-. You can then expose any of these things to other Spring components with
-custom factory beans.</p>
+<p>Just as with Unit Testing, OpenEJB will find and automatically deploy all
the EJB beans it [finds in the classpath|Application discovery via the
classpath]. You can then expose any of these things to other Spring components
with custom factory beans.</p>
<h1>Injecting OpenEJB-created resources into Spring components</h1>
-<pre><code>If you want to have any of the Topics, Queues, DataSources,
EntityManagers
-</code></pre>
-
-<p>or more that OpenEJB creates injected into components that Spring creates,
-here's one technique....</p>
+<p>If you want to have any of the Topics, Queues, DataSources, EntityManagers
or more that OpenEJB creates injected into components that Spring creates,
here's one technique....</p>
-<pre><code>Let's say you have a persistence unit called "*OrangeUnit*"
declared in a
-</code></pre>
+<p>Let's say you have a persistence unit called "<em>OrangeUnit</em>" declared
in a persistence.xml file. One way to get the related <em>EntityManager</em>
created by OpenEJB is to do as follows. Create an @Stateless bean with an
@PersistenceContext ref in it, then use a factory bean to look it up, pull the
EntityManager out and return it</p>
-<p>persistence.xml file. One way to get the related <em>EntityManager</em>
created
-by OpenEJB is to do as follows. Create an @Stateless bean with an
-@PersistenceContext ref in it, then use a factory bean to look it up, pull
-the EntityManager out and return it</p>
+<p>OrangeUnitBean.java</p>
-<pre><code>{code:title=OrangeUnitBean.java}
-/*
+<pre><code>/*
* OpenEJB will automatically find this bean. Just put it in the same jar
* that your META-INF/persistence.xml file is located in and make sure that
- * that same jar file also has a META-INF/ejb-jar.xml file. The
-</code></pre>
-
-<p>ejb-jar.xml
- * need only contain the text "<ejb-jar/>" at minimum.
- */
- @Stateless
- public class OrangeUnitBean implements OrangeUnitLocal {</p>
+ * that same jar file also has a META-INF/ejb-jar.xml file. The ejb-jar.xml
+ * need only contain the text "<ejb-jar/>" at minimum.
+ */
+@Stateless
+public class OrangeUnitBean implements OrangeUnitLocal {
-<pre><code> @PersistenceContext(unitName="OrangeUnit")
+ @PersistenceContext(unitName="OrangeUnit")
private EntityManager entityManager;
public EntityManager getEntityManager() {
- return entityManager;
+ return entityManager;
}
}
</code></pre>
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style: solid;"><B>OrangeUnitLocal.java</B></DIV><DIV
class="codeContent panelContent">
- /**
- * The local interface for the OrangeUnitBean
- */
- public interface OrangeUnitLocal {
- public EntityManager getEntityManager();
- }</p>
-
-<p><DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV
class="codeHeader panelHeader" style="border-bottom-width:
1px;border-bottom-style: solid;"><B>OrangeUnitFactoryBean.java</B></DIV><DIV
class="codeContent panelContent">
- /**
- * This factory bean will lookup the OrangeUnitBean using the
-javax.naming.Context
- * that is created via the OpenEjbFactoryBean above. It will simply grab
-the EntityManager
- * from that bean and hand it over to Spring. Anyone in Spring-land can
-then easily get
- * a reference to the EntityManager by simply referencing this factory
-bean.
- */
- public class OrangeUnitFactoryBean implements
-org.springframework.beans.factory.FactoryBean {
- private Context context;</p>
+<p>OrangeUnitLocal.java</p>
-<pre><code> public Context getContext() {
- return context;
+<pre><code>/**
+ * The local interface for the OrangeUnitBean
+ */
+public interface OrangeUnitLocal {
+ public EntityManager getEntityManager();
+}
+</code></pre>
+
+<p>OrangeUnitFactoryBean.java</p>
+
+<pre><code>/**
+ * This factory bean will lookup the OrangeUnitBean using the
javax.naming.Context
+ * that is created via the OpenEjbFactoryBean above. It will simply grab the
EntityManager
+ * from that bean and hand it over to Spring. Anyone in Spring-land can then
easily get
+ * a reference to the EntityManager by simply referencing this factory bean.
+ */
+public class OrangeUnitFactoryBean implements
org.springframework.beans.factory.FactoryBean {
+ private Context context;
+
+ public Context getContext() {
+ return context;
}
public void setContext(Context context) {
- this.context = context;
+ this.context = context;
}
public Object getObject() {
- try {
- ResourceLocal bean = (ResourceLocal)
-</code></pre>
-
-<p>context.lookup("OrangeUnitBeanLocal");
+ try {
+ ResourceLocal bean = (ResourceLocal)
context.lookup("OrangeUnitBeanLocal");
return bean.getEntityManager();
} catch (NamingException e) {
throw new RuntimeException(e);
}
- }</p>
+ }
-<pre><code> public Class getObjectType(){
- return EntityManager.class;
+ public Class getObjectType(){
+ return EntityManager.class;
}
boolean isSingleton() {
- return true;
+ return true;
}
}
</code></pre>
<p>The factory bean would then be declared in your spring xml file as
follows:</p>
-<p>{code:xml|title=in the spring xml}
-<bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
- <property name="context" ref="OpenEjbContext">
-</bean></p>
+<pre><code><bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
+ <property name="context" ref="OpenEjbContext">
+</bean>
+</code></pre>
-<pre><code>The EntityManager can then easily be consumed by a spring bean.
+<p>The EntityManager can then easily be consumed by a spring bean.</p>
-{code:title=SomePojo.java}
-public class SomePojo {
+<pre><code>public class SomePojo {
private EntityManager entityManager;
public void setEntityManager(EntityManager entityManager) {
- this.entityManager = entityManager;
+ this.entityManager = entityManager;
}
...
}
</code></pre>
-<p>{code:xml|title=in the spring xml}
-<bean id="SomePojo" class="org.acme.SomePojo">
- <property name="entityManager" ref="OrangeUnit">
-</bean></p>
+<p>In the spring xml</p>
-<pre><code>Here's what all three declarations would look like together in your
spring
+<pre><code><bean id="SomePojo" class="org.acme.SomePojo">
+ <property name="entityManager" ref="OrangeUnit">
+</bean>
</code></pre>
-<p>xml:</p>
+<p>Here's what all three declarations would look like together in your spring
xml:</p>
-<pre><code>{code:xml|title=spring bean definitions combined}
-<bean id="OpenEjbContext" class="org.acme.OpenEjbFactoryBean">
+<p>Spring bean definitions combined</p>
+
+<pre><code><bean id="OpenEjbContext" class="org.acme.OpenEjbFactoryBean">
<property name="jndiEnvironment">
<props>
<prop key="myDs">new://Resource?type=DataSource</prop>
<prop key="myDs.JdbcDriver">com.mysql.jdbc.Driver</prop>
- <prop
-</code></pre>
-
-<p>key="myDs.JdbcUrl">jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true</prop>
- <prop key="myDs.UserName">root</prop>
- <prop key="myDs.Password"></prop>
- </props>
- </property>
- </bean></p>
+ <prop
key="myDs.JdbcUrl">jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true</prop>
+ <prop key="myDs.UserName">root</prop>
+ <prop key="myDs.Password"></prop>
+ </props>
+ </property>
+</bean>
-<pre><code><bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
+<bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
<property name="context" ref="OpenEjbContext">
</bean>
@@ -379,9 +339,7 @@ public class SomePojo {
</code></pre>
<p>{info:title=Some more useful info.}
-Here is a bunch of links suggested by a user. If anybody has time to go
-through them and write a doc, that would be great. These links explain how
-to make available spring components to openejb
+Here is a bunch of links suggested by a user. If anybody has time to go
through them and write a doc, that would be great. These links explain how to
make available spring components to openejb
http://twasink.net/blog/archives/2007/01/using_spring_wi.html
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/ejb/interceptor/SpringBeanAutowiringInterceptor.html
http://wiki.netbeans.org/MavenSpringEJBsOnGlassfish</p>
Modified: websites/staging/openejb/trunk/content/webadmin.html
==============================================================================
--- websites/staging/openejb/trunk/content/webadmin.html (original)
+++ websites/staging/openejb/trunk/content/webadmin.html Mon Jul 11 02:31:36
2011
@@ -209,42 +209,35 @@ OpenEJB ready.
<p>To create an EJB and have it included as part of the WebAdmin, simply
subclass from WebAdminBean and include it in your ejb-jar.xml file as such:</p>
-<p>{code:xml|title=ejb-jar.xml}
- <session>
- <description>A JNDI viewer</description>
- <ejb-name>webadmin/ViewJndi</ejb-name>
- <home>org.openejb.webadmin.HttpHome</home>
- <remote>org.openejb.webadmin.HttpObject</remote>
- <ejb-class>org.openejb.webadmin.clienttools.ViewJndiBean</ejb-class>
- <session-type>Stateless</session-type>
- <transaction-type>Bean</transaction-type>
- </session></p>
-
-<pre><code>The ejb-name is used to create the menus and should follow the
format of
+<pre><code><session>
+ <description>A JNDI viewer</description>
+ <ejb-name>webadmin/ViewJndi</ejb-name>
+ <home>org.openejb.webadmin.HttpHome</home>
+ <remote>org.openejb.webadmin.HttpObject</remote>
+
<ejb-class>org.openejb.webadmin.clienttools.ViewJndiBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Bean</transaction-type>
+</session>
</code></pre>
-<p>'menu-section/menu-item'. WebAdminBeans are grouped together by the
+<p>The ejb-name is used to create the menus and should follow the format of
+'menu-section/menu-item'. WebAdminBeans are grouped together by the
'menu-section' portion of their ejb-name. The 'menu-item' is the clickable
link that causes the EJB code to be execute. Very simple and makes it
possible to package administrative components with your EJB applications.</p>
<h1>WebAdmin Plugins</h1>
-<pre><code>Here is a project that already takes advantage of the new feature.
[BeanGen|http://beangen.sourceforge.net]
-</code></pre>
+<p>Here is a project that already takes advantage of the new feature.
[BeanGen|http://beangen.sourceforge.net]</p>
<h1>Developers guide</h1>
-<pre><code>Below is David Blevins' email on how webadmin worked. Please have a
look at
-</code></pre>
-
-<p>the text below before you start working on porting the existing WebAdmin to
+<p>Below is David Blevins' email on how webadmin worked. Please have a look at
+the text below before you start working on porting the existing WebAdmin to
version 3.</p>
-<pre><code>Plain old stateless beans were used as the "servlets". To make a
bean that
-</code></pre>
-
-<p>would show up in the Webadmin Console you simply had to implement the
+<p>Plain old stateless beans were used as the "servlets". To make a bean that
+would show up in the Webadmin Console you simply had to implement the
HttpBean interface (i think it's now called HttpListener) and give your
bean a deploymentId following this format "webadmin/{section}/{page}".
Anyone could add to the Webadmin console by doing both of these things,
@@ -252,43 +245,35 @@ which is really cool as people developin
for administering those apps right in the exact same jar. This is not only
easy for packaging but means new sections can be added/removed on the fly.</p>
-<pre><code>Using the described "webadmin/{section}/\{page\}" deploymentId
format,
-</code></pre>
-
-<p>things end up automagically grouped in the JNDI tree. There's a 'webadmin'
+<p>Using the described "webadmin/{section}/{page}" deploymentId format,
+things end up automagically grouped in the JNDI tree. There's a 'webadmin'
context we grab which will contain any number of "section" contexts
("ClientTools", "EJBGenerator", etc.). Each of those section subcontexts
will contain several beans which we will use to make the pages. Making the
menu is pretty easy as we just iterate over the webadmin section of the
global jndi tree.</p>
-<pre><code>When an http request came in we just took the path part of the GET
or POST
-</code></pre>
-
-<p>request, prepended "webadmin/" and then went looking for a bean with that
+<p>When an http request came in we just took the path part of the GET or POST
+request, prepended "webadmin/" and then went looking for a bean with that
deployment id and invoked it via it's HttpBean (now called HttpListener)
interface passing in a HttpRequest and HttpResponse objects which are
trimmed down versions of similar servlet classes.
- There'll be some changes to this as now we support our plain ejb protocol
+There'll be some changes to this as now we support our plain ejb protocol
over our http implementation, so the two will have to find a way to share
the URL space. See the openejb-http module.</p>
-<pre><code>To implement session state, we had a stateful session bean
implementing an
-</code></pre>
-
-<p>HttpSession interface (again, similar to the servlet equivalent) and simply
+<p>To implement session state, we had a stateful session bean implementing an
+HttpSession interface (again, similar to the servlet equivalent) and simply
wrote the internal ID of the bean instance into a Cookie sent to the
browser. For some reason we would write the javax.ejb.Handle of the
stateful bean's EJBObject to disk and
- read it back out on subsequent requests then used it to get a reference to
+read it back out on subsequent requests then used it to get a reference to
the EJBObject again. I'm not sure why we didn't just keep a static hashmap
and put the EJBObject right in it using an ID we could just make up like
UUID (that would have been way simpler).</p>
-<pre><code>We had a standard superclass we favored for beans that implemented
the
-</code></pre>
-
-<p>HttpBean (HttpListener) interface that did templating and the
+<p>We had a standard superclass we favored for beans that implemented the
+HttpBean (HttpListener) interface that did templating and the
aforementioned menu construction. The templating was perhaps too tricky
as we used a non-printable character to determine where to insert data.
Now we could just use swizzle-stream for some pretty decent templating
@@ -297,45 +282,35 @@ already have a dep on swizzle-stream and
another meg to our distro size if we can avoid it -- we have like 3 times
as many deps as 1.0 did and we should probably start tightening the belt.</p>
-<pre><code>To serve static things like images, we had a "default" HttpBean
which
-</code></pre>
-
-<p>searched for the items in the classpath and wrote them into the response
+<p>To serve static things like images, we had a "default" HttpBean which
+searched for the items in the classpath and wrote them into the response
setting the mime type, etc. correctly. One thing that we never did which
still needs to happen is that the bean didn't have the logic to set the
modification information into the response so the "If modified since"
header which would allow the browser to rely on it's cache instead of
requesting the same images over and over again.</p>
-<pre><code>That pretty much covers the way it was put together.
-
-
- - The Jndi Viewer, Class Viewer, Ejb Viewer, and Object Invoker
-were written by yours truly
- - The EJB Generator was written by Jeremy Whitlock
- - Everything else was written by Tim Urberg. Tim was "WebAdmin guy" for
-</code></pre>
+<p>That pretty much covers the way it was put together.</p>
-<p>a good long while. Before Tim came along the webadmin was just some
-experimental code I <br />
- had in a branch, he did more than he realizes by putting his energy
+<ul>
+<li>The Jndi Viewer, Class Viewer, Ejb Viewer, and Object Invoker were written
by yours truly</li>
+<li>The EJB Generator was written by Jeremy Whitlock</li>
+<li>Everything else was written by Tim Urberg. Tim was "WebAdmin guy" for
+a good long while. Before Tim came along the webadmin was just some
+experimental code I had in a branch, he did more than he realizes by putting
his energy
into it -- active people attract/ create more active people. Maybe we can
-convince him to
- come back and work on it ;)</p>
+convince him to come back and work on it ;)</li>
+</ul>
-<pre><code>And of course I have to mention our own Paulo Lopes who wrote a
really cool
-</code></pre>
-
-<p>project out in SF.net (http://beangen.sourceforge.net/) which was the first
+<p>And of course I have to mention our own Paulo Lopes who wrote a really cool
+project out in SF.net (http://beangen.sourceforge.net/) which was the first
plugin for the OpenEJB Webadmin. He wrote it before we even had shipped a
release containing the Webadmin or had any docs at all on it, which in my
mind shows just how neat the idea of using ejb's and simple conventions to
do the console really is.</p>
-<pre><code>Some notes going forward is that we have a truck load of meta-data
now
-</code></pre>
-
-<p>available via SystemInstance.get().get (OpenEjbConfiguration.class).
+<p>Some notes going forward is that we have a truck load of meta-data now
+available via SystemInstance.get().get (OpenEjbConfiguration.class).
Certainly JSR-77 is one option, but we could do far better with plain old
java code. That tree is the primary source of meta-data for OpenEJB, it's
what was used to construct every container, bean, resource adapter,
@@ -345,10 +320,8 @@ without having to read any abstract spec
tree is read only in it's function, however it is possible to copy then
edit and make new containers, etc. based on existing definitions.</p>
-<pre><code>Additionally, using this same data structure it's possible to show
the
-</code></pre>
-
-<p>potential services available via the service-jar.xml files in the classpath
+<p>Additionally, using this same data structure it's possible to show the
+potential services available via the service-jar.xml files in the classpath
that detail containers, resource adapters, database connectors, etc. which
can be configured/created at runtime. So we could also display a sort of
catalogue of components (aka. services) that someone could click and deploy