Use a “remote” EJB in Camel routes

http://blog.nanthrax.net/2011/08/use-a-remote-ejb-in-camel-routes/

Introduction

You have an existing application, let say developed using J2EE, including EJB (Session).
The application is running into a J2EE application server like JBoss, WebSphere or Weblogic.

This application “exposes” EJBs to perform some business services.

Now, you can to use these “remote” EJBs into Camel routes.

Context

We want to “expose” the EJB using WebService.

As for all EJBs, we have two interfaces for our EJB: the local and remote interfaces.
Let assume that we have:

* ejb.MyEjbSession
* ejb.MyEjbSessionHome

We assume that the MyEjbSession EJB provides a businessMethod() method, with a String in argument, and returning a String.

The first thing to do is to define an interface containing the WebService annotation. This interface will define the operations and will be used to generate the WSDL on the fly:


package net.nanthrax.blog.camel;

@WebService(targetNamespace = "http://www.nanthrax.net/blog", name = "MyEjbService")
public interface MyEjbService {

    public String businessService(String message);

}

Now, we can create a bean implementing this interface:


package net.nanthrax.blog.camel;

import ejb.MyEjbSession;

@WebService(serviceName = "myEjbService", targetNamespace = "http://www.nanthrax.net/blog", endpointInterface = "net.nanthrax.blog.camel.MyEjbService")
public class MyEjbServiceImpl implements MyEjbService {

&nbps;   private MyEjbSession proxy = null;

    public String businessService(String message) {
        return proxy.businessMethod(message);
    }

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

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

}

Camel routes

Now, we have a bean that we can use in a route. We use Spring Camel DSL. We also use Spring classes to connect to the J2EE application server and to inject the EJB proxy. In this example, we use JBoss application server:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
">

    <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://host:1099</prop>
      </props>
    </property>
    </bean>

    <bean id="ejbProxy" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
        <property name="jndiName" value="ejb/jndi/name/MyEjbSession" />
        <property name="businessInterface" value="ejb.MyEjbSession />
        <property name="homeInterface" value="ejb.MyEjbSessionHome" />
        <property name="refreshHomeOnConnectFailure" value="true" />
        <property name="cacheHome" value="true" />
        <property name="lookupHomeOnStartup" value="false" />
        <property name="resourceRef" value="false" />
        <property name="jndiTemplate" ref="jndiTemplate" />
    </bean>

    <bean id="ejbService" class="net.nanthrax.blog.camel.MyEjbServiceImpl">
        <property name="proxy" ref="ejbProxy"/>
    </bean>

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"/>

    <cxf:cxfEndpoint id="cxfEndpoint"
serviceClass="net.nanthrax.blog.camel.MyEjbService"
address="http://0.0.0.0:9090/blog/ejb-service/"/>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="cxf:bean:assetServiceCxfEndpoint"/>
            <to uri="assetServiceBean"/>
        </route>
    </camelContext>

</beans>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值