【问题标题】:Mule ESB - how to pass multi parameter to soap web service in browserMule ESB - 如何在浏览器中将多参数传递给soap Web服务
【发布时间】:2013-11-05 15:28:15
【问题描述】:

我只是对 Mule ESB 3.5 有一点经验,我发现大多数 Mule 示例只使用一个参数创建 SOAP Web 服务。例如,您可以在 SOAP Web 服务安全示例中看到这一点。

http://www.mulesoft.org/documentation/display/current/SOAP+Web+Service+Security+Example

所以我有一个问题,参考上面的例子,使用CHOICE流控制后,如何将多参数传递给SOAP Web服务的方法。

有人建议我是使用对象数组来传递多参数,但我还是一点头绪都没有。

感谢大卫。我只是试试你的建议。但我认为我应该更新我的问题以使其清楚。

首先,我创建网络服务

@WebService
public interface Greeter
{
    public String greet(String name);
    public String welcome( String name1,String name2);

}

然后我有一个用于 Web 服务配置的控制流

<flow name="UnsecureServiceFlow" doc:name="UnsecureServiceFlow">
    <http:inbound-endpoint address="http://localhost:63081/services/unsecure" exchange-pattern="request-response" doc:name="HTTP Inbound Endpoint"/>
    <cxf:jaxws-service serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="Unsecure service"/>
    <component class="com.mulesoft.mule.example.security.GreeterService" doc:name="Greeter Service" />
</flow>

Next is the sub flow using jax-ws client to call the method of web service
 <flow name="SecurityClients" doc:name="SecurityClients">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="63080" path="client" doc:name="HTTP Inbound Endpoint"/>
        <set-payload value="#[message.inboundProperties['http.query.params']['name']]" doc:name="Set payload with 'name' query param"/>
        <set-variable variableName="clientType" value="#[message.inboundProperties['http.query.params']['clientType']]" doc:name="Set clientType"/>
        <choice doc:name="Choice">
            <when expression="#[clientType == 'unsecure']">
                    <flow-ref name="unsecure" doc:name="Invoke unsecure sub-flow"/>
            </when>
            <when expression="#[clientType == 'usernameToken']">
                    <flow-ref name="usernameToken" doc:name="Invoke usernameToken sub-flow"/>
            </when>
            <when expression="#[clientType == 'usernameTokenSigned']">
                    <flow-ref name="usernameTokenSigned" doc:name="Invoke usernameToken Signed sub-flow"/>
            </when>
            <when expression="#[clientType == 'usernameTokenEncrypted']">
                    <flow-ref name="usernameTokenEncrypted" doc:name="Invoke usernameToken Encrypted sub-flow"/>
            </when>
            <when expression="#[clientType == 'samlToken']">
                    <flow-ref name="samlToken" doc:name="Invoke samlToken sub-flow"/>
            </when>
            <when expression="#[clientType == 'samlTokenSigned']">
                    <flow-ref name="samlTokenSigned" doc:name="Invoke samlToken Signed sub-flow"/>
            </when>
            <otherwise>
                    <set-payload value="Client type is not supported" doc:name="Client type is not supported"/>
            </otherwise>
        </choice>
        <set-property propertyName="Content-Type" value="text/plain" doc:name="Set response Content-Type"/>
        <catch-exception-strategy doc:name="Catch Exception Strategy">
            <set-payload value="There has been an Error processing the request" doc:name="Set Payload"/>
            <set-property propertyName="Content-Type" value="text/plain" doc:name="Set response Content-Type"/>
        </catch-exception-strategy>
    </flow>
    <sub-flow name="unsecure" doc:name="unsecure">
        <cxf:jaxws-client operation="greet" serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="Unsecure SOAP client" doc:description="Unsecure SOAP client"/>
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="63081" path="services/unsecure" doc:name="Invoke unsecure Web Service"/>
    </sub-flow>

使用该地址调用greet方法是可以的,它只有一个参数。 localhost:63080/client?clientType=usernameToken&name=John 但是,当我将 greet 方法更改为 welcome 方法时,我不知道如何将更多参数传递给它或必须更改任何内容,因为 payload只包含 name 参数

【问题讨论】:

  • 首先创建您的 WSDL,然后从中生成 JAX-WS 基础架构,您将拥有一个能够处理复杂对象的 Web 服务。
  • 谢谢大卫,但我想你在这里误解了我。在该示例中,通过选择流控制后,我将调用一个已经构建的 Web 服务方法,但该方法只有一个参数,当我更改为另一个有 2 个参数的方法时,我不知道如何传递参数给它。或者你可以更详细地指导我你的方法。再次感谢!
  • 我不明白:你想调用一个已经存在的网络服务吗?

标签: web-services soap cxf mule url-parameters


【解决方案1】:

从远程 Web 服务 WSDL 生成 JAX-WS client 类,并在 cxf:jaxws-client 配置元素中使用它们。

在您的情况下,您需要在每个when 中添加set-payload 才能创建cxf:jaxws-client 所需的请求对象。

假设您需要为samlToken 的情况创建一个org.saml.SamlToken 对象,您会这样做:

<set-payload value="#[st=new org.saml.SamlToken();st.field1=message.inboundProperties.field1; ... ; st]" />

when 之前的flow-ref

附言。您可以使用#[message.inboundProperties.clientType] 代替#[message.inboundProperties['http.query.params']['clientType']]

【讨论】:

  • 再次感谢大卫。我尝试了您的建议,但我只是更新了我的答案。你能再帮我一次吗?
  • 酷,我已经相应地审查了我的答案。
  • 所以如果我使用这个地址 localhost:63080/… ,我如何将 param1 和 param2 作为参数传递给 service welcome( String ,String )。如果我将 service 更改为 welcome(NameObject) 我可以使用 payload 作为 NameObject 容器,这样服务就可以运行良好。但我不想把所有服务都改成单参数服务
  • 在这种情况下,请求对象是一个值数组,即[String, String]。不知道“单参数服务”有什么问题?这不是文档/文字服务的全部想法吗?没有遵循 WSDL 优先的方法来创建这些服务?
  • 是的,这就是问题所在,大卫。如何传递值数组?就我而言,我需要完全从 URL 执行 Web 服务(用于性能测试)并获取输出
猜你喜欢
  • 2016-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多