上一节介绍了怎么用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); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。