You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/07/11 04:30:13 UTC

svn commit: r1145009 [3/3] - /openejb/site/trunk/content/

Modified: openejb/site/trunk/content/spring-and-openejb-3.0.mdtext
URL: http://svn.apache.org/viewvc/openejb/site/trunk/content/spring-and-openejb-3.0.mdtext?rev=1145009&r1=1145008&r2=1145009&view=diff
==============================================================================
--- openejb/site/trunk/content/spring-and-openejb-3.0.mdtext (original)
+++ openejb/site/trunk/content/spring-and-openejb-3.0.mdtext Mon Jul 11 02:30:12 2011
@@ -1,109 +1,86 @@
-Title: Spring and OpenEJB 3.0
-{note}OpenEJB 3.1 and later users should refer to the [Spring](spring.html)
- page.{note}
-<a name="SpringandOpenEJB3.0-BootstrappingOpenEJBinSpring"></a>
+{note}OpenEJB 3.1 and later users should refer to the [Spring] page.{note}
 # Bootstrapping OpenEJB in Spring
 
-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:
-
-<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 {
-    
+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:
+
+    public class OpenEjbFactoryBean implements org.springframework.beans.factory.FactoryBean {
+
         private Properties properties = new Properties();
-    
+
         public OpenEjbFactoryBean() {
-    	properties.put(Context.INITIAL_CONTEXT_FACTORY,
-"org.apache.openejb.client.LocalInitialContextFactory");
+            properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
         }
-    
+
         public Properties getJndiEnvironment() {
-    	return properties;
+            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;
         }
     }
 
-
 And include that at the top of your spring xml file as follows:
 
-{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>
-
-    
-    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.
-    
-    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.
-    
+    <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>
+
+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.
+
+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.
+
 # Injecting OpenEJB-created resources into Spring components
-    
-    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....
-    
-    Let's say you have a persistence unit called "*OrangeUnit*" declared in a
-persistence.xml file.  One way to get the related *EntityManager* 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
-    
-    {code:title=OrangeUnitBean.java}
+
+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....
+
+Let's say you have a persistence unit called "*OrangeUnit*" declared in a persistence.xml file.  One way to get the related *EntityManager* 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
+
+OrangeUnitBean.java
+
     /*
      * 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
-ejb-jar.xml
+     * 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 {
-    
+
         @PersistenceContext(unitName="OrangeUnit")
         private EntityManager entityManager;
-    
+
         public EntityManager getEntityManager() {
-    	return entityManager;
+            return entityManager;
         }
     }
 
+OrangeUnitLocal.java
 
-<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
      */
@@ -111,108 +88,95 @@ ejb-jar.xml
        public EntityManager getEntityManager();
     }
 
+OrangeUnitFactoryBean.java
 
-<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.
+     * 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 {
+    public class OrangeUnitFactoryBean implements org.springframework.beans.factory.FactoryBean {
         private Context context;
-    
+
         public Context getContext() {
-    	return context;
+            return context;
         }
-    
+
         public void setContext(Context context) {
-    	this.context = context;
+            this.context = context;
         }
-    
+
         public Object getObject() {
-    	try {
-    	    ResourceLocal bean = (ResourceLocal)
-context.lookup("OrangeUnitBeanLocal");
-    	    return bean.getEntityManager();
-    	} catch (NamingException e) {
-    	    throw new RuntimeException(e);
-    	}
+            try {
+                ResourceLocal bean = (ResourceLocal) context.lookup("OrangeUnitBeanLocal");
+                return bean.getEntityManager();
+            } catch (NamingException e) {
+                throw new RuntimeException(e);
+            }
         }
-    
+
         public Class getObjectType(){
-    	return EntityManager.class;
+            return EntityManager.class;
         }
-    
+
         boolean isSingleton() {
-    	return true;
+            return true;
         }
     }
 
-
 The factory bean would then be declared in your spring xml file as follows:
 
-{code:xml|title=in the spring xml}
-<bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
-  <property name="context" ref="OpenEjbContext">
-</bean>
-
-    
-    The EntityManager can then easily be consumed by a spring bean.
-    
-    {code:title=SomePojo.java}
+
+    <bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
+      <property name="context" ref="OpenEjbContext">
+    </bean>
+
+The EntityManager can then easily be consumed by a spring bean.
+
     public class SomePojo {
-    
+
         private EntityManager entityManager;
-    
+
         public void setEntityManager(EntityManager entityManager) {
-    	this.entityManager = entityManager;
+            this.entityManager = entityManager;
         }
-        
+
         ...
     }
 
-{code:xml|title=in the spring xml}
-<bean id="SomePojo" class="org.acme.SomePojo">
-  <property name="entityManager" ref="OrangeUnit">
-</bean>
-
-    
-    Here's what all three declarations would look like together in your spring
-xml:
-    
-    {code:xml|title=spring bean definitions combined}
+In the spring xml
+
+    <bean id="SomePojo" class="org.acme.SomePojo">
+      <property name="entityManager" ref="OrangeUnit">
+    </bean>
+
+Here's what all three declarations would look like together in your spring xml:
+
+Spring bean definitions combined
+
     <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.JdbcUrl">jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true</prop>
           <prop key="myDs.UserName">root</prop>
           <prop key="myDs.Password"></prop>
         </props>
       </property>
     </bean>
-    
+
     <bean id="OrangeUnit" class="org.acme.OrangeUnitFactoryBean">
       <property name="context" ref="OpenEjbContext">
     </bean>
-    
+
     <bean id="SomePojo" class="org.acme.SomePojo">
       <property name="entityManager" ref="OrangeUnit">
     </bean>
 
-
 {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

Modified: openejb/site/trunk/content/webadmin.mdtext
URL: http://svn.apache.org/viewvc/openejb/site/trunk/content/webadmin.mdtext?rev=1145009&r1=1145008&r2=1145009&view=diff
==============================================================================
--- openejb/site/trunk/content/webadmin.mdtext (original)
+++ openejb/site/trunk/content/webadmin.mdtext Mon Jul 11 02:30:12 2011
@@ -52,34 +52,33 @@ Now you can open your browser to go to h
 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:
 
-{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>
+    <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>
 
     
-    The ejb-name is used to create the menus and should follow the format of
+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.
-    
+
 # WebAdmin Plugins
-    
-    Here is a project that already takes advantage of the new feature. [BeanGen|http://beangen.sourceforge.net]
-    
+
+Here is a project that already takes advantage of the new feature. [BeanGen|http://beangen.sourceforge.net]
+
 # Developers guide
-    Below is David Blevins' email on how webadmin worked. Please have a look at
+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.
-    
-    Plain old stateless beans were used as the "servlets".	To make a bean that
+
+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\}". 
@@ -87,35 +86,35 @@ Anyone could add to the Webadmin console
 which is really cool as people developing EJB apps can also deploy beans
 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.
-    
-    Using the described "webadmin/{section}/\{page\}" deploymentId format,
+
+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.
-    
-    When an http request came in we just took the path part of the GET or POST
+
+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.
-    
-    To implement session state, we had a stateful session bean implementing an
+
+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).
-    
-    We had a standard superclass we favored for beans that implemented the
+
+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. 
@@ -124,37 +123,34 @@ ability or even velocity.  I'd be hesita
 already have a dep on swizzle-stream and wouldn't want to see us add
 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.
-    
-    To serve static things like images, we had a "default" HttpBean which
+
+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.
-    
-    That pretty much covers the way it was put together.
+
+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
-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 ;)
+  - 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
+    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 ;)
     
-    And of course I have to mention our own Paulo Lopes who wrote a really cool
+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.
-    
-    Some notes going forward is that we have a truck load of meta-data now
+
+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
@@ -164,8 +160,8 @@ protocols).  Someone new to the project 
 without having to read any abstract specs.  Something to consider.  The
 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.
-    
-    Additionally, using this same data structure it's possible to show the
+
+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