camel-soap 客户端如何发起请求

发布于 2022-09-05 03:01:48 字数 5543 浏览 30 评论 0

最近有一个小项目,要用到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获得的结果

clipboard.png

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情稳全场 2022-09-12 03:01:48

object(stdClass)[2]
public 'RtnMsg' => string 'PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8T3V0cHV0UGFyYW1ldGVyPjxSdG5Db2RlPjU8L1J0bkNv
ZGU+PEVyck1zZz69u9LXv827p7bL0N64xMPFteq74dSx0MXPosqnsNyjur3izvZYTUzKp7Dco7rO
xLW1tcS2pbLjzt7Qp6GjDQoNCkxpbmU6IDENCmhlbG8gPC9FcnJNc2c+PC9PdXRwdXRQYXJhbWV0
ZXI+DQo=' (length=239)
public 'OutputPara' => string '' (length=0)
public 'ReturnCode' => int 5
//'请求头' 
'POST /HsCRMWebSrv.dll/soap/IHsCRMWebSrv HTTP/1.1
Host: 121.42.255.15:82
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.30
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:HsCRMWebSrvIntf-IHsCRMWebSrv#IWsPosCommOperate"
Content-Length: 594

' (length=255)
'请求body' (length=10)
'<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:HsCRMWebSrvIntf-IHsCRMWebSrv" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:IWsPosCommOperate><piFunctionCode xsi:type="xsd:int">123</piFunctionCode><psInputPara xsi:type="xsd:string">helo</psInputPara></ns1:IWsPosCommOperate></SOAP-ENV:Body></SOAP-ENV:Envelope>
' (length=594)
 '响应头' (length=9)
 'HTTP/1.1 200 OK
Content-Length: 980
Content-Type: text/xml
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 28 Jun 2017 05:32:36 GMT
' (length=149)
'响应body' (length=10)
'<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body SOAP-ENC:encodingStyle="http://schemas.xmlsoap.org/soap/envelope/" xmlns:NS2="urn:HsCRMWebSrvIntf"><NS1:IWsPosCommOperateResponse xmlns:NS1="urn:HsCRMWebSrvIntf-IHsCRMWebSrv"><return href="#1"/></NS1:IWsPosCommOperateResponse><NS2:TReturnInfo id="1" xsi:type="NS2:TReturnInfo"><RtnMsg xsi:type="xsd:string">PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8T3V0cHV0UGFyYW1ldGVyPjxSdG5Db2RlPjU8L1J0bkNv
ZGU+PEVyck1zZz69u9LXv827p7bL0N64xMPFteq74dSx0MXPosqnsNyjur3izvZYTUzKp7Dco7rO
xLW1tcS2pbLjzt7Qp6GjDQoNCkxpbmU6IDENCmhlbG8gPC9FcnJNc2c+PC9PdXRwdXRQYXJhbWV0
ZXI+DQo=</RtnMsg><OutputPara xsi:type="xsd:string"></OutputPara><ReturnCode xsi:type="xsd:int">5</ReturnCode></NS2:TReturnInfo></SOAP-ENV:Body></SOAP-ENV:Envelope>
' (length=980)

array (size=1)
0 => string 'TReturnInfo IWsPosCommOperate(int $piFunctionCode, string $psInputPara)' (length=71)

array (size=1)
0 => string 'struct TReturnInfo {
string RtnMsg;
string OutputPara;
int ReturnCode;
}' (length=75)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文