camel-soap 客户端如何发起请求
最近有一个小项目,要用到Springboot,ApacheCamel,WebService.
目前我要向该地址(http://121.42.255.15:82/HsCRM...发请求,
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns1="urn:HsCRMWebSrvIntf" name="IHsCRMWebSrvservice" targetNamespace="http://tempuri.org/">
<types>
<xs:schema xmlns="urn:HsCRMWebSrvIntf" targetNamespace="urn:HsCRMWebSrvIntf">
<xs:complexType name="TReturnInfo">
<xs:sequence>
<xs:element name="RtnMsg" type="xs:string"/>
<xs:element name="OutputPara" type="xs:string"/>
<xs:element name="ReturnCode" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>
<message name="IWsPosCommOperate0Request">
<part name="piFunctionCode" type="xs:int"/>
<part name="psInputPara" type="xs:string"/>
</message>
<message name="IWsPosCommOperate0Response">
<part name="return" type="ns1:TReturnInfo"/>
</message>
<portType name="IHsCRMWebSrv">
<operation name="IWsPosCommOperate">
<input message="tns:IWsPosCommOperate0Request"/>
<output message="tns:IWsPosCommOperate0Response"/>
</operation>
</portType>
<binding name="IHsCRMWebSrvbinding" type="tns:IHsCRMWebSrv">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="IWsPosCommOperate">
<soap:operation soapAction="urn:HsCRMWebSrvIntf-IHsCRMWebSrv#IWsPosCommOperate" style="rpc"/>
<input message="tns:IWsPosCommOperate0Request">
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:HsCRMWebSrvIntf-IHsCRMWebSrv"/>
</input>
<output message="tns:IWsPosCommOperate0Response">
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:HsCRMWebSrvIntf-IHsCRMWebSrv"/>
</output>
</operation>
</binding>
<service name="IHsCRMWebSrvservice">
<port name="IHsCRMWebSrvPort" binding="tns:IHsCRMWebSrvbinding">
<soap:address location="http://121.42.255.15:82/HsCRMWebSrv.dll/soap/IHsCRMWebSrv"/>
</port>
</service>
</definitions>
函数原型如下:
function IWsPosCommOperate (const piFunctionCode: Integer;
const psInputPara: WideString):TReturnInfo;stdcall
n 输入参数:
piFunctionCode:功能代码;
psInputPara:其他输入参数,一般是XML格式的字符串,其具体内容根据功能来决定;
n 输出参数:
TReturnInfo 的类定义如下:
RtnMsg:错误或异常消息字符串,需进行Base64位转换。
OutputPara:xml格式的结果字符串(成功时才有值)
ReturnCode:返回的结果代码
下图是我用SoapUI获得的结果
Route部分代码
@Component
public class PublicKeyRouter extends RouteBuilder {
public void configure() throws Exception {
// JaxbDataFormat jaxb = new JaxbDataFormat(IWsPosCommOperate.class.getPackage().getName());
JaxbDataFormat jaxb2 = new JaxbDataFormat(IWsPosCommOperateResponse.class.getPackage().getName());
from("timer://foo?fixedRate=true&period=10000")
.process(new IWsPosCommOperateProcessor())
.to("spring-ws:http://121.42.255.15:82/HsCRMWebSrv.dll/soap/IHsCRMWebSrv")
.unmarshal(jaxb2)
.process(new TReturnInfoProcessor());
}
}
IwsPosCommOperateProcessor.class代码如下
String str = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:HsCRMWebSrvIntf-IHsCRMWebSrv\">\n"
+ " <soapenv:Header/>\n"
+ " <soapenv:Body>\n"
+ " <urn:IWsPosCommOperate soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
+ " <piFunctionCode xsi:type=\"xsd:int\">8</piFunctionCode>\n"
+ " <psInputPara xsi:type=\"xsd:string\"><InputParameter><Random>34</Random><ClientCode>1003_001</ClientCode></InputParameter></psInputPara>\n"
+ " </urn:IWsPosCommOperate>\n"
+ " </soapenv:Body>\n"
+ "</soapenv:Envelope>";
exchange.getIn().setBody(formartSoapString(str).getSOAPBody());
}
public SOAPMessage formartSoapString(String soapString)
{
MessageFactory msgFactory;
try
{
msgFactory = MessageFactory.newInstance();
SOAPMessage reqMsg =
msgFactory.createMessage(new MimeHeaders(),
new ByteArrayInputStream(soapString.getBytes("UTF-8")));
reqMsg.saveChanges();
return reqMsg;
}
catch (Exception e)
{
return null;
}
}
我尝试了各种方式,都没有返回结果,所以我想请教下,
在"from..to.."的to之前如何正确传递数据?
万分感谢!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)