使用代理服务调用Soap服务

时间:2014-03-17 06:22:56

标签: wso2 wso2esb wso2carbon

我想创建一个代理服务来使用wso2代理服务调用外部Soap服务。

我已经创建了这样的代理服务:

<target>
    <inSequence>
        <property name="messageType" value="text/xml" scope="axis2"/>
        <property name="ContentType" value="text/xml" scope="axis2"/>
    </inSequence>
    <outSequence>
        <property name="messageType" value="text/xml" scope="axis2"/>
        <property name="ContentType" value="text/xml" scope="axis2"/>
        <send/>
    </outSequence>
    <faultSequence>
        <log level="full">
            <property name="MESSAGE" value="Executing default &quot;fault&quot; sequence"/>
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
        </log>
        <log level="custom">
            <property name="Trace" expression="get-property('ERROR_DETAIL')"/>
        </log>
    </faultSequence>
    <endpoint>
        <address uri="http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit"/>
    </endpoint>
</target>

请查看此链接(http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

我想使用代理服务调用此Soap服务。

我正在使用REST Client(Mozilla Firefox Addon)和

我的输入请求:

<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
 <Celsius>33</Celsius>
</CelsiusToFahrenheit>

使用代理服务调用此服务时出错。

以下是我的错误。我在代理服务配置上启用了TRACE。

[2014-03-17 11:42:16,187]  WARN {SERVICE_LOGGER.FilterMediatorProxy} -  Executing fault handler due to exception encountered
[2014-03-17 11:42:16,188]  WARN {SERVICE_LOGGER.FilterMediatorProxy} -  ERROR_CODE : 0 ERROR_MESSAGE : Unexpected error during sending message out
[2014-03-17 11:42:16,188]  INFO {SERVICE_LOGGER.FilterMediatorProxy} -  FaultHandler executing impl: org.apache.synapse.mediators.MediatorFaultHandler
[2014-03-17 11:42:16,189]  WARN {SERVICE_LOGGER.FilterMediatorProxy} -  Executing fault sequence mediator : org.apache.synapse.mediators.base.SequenceMediator
[2014-03-17 11:42:16,194]  INFO {SERVICE_LOGGER.FilterMediatorProxy} -  To: http://10.132.97.131:9763/services/FilterMediatorProxy.FilterMediatorProxyHttpEndpoint/, From: 10.132.97.131, Direction: request, MESSAGE = Executing default "fault" sequence, ERROR_CODE = 0, ERROR_MESSAGE = Unexpected error during sending message out, Envelope: 
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
   <Celsius>33</Celsius>
</CelsiusToFahrenheit></soapenv:Body></soapenv:Envelope>
[2014-03-17 11:42:16,206]  INFO {SERVICE_LOGGER.FilterMediatorProxy} -  
Trace = org.apache.synapse.SynapseException: Unexpected error during sending message out
    at org.apache.synapse.core.axis2.Axis2Sender.handleException(Axis2Sender.java:172)
    at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:71)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send   (Axis2SynapseEnvironment.java:338)
    at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:333)
    at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:187)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at org.wso2.carbon.core.transports.CarbonServlet.doPost(CarbonServlet.java:231)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.equinox.http.helper.FilterServletAdaptor$FilterChainImpl.doFilter(FilterServletAdaptor.java:56)
    at org.wso2.carbon.mashup.jsservices.custom.ui.CustomUIServletFilter.doFilter(CustomUIServletFilter.java:233)
    at org.eclipse.equinox.http.helper.FilterServletAdaptor.service(FilterServletAdaptor.java:37)
    at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:128)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:68)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.wso2.carbon.tomcat.ext.servlet.DelegationServlet.service(DelegationServlet.java:68)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.wso2.carbon.tomcat.ext.filter.CharacterSetFilter.doFilter(CharacterSetFilter.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:178)
    at org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
    at org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:56)
    at org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:141)
    at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:156)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:52)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.axis2.AxisFault: Connection refused: connect
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
    at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
    at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
    at org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.send(DynamicAxisOperation.java:185)
    at org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.executeImpl(DynamicAxisOperation.java:167)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
    at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)
    at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:59)
    ... 44 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.reflect.GeneratedMethodAccessor113.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
    at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:622)
    at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
    ... 53 more

我的配置有什么问题?当我直接调用Soap服务(不使用REST客户端的任何代理)时,我正确地得到了响应。

1 个答案:

答案 0 :(得分:0)

您必须将请求发送到后端服务, 在以下代理中,在inSequence中,它将请求发送到后端服务,并且后端服务的响应由<send/>

在outSequence中发送回客户端
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="CelsiusToFahrenheitService"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="full"/>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>

我使用ESB中的Try this service

测试了上述代理

请求是,

<body>
 <CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
   <Celsius>88</Celsius>
 </CelsiusToFahrenheit>    
</body>

我收到了以下回复,

<CelsiusToFahrenheitResponse xmlns="http://www.w3schools.com/webservices/">
   <CelsiusToFahrenheitResult>190.4</CelsiusToFahrenheitResult>
</CelsiusToFahrenheitResponse>