jboss ESB 是企业服务总线,应用很广,但资料很少,而且仅有的很少的资料都是英文的。
最近研究了一下jboss esb的服务编排,直接进入主题了。
jboss ESB 的环境配置这里就不说了,jboss的服务编排要建三个项目
(1)jbpm的项目(编排服务的流转顺序,这里使用的是jbpm3)
(2)建一个web项目,提供webservice服务。
(3)建一个esb服务,作为企业服务总线使用。
一 建 jbpm项目,然后建一个流程实例
如图所示的流程实例,有一个开始节点、两个esb service 节点 、一个任务节点和一个结束节点
a 打开esb service节点的属性页面,编辑服务的名称,类别,输入、输出参数(这里的服务名称、类别、输入输出参数将和esb中的对应)
二 建一个动态的web项目,作为webservice服务使用。
这里使用cxf 提供的建立webservice的方法
1 webservice_1
package com.richfit.jbpmwebservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public class WebService_1java {
@WebMethod(operationName = "process")
public String process_1(@WebParam(name = "xml") String xml) {
System.out
.println("------------------start process_1--------------------");
System.out.println(xml);
System.out
.println("------------------start process_1--------------------");
return "webservice_1:" + xml;
}
}
2 webservice_2
package com.richfit.jbpmwebservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public class WebService_2java {
@WebMethod(operationName = "process")
public String process_1(@WebParam(name = "xml") String xml) {
System.out
.println("------------------start process_2--------------------");
System.out.println(xml);
System.out
.println("------------------start process_2--------------------");
return "webservice_1:" + xml;
}
}
三 建立esb服务
ProcessWebServiceParam 类
package com.richfit.jbpm;
import java.util.HashMap;
import java.util.Map;
import org.jboss.soa.esb.actions.AbstractActionLifecycle;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
public class ProcessWebServiceParam extends AbstractActionLifecycle{
public ProcessWebServiceParam(ConfigTree _tree) {
}
public Message processParam(Message msg) throws ActionProcessingException {
String order = (String)msg.getBody().get("xml");
Map<String, String> map = new HashMap<String, String>();
map.put("process.xml", order);
msg.getBody().add("xml",map);
return msg;
}
public Message processReturn(Message msg) throws ActionProcessingException {
Map order = (Map)msg.getBody().get("return");
msg.getBody().add("xml",order.get("processResponse.return"));
return msg;
}
}
jbm-queue-service.xml 文件 (为provider提供队列)
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.demo.destination:service=Queue,name=bpmstart"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>
jboss-esb.xml 文件 (esb的主要文件,配置服务、action,provider 等信息)
<?xml version="1.0"?>
<jbossesb parameterReloadSecs="5"
xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd">
<providers>
<jms-provider connection-factory="ConnectionFactory"
name="jboss message">
<jms-bus busid="bpm start channel">
<jms-message-filter dest-name="queue/bpmstart"
dest-type="QUEUE" />
</jms-bus>
</jms-provider>
</providers>
<services>
<service category="bpm" description="webservice_1" invmScope="GLOBAL"
name="webservice_1">
<actions>
<action class="com.richfit.jbpm.ProcessWebServiceParam" name="processParam"
process="processParam" />
<action class="org.jboss.soa.esb.actions.soap.SOAPClient"
name="webservice_1">
<property name="wsdl"
value="http://127.0.0.1:8080/jbpmtest/webservice_1?wsdl" />
<property name="SOAPAction" value="process" />
<property name="get-payload-location" value="xml"></property>
<property name="responseAsognlMap" value="true"></property>
<property name="set-payload-location" value="return"></property>
</action>
<action class="com.richfit.jbpm.ProcessWebServiceParam" name="processReturn"
process="processReturn" />
</actions>
</service>
<service category="bpm" description="webservice_2" invmScope="GLOBAL"
name="webservice_2">
<actions>
<action class="com.richfit.jbpm.ProcessWebServiceParam" name="processParam"
process="processParam" />
<action class="org.jboss.soa.esb.actions.soap.SOAPClient"
name="webservice_2">
<property name="wsdl"
value="http://127.0.0.1:8080/jbpmtest/webservice_2?wsdl" />
<property name="SOAPAction" value="process" />
<property name="get-payload-location" value="xml"></property>
<property name="responseAsognlMap" value="true"></property>
<property name="set-payload-location" value="return"></property>
</action>
<action class="com.richfit.jbpm.ProcessWebServiceParam" name="processReturn"
process="processReturn" />
</actions>
</service>
(这里是对jbpm的引用)
<service category="bpm" description="order bpmstart" name="bpmstart">
<listeners>
<jms-listener busidref="bpm start channel" name="bpm start listener" />
</listeners>
<actions mep="OneWay">
<action name="start order bpm"
class="org.jboss.soa.esb.services.jbpm.actions.BpmProcessor">
<property name="command" value="StartProcessInstanceCommand" />
<property name="process-definition-name" value="webservicebpm" />
<property name="esbToBpmVars">
<mapping esb="BODY_CONTENT" bpm="xml" />
</property>
</action>
</actions>
</service>
</services>
</jbossesb>
deployment.xml文件,发布服务的描叙文件
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.demo.destination:service=Queue,name=bpmstart"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>
到这里,所有的信息都建立完毕。
然后发布服务和流程实例,注意这里的服务器使用的是jboss
建立客户端测试,esb的服务编排是否成功
[img][http://hi.csdn.net/attachment/201010/9/0_1286635466C6cB.gif/img]
所需的jar包如上图所示。
客户端的目录说明,
SimpleWebServiceEsbClient 类信息
package org.jboss.simple.esbclient;
import org.jboss.soa.esb.client.ServiceInvoker;
import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
public class SimpleWebServiceEsbClient {
/**
* @param args
* @throws RegistryException
* @throws MessageDeliverException
* @throws FaultMessageException
*/
public static void main(String[] args) throws FaultMessageException,
MessageDeliverException, RegistryException {
System.setProperty("javax.xml.registry.ConnectionFactoryClass",
"org.apache.ws.scout.registry.ConnectionFactoryImpl");
// System.setProperty("org.jboss.soa.esb.propertyFile",
// "abs://D:/jbossesb-properties.xml");
Message esbMessage = MessageFactory.getInstance().getMessage();
// Map<String, String> map = new HashMap<String, String>();
// map.put("hello.username", "jboss soa");
esbMessage.getBody().add("simplewebservice");
new ServiceInvoker("jbpm", "bpmstart").deliverAsync(esbMessage);
}
}
uudi.xml文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<uddi>
<reloadDelay>3600000</reloadDelay>
<manager name="esb-registry">
<nodes>
<node>
<!-- required 'default' node -->
<name>default</name>
<description>Main jUDDI node</description>
<!-- JAX-WS Transport -->
<proxyTransport>org.apache.juddi.v3.client.transport.JAXWSTransport</proxyTransport>
<custodyTransferUrl>http://localhost:8080/juddiv3/services/custody-transfer?wsdl</custodyTransferUrl>
<inquiryUrl>http://localhost:8080/juddiv3/services/inquiry?wsdl</inquiryUrl>
<publishUrl>http://localhost:8080/juddiv3/services/publish?wsdl</publishUrl>
<securityUrl>http://localhost:8080/juddiv3/services/security?wsdl</securityUrl>
<subscriptionUrl>http://localhost:8080/juddiv3/services/subscription?wsdl</subscriptionUrl>
<subscriptionListenerUrl>http://localhost:8080/juddiv3/services/subscription-listener?wsdl</subscriptionListenerUrl>
<juddiApiUrl>http://localhost:8080/juddiv3/services/juddi-api?wsdl</juddiApiUrl>
<!-- In VM Transport Settings
<proxyTransport>org.jboss.internal.soa.esb.registry.client.JuddiInVMTransport</proxyTransport>
<custodyTransferUrl>org.apache.juddi.api.impl.UDDICustodyTransferImpl</custodyTransferUrl>
<inquiryUrl>org.apache.juddi.api.impl.UDDIInquiryImpl</inquiryUrl>
<publishUrl>org.apache.juddi.api.impl.UDDIPublicationImpl</publishUrl>
<securityUrl>org.apache.juddi.api.impl.UDDISecurityImpl</securityUrl>
<subscriptionUrl>org.apache.juddi.api.impl.UDDISubscriptionImpl</subscriptionUrl>
<subscriptionListenerUrl>org.apache.juddi.api.impl.UDDISubscriptionListenerImpl</subscriptionListenerUrl>
<juddiApiUrl>org.apache.juddi.api.impl.JUDDIApiImpl</juddiApiUrl> -->
<!-- RMI Transport Settings
<proxyTransport>org.jboss.internal.soa.esb.registry.client.JuddiRMITransport</proxyTransport>
<custodyTransferUrl>/juddiv3/UDDICustodyTransferService</custodyTransferUrl>
<inquiryUrl>/juddiv3/UDDIInquiryService</inquiryUrl>
<publishUrl>/juddiv3/UDDIPublicationService</publishUrl>
<securityUrl>/juddiv3/UDDISecurityService</securityUrl>
<subscriptionUrl>/juddiv3/UDDISubscriptionService</subscriptionUrl>
<subscriptionListenerUrl>/juddiv3/UDDISubscriptionListenerService</subscriptionListenerUrl>
<juddiApiUrl>/juddiv3/JUDDIApiService</juddiApiUrl>
<javaNamingFactoryInitial>org.jnp.interfaces.NamingContextFactory</javaNamingFactoryInitial>
<javaNamingFactoryUrlPkgs>org.jboss.naming</javaNamingFactoryUrlPkgs>
<javaNamingProviderUrl>jnp://localhost:1099</javaNamingProviderUrl>-->
</node>
<node>
<name>default-ws</name>
<description>jUDDI console node</description>
<!-- In VM Transport Settings -->
<proxyTransport>org.jboss.internal.soa.esb.registry.client.JuddiInVMTransport</proxyTransport>
<custodyTransferUrl>org.apache.juddi.api.impl.UDDICustodyTransferImpl</custodyTransferUrl>
<inquiryUrl>org.apache.juddi.api.impl.UDDIInquiryImpl</inquiryUrl>
<publishUrl>org.apache.juddi.api.impl.UDDIPublicationImpl</publishUrl>
<securityUrl>org.apache.juddi.api.impl.UDDISecurityImpl</securityUrl>
<subscriptionUrl>org.apache.juddi.api.impl.UDDISubscriptionImpl</subscriptionUrl>
<subscriptionListenerUrl>org.apache.juddi.api.impl.UDDISubscriptionListenerImpl</subscriptionListenerUrl>
<juddiApiUrl>org.apache.juddi.api.impl.JUDDIApiImpl</juddiApiUrl>
</node>
</nodes>
</manager>
</uddi>
jbossesb-properties.xml 文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2006, JBoss Inc., and others contributors as indicated
by the @authors tag. All rights reserved.
See the copyright.txt in the distribution for a
full listing of individual contributors.
This copyrighted material is made available to anyone wishing to use,
modify, copy, or redistribute it subject to the terms and conditions
of the GNU Lesser General Public License, v. 2.1.
This program is distributed in the hope that it will be useful, but WITHOUT A
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License,
v.2.1 along with this distribution; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
(C) 2005-2006,
@author JBoss Inc.
-->
<!-- $Id: jbossesb-unittest-properties.xml $ -->
<!--
These options are described in the JBossESB manual.
Defaults are provided here for convenience only.
Please read through this file prior to using the system, and consider
updating the specified entries.
-->
<esb
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="jbossesb-1_0.xsd">
<properties name="core">
<property name="org.jboss.soa.esb.jndi.server.context.factory" value="org.jnp.interfaces.NamingContextFactory"/>
<property name="org.jboss.soa.esb.jndi.server.url" value="${jboss.esb.bind.address}:1099"/>
<property name="org.jboss.soa.esb.persistence.connection.factory" value="org.jboss.internal.soa.esb.persistence.format.MessageStoreFactoryImpl"/>
<property name="org.jboss.soa.esb.loadbalancer.policy" value="org.jboss.soa.esb.listeners.ha.RoundRobin"/>
<property name="org.jboss.soa.esb.mime.text.types" value="text/*;application/xml;application/*+xml"/>
<property name="jboss.esb.invm.scope.default" value="NONE"/>
</properties>
<properties name="security">
<property name="org.jboss.soa.esb.services.security.implementationClass" value="org.jboss.internal.soa.esb.services.security.JaasSecurityService"/>
<property name="org.jboss.soa.esb.services.security.callbackHandler" value="org.jboss.internal.soa.esb.services.security.UserPassCallbackHandler"/>
<!-- Algorithm and key size for internal sealing of objects -->
<property name="org.jboss.soa.esb.services.security.sealAlgorithm" value="TripleDES"/>
<property name="org.jboss.soa.esb.services.security.sealKeySize" value="168"/>
<!-- Timeout in milliseconds. After which the context is considered invalid -->
<property name="org.jboss.soa.esb.services.security.contextTimeout" value="30000"/>
<property name="org.jboss.soa.esb.services.security.contextPropagatorImplementationClass" value="org.jboss.internal.soa.esb.services.security.JBossASContextPropagator"/>
<!-- Public keystore configuration used to hold keys for encryption/decryption -->
<property name="org.jboss.soa.esb.services.security.publicKeystore" value="/publicKeyStore"/>
<property name="org.jboss.soa.esb.services.security.publicKeystorePassword" value="testKeystorePassword"/>
<property name="org.jboss.soa.esb.services.security.publicKeyAlias" value="testAlias"/>
<property name="org.jboss.soa.esb.services.security.publicKeyPassword" value="testPassword"/>
<property name="org.jboss.soa.esb.services.security.publicKeyTransformation" value="RSA/ECB/PKCS1Padding"/>
</properties>
<properties name="registry">
<property name="org.jboss.soa.esb.registry.queryManagerURI" value="org.apache.juddi.v3.client.transport.wrapper.UDDIInquiryService#inquire"/>
<property name="org.jboss.soa.esb.registry.lifeCycleManagerURI" value="org.apache.juddi.v3.client.transport.wrapper.UDDIPublicationService#publish"/>
<property name="org.jboss.soa.esb.registry.securityManagerURI" value="org.apache.juddi.v3.client.transport.wrapper.UDDISecurityService#secure"/>
<property name="org.jboss.soa.esb.registry.implementationClass" value="org.jboss.internal.soa.esb.services.registry.JAXRRegistryImpl"/>
<property name="org.jboss.soa.esb.registry.factoryClass" value="org.apache.ws.scout.registry.ConnectionFactoryImpl"/>
<property name="org.jboss.soa.esb.registry.user" value="root"/>
<property name="org.jboss.soa.esb.registry.password" value="root"/>
<!-- the following parameter is scout specific to set the type of communication between scout and the UDDI (embedded, rmi, soap) -->
<property name="org.jboss.soa.esb.scout.proxy.transportClass" value="org.apache.ws.scout.transport.LocalTransport"/>
<property name="org.jboss.soa.esb.scout.proxy.uddiVersion" value="3.0"/>
<property name="org.jboss.soa.esb.scout.proxy.uddiNameSpace" value="urn:uddi-org:api_v3"/>
<!-- specify the interceptors, in order -->
<property name="org.jboss.soa.esb.registry.interceptors" value="org.jboss.internal.soa.esb.services.registry.InVMRegistryInterceptor"/>
<!-- Example of specifying multiple registry interceptors
<property name="org.jboss.soa.esb.registry.interceptors"
value="org.jboss.internal.soa.esb.services.registry.InVMRegistryInterceptor, org.jboss.internal.soa.esb.services.registry.CachingRegistryInterceptor"/>
-->
<!-- The following properties modify the cache interceptor behaviour -->
<property name="org.jboss.soa.esb.registry.cache.maxSize" value="100"/>
<property name="org.jboss.soa.esb.registry.cache.validityPeriod" value="600000"/>
<!-- Organization Category to be used by this deployment. -->
<property name="org.jboss.soa.esb.registry.orgCategory" value="org.jboss.soa.esb.:category"/>
</properties>
<properties name="transports" depends="core">
<property name="org.jboss.soa.esb.mail.smtp.host" value="localhost"/>
<property name="org.jboss.soa.esb.mail.smtp.user" value="jbossesb"/>
<property name="org.jboss.soa.esb.mail.smtp.password" value=""/>
<property name="org.jboss.soa.esb.mail.smtp.port" value="25"/>
<property name="org.jboss.soa.esb.mail.smtp.auth" value="true"/>
<property name="org.jboss.soa.esb.ftp.localdir" value="/tmp"/>
<property name="org.jboss.soa.esb.ftp.remotedir" value="/tmp"/>
<property name="org.jboss.soa.esb.jms.connectionPool" value="20"/>
<property name="org.jboss.soa.esb.jms.sessionSleep" value="30"/>
<!-- expiry of messages to temporary invm destinations (default replies)
expire after the following timeout, specified in milliseconds (5 mins) -->
<property name="org.jboss.soa.esb.invm.expiryTime" value="300000"/>
<!-- Uncomment this to return stack traces when exposing an ESB service through WS
<property name="org.jboss.soa.esb.ws.returnStackTrace" value="true"/>
-->
<!-- Uncomment this to specify the WS response timeout when exposing an ESB service through WS
<property name="org.jboss.soa.esb.ws.timeout" value="30000"/>
-->
</properties>
<properties name="connection">
<property name="min-pool-size" value="5"/>
<property name="max-pool-size" value="10"/>
<property name="blocking-timeout-millis" value="5000"/>
<property name="abandoned-connection-timeout" value="10000"/>
<property name="abandoned-connection-time-interval" value="30000"/>
</properties>
<properties name="jca">
<property name="org.jboss.soa.esb.jca.activation.mapper.jms-ra.rar" value="org.jboss.soa.esb.listeners.jca.JBossActivationMapper"/>
<property name="org.jboss.soa.esb.jca.activation.mapper.wmq.jmsra.rar" value="org.jboss.soa.esb.listeners.jca.WMQActivationMapper"/>
</properties>
<properties name="dbstore">
<!-- connection manager type -->
<!-- <property name="org.jboss.soa.esb.persistence.db.conn.manager" value="org.jboss.internal.soa.esb.persistence.manager.StandaloneConnectionManager"/> -->
<property name="org.jboss.soa.esb.persistence.db.conn.manager" value="org.jboss.internal.soa.esb.persistence.manager.J2eeConnectionManager"/>
<!-- this property is only used if using the j2ee connection manager -->
<property name="org.jboss.soa.esb.persistence.db.datasource.name" value="java:/JBossESBDS"/>
<!-- standalone connection pooling settings -->
<property name="org.jboss.soa.esb.persistence.db.connection.url" value="jdbc:hsqldb:hsql://localhost:9001/"/>
<property name="org.jboss.soa.esb.persistence.db.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="org.jboss.soa.esb.persistence.db.user" value="sa"/>
<property name="org.jboss.soa.esb.persistence.db.pwd" value=""/>
<property name="org.jboss.soa.esb.persistence.db.pool.initial.size" value="2"/>
<property name="org.jboss.soa.esb.persistence.db.pool.min.size" value="2"/>
<property name="org.jboss.soa.esb.persistence.db.pool.max.size" value="5"/>
<!--table managed by pool to test for valid connections - created by pool automatically -->
<property name="org.jboss.soa.esb.persistence.db.pool.test.table" value="pooltest"/>
<property name="org.jboss.soa.esb.persistence.db.pool.timeout.millis" value="5000"/>
</properties>
<properties name="filters">
<property name="org.jboss.soa.esb.filter.1" value="org.jboss.internal.soa.esb.message.filter.MetaDataFilter"/>
<!-- property name="org.jboss.soa.esb.filter.#" value="org.jboss.internal.soa.esb.message.filter.EntryExitTimeFilter"/ -->
<property name="org.jboss.soa.esb.filter.2" value="org.jboss.internal.soa.esb.message.filter.GatewayFilter"/>
</properties>
<properties name="rules">
<!-- change this to true if you wish to have the same behaviour as ESB4.6 and prior (including SOA 4.3) -->
<property name="org.jboss.soa.esb.services.rules.continueState" value="false"/>
</properties>
</esb>
如果控制台打印出了webservice总输出的信息,说明服务编排成功。还可以从jboss的控制台查看流程实例的节点是否运行到了end节点