Mule MEL performs a substring on a thread variable

I have a my_variable variable with a value as a dynamic URL, for example -

http://stackoverflow.com/questions/ask

I want to make a substring on this dynamic URL to find the line after the last "/", that is, in the case of the above URL, I want to get the substring "ask"

How can I use MEL for this?

+4
source share
4 answers

You can use string functions that are available from the java.lang package.

#[flowVars['my_variable'].substring(flowVars['my_variable'].lastIndexOf('/'))]

Hope this helps.

+4
source

JDK MEL, (http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Reference):

  • java.lang. *
  • java.io. *
  • java.net. *
  • java.util. *
  • java.math.BigDecimal
  • java.math.BigInteger
  • javax.activation.DataHandler
  • javax.activation.MimeType
  • java.util.regex.Pattern
  • org.mule.api.transformer.DataType
  • org.mule.transformer.types.DataTypeFactory

8081 :

<flow name="testedbFlow3">
    <http:inbound-endpoint host="0.0.0.0" port="8081" />
    <expression-transformer expression="#[message.inboundProperties['http.request'].split(&quot;^.*/&quot;)[1]]"/>
</flow>
+2

You can use the basic Java methods String, such as substring(), and lastIndexOf()to the variable.

+1
source
#[flowVars['my_variable'].substring(flowVars['my_variable'].lastIndexOf('/'))]

which is easy

0
source

Source: https://habr.com/ru/post/1540110/


All Articles