Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

First of all, we create the pom.xml :

Code Block
xml
borderStylesolid
titlepom.xml
borderStylesolid
xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.apache.servicemix.examples</groupId>
    <artifactId>ejb-example</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>org.apache.servicemix.examples</groupId>
  <artifactId>ejb-cxf-su</artifactId>
  <packaging>jbi-service-unit</packaging>
  <name>Apache ServiceMix :: Examples :: EJB :: CXF SU</name>

  <dependencies>
    <dependency>
      <groupId>org.apache.servicemix</groupId>
      <artifactId>servicemix-cxf-se</artifactId>
      <version>2008.01</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>2.5.5</version>
    </dependency>
    <dependency>
      <groupId>jboss</groupId>
      <artifactId>jbossall-client</artifactId>
      <version>4.2.2.GA</version>
    </dependency>
    <dependency>
       <groupId>my.ejb.provider</groupId>
       <artifactId>ejb-client</artifactId>
       <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
 
  <build>
     <resources>
       <resource>
          <directory>src/main/resources</directory>
             <includes>
               <include>**/*</include>
             </includes>
        </resource>
      </resources>
      <plugins>
        <plugin>
          <groupId>org.apache.servicemix.tooling</groupId>
          <artifactId>jbi-maven-plugin</artifactId>
          <version>3.2.3</version>
          <extensions>true</extensions>
         </plugin>
       </plugins>
  </build>
   
</project>

...

Now we can setup the xbean.xml (in the src/main/resources directory) to expose our EJB :

Code Block
xmlborderStylesolid
titlexbean.xml
borderStylesolid
xml

<beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0"
       xmlns:myService="http://www.example.com/myService">

   <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
      <property name="environment">
         <props>
            <prop key="java.naming.factory.initial">
               org.jnp.interfaces.NamingContextFactory
            </prop>
            <prop key="java.naming.provider.url">
               jnp://localhost:1299
            </prop>
         </props>
      </property>
   </bean>

   <bean id="ejbProxy" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
      <property name="jndiName" value="ejb/myEJB"/>
      <property name="businessInterface" value="com.ejb.provider.MyEJB"/>
      <property name="homeInterface" value="com.ejb.provider.MyEJBHome"/>
      <property name="refreshHomeOnConnectFailure" value="true"/>
      <property name="cacheHome" value="true"/>
      <property name="lookupHomeOnStartup" value="true"/>
      <property name="resourceRef" value="false"/>
      <property name="jndiTemplate" ref="jndiTemplate"/>
   </bean>

   <cxfse:endpoint>
      <cxfse:pojo>
         <bean class="org.apache.servicemix.examples.MyEJBImpl">
            <property name="proxy" ref="ejbProxy"/>
         </bean>
      </cxfse:pojo>
   </cxfse:endpoint>

</beans>

...

So we create the MyEJB interface :

Code Block
javaborderStylesolid
titleMyEJB.java
borderStylesolid
java
package org.apache.servicemix.examples;

import javax.jws.WebService;

@WebService(targetNamespace = "http://www.example.com/myService", name = "MyEJB")
public interface MyEJB {

   public String echo(String message);

}

and the corresponding impl :

Code Block
javaborderStylesolid
titleMyEJBImpl.java
borderStylesolid
java
/**
 * Service delegate to the AutomaticSimulationSession EJB
 *
 * @author <a href="mailto:onofre@fimasys.fr">Jean-Baptiste Onofré</a>
 */
package org.apache.servicemix.examples;

import javax.jws.WebService;
import javax.xml.ws.Holder;

import com.ejb.provider.MyEJB;

@WebService(serviceName = "myService", targetNamespace = "http://www.example.com/myService", endpointInterface = "org.apache.servicemix.examples.MyEJB")
public class MyEJBImpl implements MyEJB {

   // simple Spring remote EJB proxy
   private AutomaticSimulationSession proxy;

   // getters and setters

   public void setProxy(AutomaticSimulationSession proxy) {
      this.proxy = proxy;
   }

   public AutomaticSimulationSession getProxy() {
      return this.proxy;
   }

   // service delegation methods

   /**
    * Delegation to the <code>echo</code> method of the <code>MyEJB</code> EJB.
    */
   public String echo(String message) {
      try {
         return (proxy.echo(message).toString();
      }
      catch(Exception exception) {
         exception.printStackTrace();
         return "Error occurs : " + exception.getMessage();
      }
   }

}

...