Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用请求路径在Mule ESB中进行路由_Java_Xml_Mule - Fatal编程技术网

Java 如何使用请求路径在Mule ESB中进行路由

Java 如何使用请求路径在Mule ESB中进行路由,java,xml,mule,Java,Xml,Mule,您好,我正在尝试在flow中添加一个路由器,这样我就可以重复使用我的代码并避免重复 我通常为每个请求路径执行一个流程,例如: HTTP LISTENER=localhost:8080/mule1 HTTP LISTENER=localhost:8080/mule2 我想知道是否可以使用请求路径通过路由器/选择连接器进行路由。我不能按照它告诉我的那样去做,因为只有一个听众/ 这是我的密码: <flow name="Tickets"> <http:listener

您好,我正在尝试在flow中添加一个路由器,这样我就可以重复使用我的代码并避免重复

我通常为每个请求路径执行一个流程,例如:

HTTP LISTENER=localhost:8080/mule1 HTTP LISTENER=localhost:8080/mule2

我想知道是否可以使用请求路径通过路由器/选择连接器进行路由。我不能按照它告诉我的那样去做,因为只有一个听众/

这是我的密码:

<flow name="Tickets">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <logger message="#[message.inboundProperties.'http.listener.path']" level="INFO" doc:name="Logger"/>
        <choice doc:name="Choice">
            <when expression="#[message.inboundProperties.'http.request.path' == &quot;/getTicketByTicketCode&quot;]">
                <set-payload value="#[message.inboundProperties.'http.query.params'.ticketcode]" doc:name="Set Payload"/>
                <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[def writer = new StringWriter() 
def xml = new groovy.xml.MarkupBuilder(writer)
xml.mkp.xmlDeclaration(version: "1.0", encoding: "UTF-8")
xml.GetTicketByCode(xmlns: 'http://tempuri.org/') { 
  code(payload)
} 
result = writer.toString() ]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="GetTicketByCode" doc:name="Web Service Consumer"/>
            </when>
            <when expression="#[message.inboundProperties.'http.request.path' == &quot;/validateTickets&quot;]">
                <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="ValidateTicket" doc:name="Web Service Consumer"/>
            </when>
        </choice>
        <mulexml:xslt-transformer xsl-file="removeattributes.xsl" maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT"/>
        <json:xml-to-json-transformer doc:name="XML to JSON"/>
    </flow>


INFO  2015-05-26 09:25:40,303 [[billeterie].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: No listener found for request: (GET)/getTicketByTicketCode
INFO  2015-05-26 09:25:40,303 [[billeterie].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: Available listeners are: [(*)/]

INFO 2015-05-26 09:25:40303[[billeterie].HTTP\u Listener\u Configuration.worker.01]org.mule.module.HTTP.internal.Listener.HttpListenerRegistry:找不到请求的侦听器:(GET)/getTicketByTicketCode
INFO 2015-05-26 09:25:40303[[billeterie].HTTP_Listener_Configuration.worker.01]org.mule.module.HTTP.internal.Listener.HttpListenerRegistry:可用的侦听器有:[(*)/]

有没有办法让这一切顺利进行?或者,唯一的方法是添加另一个与路径类似的queryParam。谢谢

您可以使用以下
路径=“/*”
,我已将您的流程修改如下:-

<flow name="Tickets">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/*" doc:name="HTTP"/>
        <logger message="#[message.inboundProperties.'http.listener.path']" level="INFO" doc:name="Logger"/>
        <choice doc:name="Choice">
            <when expression="#[message.inboundProperties.'http.request.path'.contains('/getTicketByTicketCode')]">
                 <logger message="getTicketByTicketCode flow" level="INFO" doc:name="Logger"/>
                 <set-payload value="#[message.inboundProperties.'http.query.params'.ticketcode]" doc:name="Set Payload"/>
                <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[def writer = new StringWriter() 
def xml = new groovy.xml.MarkupBuilder(writer)
xml.mkp.xmlDeclaration(version: "1.0", encoding: "UTF-8")
xml.GetTicketByCode(xmlns: 'http://tempuri.org/') { 
  code(payload)
} 
result = writer.toString() ]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="GetTicketByCode" doc:name="Web Service Consumer"/>

            </when>
            <when expression="#[message.inboundProperties.'http.request.path'.contains('/validateTickets')]">
                 <logger message="validateTickets flow" level="INFO" doc:name="Logger"/> 
                  <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy"><![CDATA[]]></scripting:script>
                </scripting:component>
                <ws:consumer config-ref="Web_Service_Consumer" operation="ValidateTicket" doc:name="Web Service Consumer"/>
            </when>
            <otherwise>
               <logger message="Other than this url " level="INFO" doc:name="Logger"/> 

            </otherwise>

           <mulexml:xslt-transformer xsl-file="removeattributes.xsl" maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT"/>
        <json:xml-to-json-transformer doc:name="XML to JSON"/> 
        </choice>

    </flow>

现在,如果您的url包含getTicketByTicketCode,那么它将转到第一个流,如果它包含ValidateCitkets,那么它将转到第二个流


或者,如果它没有这两个选项中的任何一个,它将在条件下打印记录器,否则条件

无法相信我没有尝试。。。感谢您的回答,它非常有效。我建议您使用APIKit: