Apache Servicemix 教程 – GET/POST传递

   这几天在南京出差,参与一个华为巴西的POC演示项目. 涉及到CRM,OSS,BSS,BA等多个生产系统. 原先项目采用WebLogic作为中间件(浙江电信自己的中间件,部署在Weblogic)上.由于该中间件的局限性,其他系统SOAP传递有点问题, 因此对方简易使用别的ESB产品,已便于支撑项目能够完成.

   CRM系统是把浙江电信CRM完全移植,采用sieble7. 可能是时代的局限性, sieble7还不支持soap消息的传递,而是使用一种特定结构的xml,通过post方式传递到外部系统. 最新的sieble8应该不会有这个问题.

   然而,阅读Servicemix文档,可以发现Servicemix并没有直接的HTTP Post/Get的Binding Component. 然后自己观察就可以发现,Servicemix提供了HTTP Binding Compoent组件, 而POST/GET方式正式最基本的HTTP提交方式. 因此完全可以用HTTP Bingding Compoent支持这点.

HTTP Binding Compoent    http://servicemix.apache.org/servicemix-http.html

  阅读HTTP Binding Compoent的文档.并没有找到那里有设置GET/POST参数的地方, 而POST/GET传递方式,最基本的一点是必须要有一个参数作为载体,然后通过这个载体传递到服务端.

  继续翻文档,翻Mail List,终于找到servicemix有个相似的例子: Http Upload

   使用HTTPMarshaler完全可以解决我们的需求.

Http 配置


				xmlns:http="http://servicemix.apache.org/http/1.0"

				xmlns:novaesb="http://www.fengsage.com/novaesb"

				xmlns="http://www.springframework.org/schema/beans"

				xmlns:xsi="http://http://www.w3.org/2001/XMLSchema-instance"

				xsi:schemaLocation="http://servicemix.apache.org/http/1.0 http://servicemix.apache.org/schema/servicemix-http-3.2.3.xsd

				http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

				service="novaesb:httplistener"

				endpoint="listenerEndpoint"

				locationURI="http://0.0.0.0:8192/query/"

				defaultMep="http://www.w3.org/2004/08/wsdl/in-out"

				targetService="novaesb:CustomerTarget"

				marshaler="#marshaler" />

				id="marshaler" class="com.fengsage.novaesb.HTTPMarshaler" />

				

com.fengsage.novaesb.HTTPMarshaler代码


				/*

				* To change this template, choose Tools | Templates

				* and open the template in the editor.

				*/

				package com.fengsage.novaesb;

				import javax.jbi.component.ComponentContext;

				import javax.jbi.messaging.MessageExchange;

				import javax.jbi.messaging.MessagingException;

				import javax.jbi.messaging.NormalizedMessage;

				import javax.servlet.http.HttpServletRequest;

				import javax.servlet.http.HttpServletResponse;

				import org.apache.log4j.Logger;

				import org.apache.servicemix.http.endpoints.DefaultHttpConsumerMarshaler;

				import org.apache.servicemix.jbi.jaxp.StringSource;

				/**

				* HTTP protocal POST/GET

				* @author Fred

				*/

				public class HTTPMarshaler extends DefaultHttpConsumerMarshaler{

				private static final Logger logger = Logger.getLogger(HTTPMarshaler.class);

				public MessageExchange createExchange(HttpServletRequest req, ComponentContext context) throws Exception {

				String request = req.getParameter("request");

				logger.info("******"+request);

				MessageExchange me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());

				NormalizedMessage in = me.createMessage();

				if (request != null) {

				in.setContent(new StringSource(this.wappedJBI(request)));

				} else {

				in.setContent(new StringSource(this.wappedJBI("null")));

				}

				me.setMessage(in, "in");

				return me;

				}

				public static String wappedJBI(String xml){

				String head = " "

				+ "

				+ "xmlns:xsd="http://www.w3.org/2001/XMLSchema" "

				+ "xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"";

				String body = ""+xml+"";

				String end = "";

				return head+body+end;

				}

				public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request,

				HttpServletResponse response) throws Exception {

				response.getOutputStream().print("11111111111111111");

				}

				}

 

~Over~

评论关闭。