Mule-使用choice组件测试http get请求

Mule-使用choice组件测试http get请求,http,expression,mule,mule-studio,Http,Expression,Mule,Mule Studio,我有以下流程: <flow name="SOAPWebService" doc:name="SOAPWebService"> <http:inbound-endpoint address="http://localhost:8088/esb/" exchange-pattern="request-response" doc:name="HTTP"> </http:inbound-endpoint> <choice d

我有以下流程:

 <flow name="SOAPWebService" doc:name="SOAPWebService">

<http:inbound-endpoint address="http://localhost:8088/esb/"   exchange-pattern="request-response" doc:name="HTTP">          
</http:inbound-endpoint>

    <choice doc:name="Choice">
        <when expression="#[payload.contains('c22')]">
            <set-variable variableName="paramCtr" value="#[message.inboundProperties['ctr']]" doc:name="conteneur"/>
            <set-variable variableName="paramC" value="#[message.inboundProperties['c']]" doc:name="critere"/>
            <component class="com.example.components.SampleComponent" doc:name="Java"/>
            <mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="C:\MuleStudio\SandBox\resources\PrepareRequestXMLPort.xsl" doc:name="XSLT">
                <mulexml:context-property key="paramCtr" value="#[flowVars['paramCtr']]"/>
                <mulexml:context-property key="paramC" value="#[flowVars['paramC']]"/>
            </mulexml:xslt-transformer>
            <cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="SOAP"/>
            <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8080/ClientsDB/port" doc:name="PortWS"/>
        </when>
        <otherwise>
            <set-variable variableName="paramCtr" value="#[message.inboundProperties['ctr']]" doc:name="conteneur"/>
            <set-variable variableName="paramC" value="#[message.inboundProperties['c']]" doc:name="critere"/>
            <component class="com.example.components.SampleComponent" doc:name="Java"/>
            <mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="C:\MuleStudio\SandBox\resources\PrepareRequestXMLDouane.xsl" doc:name="XSLT">
                <mulexml:context-property key="paramCtr" value="#[flowVars['paramCtr']]"/>
                <mulexml:context-property key="paramC" value="#[flowVars['paramC']]"/>
            </mulexml:xslt-transformer>
            <cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="SOAP"/>
            <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8080/ClientsDB/douane" doc:name="DouaneWS"/>
        </otherwise>
    </choice>


<byte-array-to-string-transformer   doc:name="Byte Array to String" />
    <file:outbound-endpoint path="C:\MuleStudio\SandBox\output" outputPattern="#[function:datestamp:dd-MM-yy]_#[function:systime].xml " responseTimeout="10000" doc:name="Outgoing File"/>

我想测试像
http://localhost:8088/esb/?type=xxxx&id=1234
如果它包含字符串
xxxx
,将请求路由到所需的web服务代理。 我试过使用表达式
expression=“#[string.contains['xxxxx']]”
,但它似乎不起作用

有什么想法吗


谢谢。

两件事:您需要将“字符串”替换为要在其上执行的属性。消息属性或有效负载等,即#[payload.contains…]

“contains”是Java.lang.String上的一个Java方法,因此您需要使用带有()而不是[]的标准Java方法调用

工作示例:

<choice doc:name="Choice">
    <when expression="#[payload.contains('xxxx')]">

        <logger level="ERROR" message="YES" />
    </when>
    <otherwise>
        <logger level="ERROR" message="NO" />
    </otherwise>
</choice>

或者直接为查询参数处理入站属性:


两件事:您需要将“字符串”替换为要在其上执行的属性。消息属性或有效负载等,即#[payload.contains…]

“contains”是Java.lang.String上的一个Java方法,因此您需要使用带有()而不是[]的标准Java方法调用

工作示例:

<choice doc:name="Choice">
    <when expression="#[payload.contains('xxxx')]">

        <logger level="ERROR" message="YES" />
    </when>
    <otherwise>
        <logger level="ERROR" message="NO" />
    </otherwise>
</choice>

或者直接为查询参数处理入站属性:


在http入站后,使用set变量将查询参数存储到流变量中。 然后在表达式中使用流变量

<set-variable value="#[message.inboundProperties['id']]" variableName="paramId"></set-variable>
<set-variable value="#[message.inboundProperties['type']]" variableName="paramType"></set-variable>


or you can directly use inbound property for comparision.

    <when expression="#[message.inboundProperties['type']== 'XXXX']">

也可以直接使用入站属性进行比较。

在http入站后,使用set变量将查询参数存储到流变量中。 然后在表达式中使用流变量

<set-variable value="#[message.inboundProperties['id']]" variableName="paramId"></set-variable>
<set-variable value="#[message.inboundProperties['type']]" variableName="paramType"></set-variable>


or you can directly use inbound property for comparision.

    <when expression="#[message.inboundProperties['type']== 'XXXX']">

也可以直接使用入站属性进行比较。

谢谢你的回答,我没有得到你的第一个解决方案。第二个作为输出org.mule.module.cxf.support.StreamClosingInterceptor提供$1@ecc6dcthe异常与此选择路由器无关。您是否尝试了Logger并查看了在流中引发此异常的确切位置。你能提供完整的流程吗?我不知道choice组件到底发生了什么,但我只在运行流程时得到了org.mule.module.cxf.support.StreamClosingInterceptor$1@ecc6dc而不是soap响应。当我不使用choce组件时,我通常会得到soap响应,但是当我添加choice和另一个web服务代理时,我得到了上述响应。因此,您最初发布的与choice相关的帖子得到了正确的解决。所以,我们接受这个答案。关于你的新问题,我想它与你之前发布的问题相似。我为新问题创建了另一个帖子。非常感谢你的帮助。谢谢你的回答,我没有得到你的第一个解决方案。第二个作为输出org.mule.module.cxf.support.StreamClosingInterceptor提供$1@ecc6dcthe异常与此选择路由器无关。您是否尝试了Logger并查看了在流中引发此异常的确切位置。你能提供完整的流程吗?我不知道choice组件到底发生了什么,但我只在运行流程时得到了org.mule.module.cxf.support.StreamClosingInterceptor$1@ecc6dc而不是soap响应。当我不使用choce组件时,我通常会得到soap响应,但是当我添加choice和另一个web服务代理时,我得到了上述响应。因此,您最初发布的与choice相关的帖子得到了正确的解决。所以,我们接受这个答案。关于你的新一期,我想它与你之前发布的问题相似。我为新一期创建了另一篇文章。非常感谢你的帮助。