Mule中的CXF Web服务代理配置问题

时间:2012-04-11 21:46:26

标签: soap cxf mule

现在,我有一个名为ProcessPayment的服务,可以调用计费系统。正如我们在这里看到的,我想通过我的支付服务拨打另一个结算服务。 PaymentService的响应有3个数据元素。 BillingService中需要其中一个。

如何在Mule中为两个或更多服务配置流量?我尝试了各种排列,但它不起作用!

骡-config.xml中

 <?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:ognl="http://www.mulesoft.org/schema/mule/ognl" xmlns:servlet="http://www.mulesoft.org/schema/mule/servlet"
    xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:pattern="http://www.mulesoft.org/schema/mule/pattern"
    xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
        http://www.mulesoft.org/schema/mule/pattern http://www.mulesoft.org/schema/mule/pattern/3.1/mule-pattern.xsd
        http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd 
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
        http://www.mulesoft.org/schema/mule/ognl http://www.mulesoft.org/schema/mule/ognl/current/mule-ognl.xsd 
        http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">

    <!-- <flow name="parallelservices"> <all enableCorrelation="ALWAYS"> <cxf:proxy-service 
        wsdlLocation="classpath:billingservice.wsdl" bindingId="BillingServiceServiceSoapBinding" 
        port="BillingServicePort" service="BillingServiceService" payload="body" 
        namespace="http://com.myapp.demo/" /> </all> </flow> -->

    <flow name="initpayment">
        <inbound-endpoint address="http://localhost:8585/services/processpayment">
            <cxf:proxy-service wsdlLocation="classpath:processpaymentservice.wsdl"
                bindingId="ProcessPaymentServiceServiceSoapBinding" service="ProcessPaymentServiceService"
                payload="body" namespace="http://com.myapp.demo/" />
        </inbound-endpoint>
        <outbound-endpoint address="http://localhost:8081/BillingEntry/services/BillingServicePort">
            <!-- <flow-ref name="parallelservices" /> -->
            <cxf:proxy-client/>
        </outbound-endpoint>
    </flow>

</mule>

处理付款wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ProcessPaymentServiceService" targetNamespace="http://processpayment.icp.sf/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://com.myapp.demo/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://processpayment.icp.sf/" schemaLocation="processpaymentservice_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="processPayment">
    <wsdl:part name="parameters" element="tns:processPayment">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="processPaymentResponse">
    <wsdl:part name="parameters" element="tns:processPaymentResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="IProcessPayment">
    <wsdl:operation name="processPayment">
      <wsdl:input name="processPayment" message="tns:processPayment">
    </wsdl:input>
      <wsdl:output name="processPaymentResponse" message="tns:processPaymentResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ProcessPaymentServiceServiceSoapBinding" type="tns:IProcessPayment">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="processPayment">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="processPayment">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="processPaymentResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ProcessPaymentServiceService">
    <wsdl:port name="ProcessPaymentServicePort" binding="tns:ProcessPaymentServiceServiceSoapBinding">
      <soap:address location="http://localhost:8081/ProcessPayment/services/ProcessPaymentServicePort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

结算服务wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="BillingServiceService" targetNamespace="http://com.myapp.demo2/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://billing.icp.sf/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://billing.icp.sf/" schemaLocation="billingservice_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="billingEntryResponse">
    <wsdl:part name="parameters" element="tns:billingEntryResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="billingEntry">
    <wsdl:part name="parameters" element="tns:billingEntry">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="IBillingService">
    <wsdl:operation name="billingEntry">
      <wsdl:input name="billingEntry" message="tns:billingEntry">
    </wsdl:input>
      <wsdl:output name="billingEntryResponse" message="tns:billingEntryResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="BillingServiceServiceSoapBinding" type="tns:IBillingService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="billingEntry">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="billingEntry">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="billingEntryResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="BillingServiceService">
    <wsdl:port name="BillingServicePort" binding="tns:BillingServiceServiceSoapBinding">
      <soap:address location="http://localhost:8081/BillingEntry/services/BillingServicePort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

即时问题

当我点击Mule配置入站URL时,我能够为ProcessPayment服务生成wsdl。但它显示

的修改值
   <import schemaLocation="".../>

   <wsdl:port><soap:address>*****</soap:address></wsdl:port>

使用此URL,我无法在SOAPui上测试服务。但是当我点击服务原始地址而不是Mule入站地址时,我得到了我的实际服务。它也在SOAP UI中运行。

快速提问:

如何执行流程?只需从浏览器或SOAPui调用入站URL就不会工作吗?

1 个答案:

答案 0 :(得分:2)

在这里,我创建了一个示例,演示了如何使用CXF代理执行SOAP信封级操作。从那里我相信你可以扩展和构建你需要的任何东西。

请注意:

  • 不需要代码生成,我实际上必须删除您生成的类,否则它不起作用。这个带有WSDL + XSD的单一XML配置就足够了。
  • 我已经对Mule核心元素进行了限定,以避免在默认命名空间中生成的元素XSL-T最终出现在Mule核心命名空间中。如果您将XSL片段外部化,则不需要这样做。
  • (人为的)示例公开了processpaymentservice.wsdl。它接受paymentType_req的值,假装它是一个IP地址并用它来调用http://www.webservicex.net/geoipservice.asmx。然后,geolocated coutry名称将用作流程付款响应的paymentType_res元素的值(其他2个值是伪造的)。
  • 使用soapUI 4.5和Mule 3.2.1进行测试。

享受!

<mule:flow name="processPaymentServiceOrchestration">
    <http:inbound-endpoint address="http://localhost:8080/ppso"
        exchange-pattern="request-response">
        <cxf:proxy-service wsdlLocation="classpath:processpaymentservice.wsdl"
            service="ProcessPaymentServiceService" namespace="http://processpayment.icp.sf/" />
    </http:inbound-endpoint>

    <!-- Transform input of ProcessPayment to input of GetGeoIP -->
    <mulexml:xslt-transformer>
        <mulexml:xslt-text>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:web="http://www.webservicex.net/">
              <xsl:template match="/">
                <web:GetGeoIP>
                   <web:IPAddress><xsl:value-of select="//paymentType_req" /></web:IPAddress>
                </web:GetGeoIP>
              </xsl:template>
            </xsl:stylesheet>
        </mulexml:xslt-text>
    </mulexml:xslt-transformer>

    <mule:message-properties-transformer>
        <mule:add-message-property key="SOAPAction" value="http://www.webservicex.net/GetGeoIP" />
    </mule:message-properties-transformer>

    <http:outbound-endpoint address="http://www.webservicex.net/geoipservice.asmx"
        exchange-pattern="request-response">
        <cxf:proxy-client soapVersion="1.2" />
    </http:outbound-endpoint>

    <!-- Transform response of GetGeoIP in response of ProcessPayment -->
    <mulexml:xslt-transformer>
        <mulexml:xslt-text>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:pp="http://processpayment.icp.sf/" xmlns:web="http://www.webservicex.net/">
              <xsl:template match="/">
                <pp:return>
                   <billingID_res>fake billingID_res</billingID_res>
                   <paymentID_res>fake paymentID_res</paymentID_res>
                   <paymentType_res><xsl:value-of select="//web:CountryName"/></paymentType_res>
                </pp:return>
              </xsl:template>
            </xsl:stylesheet>
        </mulexml:xslt-text>
    </mulexml:xslt-transformer>
</mule:flow>