版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yeyincai/article/details/47374937
上一节介绍了怎么用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);
}
}