- 浏览: 87033 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
518ts520:
03:07:24,852 INFO [ServiceInvo ...
JBoss ESB学习笔记16——第十五个ESB应用Web Service Consumer 1 -
dy.f:
你理解错误了,selector="type='fro ...
JBoss ESB学习笔记5——第四个ESB应用Hello World File Action -
xiaoshalou_2002:
错误贴上 。Exception in thread &q ...
JBoss ESB学习笔记12——第十一个ESB应用Spring Hello World -
xiaoshalou_2002:
我这边16个例子中的客户端运行都出错,是少了 ...
JBoss ESB学习笔记12——第十一个ESB应用Spring Hello World -
qianyang:
ligenhang 写道我部署也报java.lang.Runt ...
JBoss ESB学习笔记2——第一个ESB应用Hello World
续上篇介绍了第六个ESB应用,本文介绍第七个ESB应用——Https Gateway。
说明:本文及后续文章虽非百分百的原创,但毕竟包含本人的努力和付出,所以希望大家转载时务请注明出处:http://yarafa.iteye.com,谢谢合作。
1概述
该实例主要演示了两点:一是配置一个https的ESB入口,二是在ESB外部端点中配置http路由器实现https传输方式的调用。
2 新建ESB工程
操作过程略。
3 ESB配置
3.1 创建消息队列
这里将创建一个消息地理用于接收客户端消息,在esbcontent文件夹下创建文件jbm-queue-service.xml用于配置消息队列,内容如下:
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.jms.server.destination.QueueService" name="jboss.esb.quickstart.destination:service=Queue,name=httpsgateway" xmbean-dd="xmdesc/Queue-xmbean.xml"> <dependsptional-attribute-name="ServerPeer"> jboss.messaging:service=ServerPeer </depends> <depends>jboss.messaging:service=PostOffice</depends> </mbean> </server>
3.2 定义Provider
这里将创建两个provider,一个提供客户端消息通道,另一个是jbr-provider,下面具体介绍。
3.2.1 jms-provider
<jms-provider connection-factory="ConnectionFactory" name="JMS"> <jms-bus busid="httpsgatewayChanel"> <jms-message-filter dest-name="queue/httpsgateway" dest-type="QUEUE" /> </jms-bus> </jms-provider>
3.2.2 jbr-provider
<jbr-provider host="localhost" name="httpsgateway" protocol="https"> <property name="jbr-KeyStoreURL" value="C:/jbossesb-server-4.7/httpsgateway.keystore" /> <property name="jbr-KeyStorePassword" value="123456" /> <property name="jbr-TrustStoreURL" value="C:/jbossesb-server-4.7/httpsgateway.keystore" /> <property name="jbr-TrustStorePassword" value="123456" /> <property name="jbr-ClientAuthMode" value="need" /> <property name="serviceInvokerTimeout" value="20000" /> <jbr-bus busid="httpsgatewayJBRChanel" port="9433" /> </jbr-provider>
关于jbr-provider的配置如上所示,下面对各个属性做简要说明:
jbr-KeyStoreURL:密钥库文件的路径,下面会说明如何创建密钥库文件
jbr-KeyStorePassword:密钥库文件的密码,在创建密钥库文件时指定
jbr-TrustStoreURL:受信任的密钥库文件路径,可与jbr-KeyStoreURL属性值一样
jbr-TrustStorePassword:受信任的密钥库文件的密码
jbr-ClientAuthMode:客户端验证模式
serviceInvokerTimeout:服务调用时限
httpsgatewayJBRChanel:JBR端口设置
关于各个属性的详细说明,可参考官方文档或者相关API。
3.2.3 keystore制作
密钥库文件的制作如下图所示,这里使用的是JDK提供的keytool工具。关于如何使用keytool制作密钥库文件,请自行查找,网上到处都是,这里不再说明。
将制作好的keystore文件命名为httpsgateway.keystore,并保存至C:/jbossesb-server-4.7目录下。
3.2.4 配置属性文件
在esbcontent/ META-INF目录下新建属性文件HttpRouter.properties,其内容如下:
configurators=HttpProtocol protocol-socket-factory=org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory keystore=C:/jbossesb-server-4.7/httpsgateway.keystore keystore-passw=123456 truststore=C:/jbossesb-server-4.7/httpsgateway.keystore truststore-passw=123456 max-connections-per-host=5
3.3定义Action类
3.3.1 Client Action
该类用于打印输出客户端响应的具体内容。
package com.thu.afa.esb.jbossesb.action.client; import org.jboss.soa.esb.actions.AbstractActionLifecycle; import org.jboss.soa.esb.helpers.ConfigTree; import org.jboss.soa.esb.http.HttpHeader; import org.jboss.soa.esb.http.HttpResponse; import org.jboss.soa.esb.message.Message; import java.util.List; public class HttpResponsePrinter extends AbstractActionLifecycle { protected ConfigTree configTree; public HttpResponsePrinter(ConfigTree config) { this.configTree = config; } public Message process(Message message) throws Exception { HttpResponse httpResponse = (HttpResponse) message.getBody().get(HttpResponse.RESPONSE_KEY); System.out.println("=========== Client Response: ==================================="); System.out.println("Message Payload:"); System.out.println("\t[" + message.getBody().get() + "]"); System.out.println(); System.out.println("Http Response:"); System.out.println("\tCode: " + httpResponse.getResponseCode()); System.out.println("\tLength: " + httpResponse.getLength()); System.out.println("\tEncoding: " + httpResponse.getEncoding()); System.out.println("\tHeaders:"); List<HttpHeader> headers = httpResponse.getHttpHeaders(); for (HttpHeader header : headers) { System.out.println("\t\t" + header.getName() + ": " + header.getValue()); } System.out.println("================================================================"); return message; } }
3.3.2 Server Action
该类用于打印输出服务端请求的具体内容。
package com.thu.afa.esb.jbossesb.action.server; import org.jboss.soa.esb.actions.AbstractActionLifecycle; import org.jboss.soa.esb.helpers.ConfigTree; import org.jboss.soa.esb.message.Message; import org.jboss.soa.esb.message.Properties; public class HttpRequestPrinter extends AbstractActionLifecycle { protected ConfigTree configTree; public HttpRequestPrinter(ConfigTree config) { this.configTree = config; } public Message process(Message message) throws Exception { Properties properties = message.getProperties(); System.out.println("=========== Server Request: ===================================="); System.out.println("Message Payload:"); System.out.println("\t[" + message.getBody().get() + "]"); System.out.println(); System.out.println("\tHeaders:"); System.out.println("\t\thost: " + properties.getProperty("host")); System.out.println("\t\tMethod: " + properties.getProperty("MethodType")); System.out.println("\t\tPath: " + properties.getProperty("Path")); System.out.println("\t\tuser-agent: " + properties.getProperty("user-agent")); System.out.println("\t\tcontent-type: " + properties.getProperty("content-type")); System.out.println("================================================================"); message.getBody().add("Http Response Payload!!"); return message; } }
3.4 定义第一个Service
<service category="HttpsService" description="Https Client" invmScope="GLOBAL" name="HttpsClientService"> <listeners> <jms-listener busidref="httpsgatewayChanel" is-gateway="true" name="httpsgatewayListener" /> </listeners> <actions mep="OneWay"> <action name="httprouter" class="org.jboss.soa.esb.actions.routing.http.HttpRouter"> <property name="method" value="POST" /> <property name="responseType" value="STRING" /> <property name="endpointUrl" value="https://localhost:9433/x/y"> <http-client-property name="file" value="/META-INF/HttpRouter-localhost-https-9433.properties" /> </property> <property name="headers"> <header name="name" value="llu" /> </property> </action> <action name="printResponse" class="com.thu.afa.esb.jbossesb.action.client.HttpResponsePrinter" /> </actions> </service>
配置说明:该服务执行了两次操作,首先将接收到的消息执行了一次http转发,然后由HttpResponsePrinter打印请求的内容。
3.5 定义第二个Service
<service category="HttpsService" description="Https Server" invmScope="GLOBAL" name="HttpsServerService"> <listeners> <jbr-listener busidref="httpsgatewayJBRChanel" is-gateway="true" name="httpsgatewayJbsListener" /> </listeners> <actions> <action name="printMessage" process="process" class="com.thu.afa.esb.jbossesb.action.server.HttpRequestPrinter"/> </actions> </service>
配置说明:该服务用语打印输出接收到的消息的内容。
3.6 配置部署文件
部署依赖文件deployment.xml内容如下:
<jbossesb-deployment> <depends>jboss.esb.quickstart.destination:service=Queue,name=httpsgateway </depends> </jbossesb-deployment>
3.7 部署ESB
将整个工程导出成一个ESB文件,并保存至JBoss ESB Server的部署目录下,启动JBoss ESB Server即可。
4 ESB客户端
4.1 新建Java工程
这里略去操作过程以及添加所需要的Jar包,具体操作过程可参考第一个ESB实例说明。
4.2 发送消息的客户端
/*********************************************************************** * <p>Project Name: helloworldclient</p> * <p>File Name: com.thu.afa.esb.jbossesb.client.HttpsGatewayClient.java</p> * <p>Copyright: Copyright (c) 2010</p> * <p>Company: <a href="http://afa.thu.com">http://afa.thu.com</a></p> ***********************************************************************/ package com.thu.afa.esb.jbossesb.client; import java.util.Properties; import javax.jms.Message; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueReceiver; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; /** * <p>Class Name: HttpsGatewayClient</p> * <p>Description: </p> * @author Afa * @date 2010-9-7 * @version 1.0 */ public class HttpsGatewayClient { private QueueConnection connection; private QueueSession session; private Queue queue; public void setupConnection() throws Exception { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); properties.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); InitialContext context = new InitialContext(properties); QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("ConnectionFactory"); connection = factory.createQueueConnection(); queue = (Queue) context.lookup("queue/httpsgateway"); session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); connection.start(); System.out.println("Connection Started"); } public void stop() throws Exception { if(connection != null) connection.stop(); if(session != null) session.close(); if(connection != null) connection.close(); } public void sendAMessage(String text) throws Exception { QueueSender sender = session.createSender(queue); ObjectMessage message = session.createObjectMessage(text); sender.send(message); sender.close(); } public void receiveMessage() throws Exception { QueueReceiver receiver = session.createReceiver(queue); Message message = receiver.receive(); if(message != null) { if(message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; System.out.println(objectMessage.getObject().toString()); } else if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; System.out.println(textMessage.getText()); } } receiver.close(); } /** * <p>Title: </p> * <p>Method Name: main</p> * <p>Description: </p> * @author: Afa * @date: 2010-9-7 * @param args */ public static void main(String[] args) throws Exception { HttpsGatewayClient client = new HttpsGatewayClient(); client.setupConnection(); client.sendAMessage("Llu, miss you, afa"); client.stop(); } }
运行客户端,结果如下图所示:
上述便是ESB第七个应用实例。如有问题,欢迎指正。
-----------------------------------------------------
Stay Hungry, Stay Foolish!
http://yarafa.iteye.com
Afa
Mar 5th, 2011
-----------------------------------------------------
评论
但是,当运行客户端程序发送消息时,Eclipse console 中没有任何信息打印出来
请问这是什么问题??
不同service中的action的执行是没有先后顺序的
第一个service的
<http-client-property name="file"
14.value="/META-INF/HttpRouter-localhost-https-9433.properties" />
这行中的value值要修改为value="/META-INF/HttpRouter.properties"
20:34:55,145 WARN [ServiceController] Problem starting service jboss.esb:deploy
ment=sevenesb.esb
org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException: Error configuri
ng action processing pipeline
at org.jboss.soa.esb.listeners.message.MessageAwareListener.doInitialise
(MessageAwareListener.java:191)
at org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle.initia
lise(AbstractManagedLifecycle.java:133)
at org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController.init
发表评论
-
JBoss ESB学习笔记16——第十五个ESB应用Web Service Consumer 1
2011-04-15 21:06 3218续上篇介绍了第十四个ESB应用,本文介绍第十五个ESB应用—— ... -
JBoss ESB学习笔记15——第十四个ESB应用Transform XML to POJO
2011-04-12 13:09 1997续上篇介绍了第十三个ESB应用,本文介绍第十四个ESB应用—— ... -
JBoss ESB学习笔记14——第十三个ESB应用Transform CSV to XML
2011-04-09 13:12 1946续上篇介绍了第十二个ESB应用,本文介绍第十三个ESB应用—— ... -
JBoss ESB学习笔记13——第十二个ESB应用Spring AOP
2011-04-03 11:42 1566续上篇介绍了第十一个ESB应用,本文介绍第十二个ESB应用—— ... -
JBoss ESB学习笔记12——第十一个ESB应用Spring Hello World
2011-04-01 15:27 2283续上篇介绍了第十个ESB应用,本文介绍第十一个ESB应用——S ... -
JBoss ESB学习笔记11——第十个ESB应用Message Filters
2011-03-29 20:35 1923续上篇介绍了第九个ESB应用,本文介绍第十个ESB应用——Me ... -
JBoss ESB学习笔记10——第九个ESB应用JMS Topic
2011-03-26 21:14 2328续上篇介绍了第八个ESB应用,本文介绍第九个ESB应用——JM ... -
JBoss ESB学习笔记9——第八个ESB应用JMS Router
2011-03-11 21:16 2512续上篇介绍了第七个ESB应用,本文介绍第八个ESB应用——JM ... -
JBoss ESB学习笔记7——第六个ESB应用Http Gateway
2011-02-26 10:45 3429续上篇介绍了第五个ESB应用,本文介绍第六个ESB应用——Ht ... -
JBoss ESB学习笔记6——第五个ESB应用Custom Action
2011-01-15 10:34 2218续上篇介绍了第四个ESB应用,本文介绍第五个ESB应用——Cu ... -
JBoss ESB学习笔记5——第四个ESB应用Hello World File Action
2011-01-08 11:23 2593续上篇介绍了第三个ESB应用,本文介绍第四个ESB应用——He ... -
JBoss ESB学习笔记4——第三个ESB应用Hello World Notification
2011-01-03 15:01 2985续上篇介绍了第二个ESB应用,本文介绍第三个ESB应用——He ... -
JBoss ESB学习笔记3——第二个ESB应用Hello World Action
2010-12-21 22:20 3776续上篇介绍了第一个ESB应用,本文介绍第二个ESB应用——He ... -
JBoss ESB学习笔记2——第一个ESB应用Hello World
2010-12-13 20:34 6525续上文搭建好开发环境后就可以开发ESB应用了。本文介绍第一个E ... -
JBoss ESB学习笔记1——搭建ESB开发环境
2010-12-12 13:55 7707最近由于工作需要用到 ...
相关推荐
8——第七个ESB代码Https Gateway 74 9——第八个ESB代码JMS Router 83 10——第九个ESB代码JMS Topic 91 11——第十个ESB代码Message Filters 99 12——第十一个ESB代码Spring Hello World 106 13——第十二个ESB...
JBossESB学习笔记 收集了网上1-16系列教程,笔记详细介绍了JBossESB各个组件的特性及配置文件的说明
Jboss_ESB学习笔记以及总结和实例
Jboss_ESB学习笔记,介绍的很详细,可以作为入门文档来看。
jboss esb 实例及讲解,我收集的资料整理做成书
Jboss_ESB学习笔记.doc
一、Jboss ESB的简介 1、 什么是ESB。 ESB的全称是Enterprise Service Bus,即企业服务总线。ESB是过去消息中间件的发展,ESB采用了“总线”这样一种模式来管理和简化应用之间的集成拓扑结构,以广为接受的开放...
JBoss ESB新手指南 / JBoss ESB Beginners Guide。 一本很好的jboss esb入门书籍。
jbossesb开发手册,适合初学者学习使用
9. 第七章 Webservices支持 52 9.1. JBossWS 52 10. 第八章 Web Services编排 53 10.1. WS-BPEL 53 11. 第九章 服务日程安排 54 11.1. 介绍 54 11.2. 简单日程表 54 11.3. Cron日程表 54 11.4. 日程监听器 55 11.5. ...
JBoss ESB 入门例子。主要是一个Server和一个Client。
NULL 博文链接:https://siye1982.iteye.com/blog/592400
JBOSS_Esb学习资料包含各种基础学习资料与协议交互资料
JBoss ESB Beginner's Guide
1.JBossESB的总体要求和我们应采取的架构方法的纲要。2.JBossESB的主要目的是提供一个部署,运行和管理的SOA基础结构。 3.SOA原则将贯穿于整个架构,而传统意义上ESB可能是它所提供功能的一狭小部分
。。。
中文版,简易介绍 JBOSS ESB的说明文档.
JbossESB开发环境配置.docxJbossESB开发环境配置.docx
直市场解决方案(VMS)是NAVTEQ公司中的一个机构,负责为客户提供定制的解决方案,...在本文中,我将讨论如何使用JBoss中间件平台来构建这样的系统,尤其是使用JBoss ESB和jBPM(JBoss Business Process Management)。
JBossTools实践系列:JBossESB服务开发入门