osgi2——camel閘道器呼叫其它系統webservice
阿新 • • 發佈:2019-01-06
上一節介紹了怎麼用camel和cxf去起一個webservice,這節介紹怎麼用camel去呼叫其它系統的webservice。
請看blueprint.xml的配置
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf" xmlns:cxfcore="http://cxf.apache.org/blueprint/core" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"> <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/blueprint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> <route> <from uri="<span style="font-family: Arial, Helvetica, sans-serif;">vm:_WGTest</span>"/> <to uri="cxf:http://192.168.1.100:8081/test?wsdlURL=http://192.168.1.100:8081/test?wsdl&dataFormat=RAW"/> </route> </camelContext> <bean id="gwrequest" class="com.cn.yyc.GWRequest"> <property name="camelcontext" ref="myCamelContext"/> </bean> </blueprint>
下面是com.cn.yyc.GWRequest
public class GWRequest{ private static final Logger log = LoggerFactory.getLogger(GWRequest.class); private CamelContext camelcontext; public void setCamelcontext(CamelContext camelcontext) { this.camelcontext = camelcontext; } @EndpointInject(uri = "vm:_WGTest") private ProducerTemplate producer; private String invoke(String xml){ Exchange exch = camelcontext.getEndpoint("vm:_WGTest").createExchange(); exch.setPattern(ExchangePattern.OutIn); exch.getIn().setHeader("SOAPAction", "\"\""); exch.getIn().setBody(xml);//報文內容 producer.send("vm:_WGTest", exch); return exch.getOut().getBody(String.class); } }