我有以下流程:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json="http://www.mulesoft.org/schema/mule/json" version="EE-3.5.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<json:object-to-json-transformer name="Object_to_JSON" doc:name="Object to JSON"/>
<flow doc:name="HelloWorldFlow1" name="HelloWorldFlow1">
<http:inbound-endpoint doc:description="This endpoint receives an HTTP message." doc:name="HTTP" exchange-pattern="request-response" host="localhost" port="8081" contentType="application/json" path="mule/getBalance"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.HashMap"/>
<choice doc:name="Determine Bank" >
<when expression="#[message.payload.get('uid') == 'ABC']">
<set-payload value="When ABC case" doc:name="F Acct"/>
</when>
<otherwise>
<set-payload value="#['Default case, payload: ' + payload + ', payload.get(\047uid\047): ' + payload.get('uid')]" doc:name="SOF Bank"/>
</otherwise>
</choice>
</flow>
</mule>
我尝试将ABC的uid与ABC匹配,我得到了一个成功的数学,见下文
C:\curl>type input2.txt
{ "uid" : "ABC" }
C:\curl>curl -H "Content-Type: application/json" -i -d @input2.txt http://loc
ost:8081/mule/getBalance
HTTP/1.1 200 OK
Date: Mon, 21 Jul 2014 07:06:05 -0700
Server: Mule EE Core Extensions/3.5.0
Content-Type: application/json
X-MULE_SESSION: rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rd
7GGKAwAFWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvR
d0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wACnByb3BlcnRpZXN0AA9MamF2Y
dGlsL01hcDtMAA9zZWN1cml0eUNvbnRleHR0ACdMb3JnL211bGUvYXBpL3NlY3VyaXR5L1NlY3Vya
Q29udGV4dDt4cAFwdAAkMjdmNDdiNTAtMTBlMC0xMWU0LTk2NDYtMDAyMTVlNmIzZDkwc3IAJWphd
dXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW1xAH4AA0wABW11d
dAASTGphdmEvbGFuZy9PYmplY3Q7eHBzcgAkb3JnLm11bGUudXRpbC5DYXNlSW5zZW5zaXRpdmVIY
TWFwndHZ72dFzgADAAB4cHcMP0AAAAAAABAAAAAAeHEAfgAJeHB4
X-MULE_ENCODING: UTF-8
Content-Length: 13
Connection: close
我现在需要做的是尝试仅匹配uid的前三个字符
换句话说,给定以下JSON对象
{ "uid" : "ABC002" }
我希望在只有前三个字母(ABC)
的情况下获得点击所以我保留原始流程,并将JSON对象更改为
{ "uid" : "ABC002" }
...我收到以下回复:
C:\ curl&gt;输入input2.txt {“uid”:“ABC002”}
C:\curl>curl -H "Content-Type: application/json" -i -d @input2.txt http://localh
ost:8081/mule/getBalance
HTTP/1.1 200 OK
Date: Mon, 21 Jul 2014 07:11:35 -0700
Server: Mule EE Core Extensions/3.5.0
Content-Type: application/json
X-MULE_SESSION: rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rdtEW
7GGKAwAFWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvRmxv
d0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wACnByb3BlcnRpZXN0AA9MamF2YS91
dGlsL01hcDtMAA9zZWN1cml0eUNvbnRleHR0ACdMb3JnL211bGUvYXBpL3NlY3VyaXR5L1NlY3VyaXR5
Q29udGV4dDt4cAFwdAAkZWM3OTlmZjEtMTBlMC0xMWU0LTk2NDYtMDAyMTVlNmIzZDkwc3IAJWphdmEu
dXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW1xAH4AA0wABW11dGV4
dAASTGphdmEvbGFuZy9PYmplY3Q7eHBzcgAkb3JnLm11bGUudXRpbC5DYXNlSW5zZW5zaXRpdmVIYXNo
TWFwndHZ72dFzgADAAB4cHcMP0AAAAAAABAAAAAAeHEAfgAJeHB4
X-MULE_ENCODING: UTF-8
Content-Length: 64
Connection: close
Default case, payload: {uid=ABC002}, payload.get('uid'): ABC002
正如您所看到的,它没有使用输入字符串ov ABC002
来达到when条件我使用的条件是
<when expression="#[message.payload.get('uid') == 'ABC']">
如何更改此表达式,以便只检查传入字符串的前三个字符?
由于
答案 0 :(得分:1)
以这种方式尝试它应该可以正常工作
<when expression="#[message.payload.get('uid').startsWith('ABC')]">
希望这有帮助。