How To Telephone Telephone A Stateless Ejb From A Restrain Residuum Servlet Component

In my recent projection I was inquire to educate a residual servlet (using jersey) inward a saltation spider web projection that would telephone telephone an stateless EJB, where the describe of piece of work concern logic is.  This projection is deployed on glassfish.

After several hours I was able to figure out how to arrive work, as well as my principal occupation is only the JNDI name, I was solely able to access it using it's global mention which yous tin run across on the glassfish console log. It's rattling of import then human face at your console.

I would exactly re-create as well as glue the close of import files equally they are inward my working project. Note that I accept ii projects, that are deploy sub-modules of an ear project. First is a spider web projection as well as the instant is an ejb project.

The Web Project
web.xml
<web-app version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>XXX - Customer Gateway</display-name>   <context-param>   <param-name>locatorFactorySelector</param-name>   <param-value>classpath:WEB-INF/beanRefContext.xml</param-value>  </context-param>   <listener>   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>   <servlet>   <servlet-name>jersey-serlvet</servlet-name>   <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>   <init-param>    <param-name>com.sun.jersey.config.property.packages</param-name>    <param-value>com.XXX.cg</param-value>   </init-param>   <load-on-startup>1</load-on-startup>  </servlet>   <servlet-mapping>   <servlet-name>jersey-serlvet</servlet-name>   <url-pattern>/api/*</url-pattern>  </servlet-mapping> </web-app> 
beanRef.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">   <bean id="com.XXX"   class="org.springframework.context.support.ClassPathXmlApplicationContext">   <constructor-arg>    <list>     <value>applicationContext.xml</value>    </list>   </constructor-arg>  </bean> </beans> 
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"  xmlns:util="http://www.springframework.org/schema/util"  xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/jee  http://www.springframework.org/schema/jee/spring-jee-3.0.xsd  http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-3.0.xsd"  default-autowire="byName">   <context:component-scan base-package="com.XXX" />  <context:annotation-config />  <tx:annotation-driven />  <tx:jta-transaction-manager />   <jee:jndi-lookup id="XXXCgDataSource" jndi-name="XXXCgDataSource"   lookup-on-startup="true" />   <bean id="entityManager"   class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">   <property name="dataSource" ref="XXXCgDataSource" />   <property name="persistenceUnitName" value="XXXPU" />  </bean>   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">   <property name="entityManagerFactory" ref="entityManager" />   <property name="dataSource" ref="XXXCgDataSource" />  </bean>   <!-- JNDI Lookup -->  <jee:jndi-lookup id="xxxServiceBean"   jndi-name="java:global/XXX-cg-ear-0.0.1-SNAPSHOT/XXX-cg-ejbs/XXXServiceBean"   resource-ref="true" lookup-on-startup="true"   expected-type="com.XXX.cg.service.xxx.local.XXXServiceBeanLocal"   proxy-interface="com.XXX.cg.service.xxx.local.XXXServiceBeanLocal" />   <!-- Load inward application properties reference -->  <bean id="propertiesBean" name="propertiesBean"   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">   <property name="location" value="/XXX-cg.properties" />  </bean>   <bean id="LogginInjector" class="com.XXX.commons.logger.LoggerPostProcessor" /> </beans> 
The course of didactics where the stateless EJB is existence called
@Path("/XXX") @Component populace course of didactics XXXServiceImpl {  @Log  somebody Logger log;    @EJB  protected XXXServiceBeanLocal XXXServiceBean;   @POST  @Path("/register")  @Produces({ MediaType.APPLICATION_JSON })  populace Response register(@FormParam("email") String email,    @FormParam("macid") String macid, @FormParam("type") String type) {   //...   String reply = XXXServiceBean.register(email, macid, type);   //...   provide resp;  } } 
And that's it for the spider web project. And for the ejb projection nosotros have:
beanRefContext.xml
 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">   <bean id="com.sido"   class="org.springframework.context.support.ClassPathXmlApplicationContext">   <constructor-arg>    <list>     <value>ejbApplicationContext.xml</value>    </list>   </constructor-arg>  </bean> </beans> 
applicationContext.xml
 <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"  xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/jee  http://www.springframework.org/schema/jee/spring-jee-3.0.xsd  http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"  default-autowire="byName">   <context:annotation-config />  <context:component-scan base-package="com.XXX" />  <tx:annotation-driven />   <jee:jndi-lookup id="XXXCgDataSource" jndi-name="XXXCgDataSource"   lookup-on-startup="true" />   <bean id="entityManager"   class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">   <property name="dataSource" ref="XXXCgDataSource" />   <property name="persistenceUnitName" value="XXXPU" />  </bean>   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">   <property name="entityManagerFactory" ref="entityManager" />   <property name="dataSource" ref="XXXCgDataSource" />  </bean>  </beans>
ejb-jar.xml
 <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"  version="3.1">   <!-- <display-name>XXX-cg-ejbs</display-name> -->  <module-name>XXX-cg-ejbs</module-name>   <interceptors>   <interceptor>    <interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>   </interceptor>  </interceptors>  <assembly-descriptor>   <interceptor-binding>    <ejb-name>*</ejb-name>    <interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>   </interceptor-binding>  </assembly-descriptor> </ejb-jar> 
The actual interface as well as course of didactics XXX interface
 /**  * @author czetsuya  * @created May 4, 2012  **/ bundle com.sido.cg.service.XXX.local;  import javax.ejb.Local;  @Local populace interface XXXServiceBeanLocal {  String register(String email, String macId, String type);  String create(String email, String macId, String type); } 
XXX course of didactics
 /**  * @author Edward P. Legaspi  * @created May 4, 2012  **/ bundle com.sido.cg.service.XXX;  import javax.ejb.Stateless; import javax.interceptor.Interceptors;  import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;  import com.sido.cg.service.XXX.local.XXXServiceBeanLocal;  @Interceptors(SpringBeanAutowiringInterceptor.class) @Stateless populace course of didactics XXXServiceBean implements XXXServiceBeanLocal {  @Autowired  somebody XXXService XXXService;   populace String register(String email, String macId, String type) {   provide XXXService.register(email, macId, type);  }   populace String create(String email, String macId, String type) {   provide XXXService.create(email, macId, type);  }  } 
And I believe that's all yous request to telephone telephone a stateless ejb from roughly other spider web projection powered past times spring. Take depository fiscal establishment annotation that yous tin equally good inject saltation edible bean from the ejb stateless edible bean using SpringBeanAutowiringInterceptor.
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.