6

According to the following ticket: https://www.mulesoft.org/jira/browse/MULE-6427 For NullPayload I should be able to use :

<when expression="#[payload == null]">

but that fails. So instead I have to use:

<when expression="#[payload is NullPayload]">

Am I doing something wrong? Or is this the correct way for checking for null or NullPayload?

eebbesen
  • 5,070
  • 8
  • 48
  • 70
jon lee
  • 887
  • 1
  • 15
  • 32

6 Answers6

9

In theory, this should be fixed, but it doesn't looks like so. I'm using CE 3.4.0 and the expression #[payload == null] doesn't work for NullPayload.

I've found this link that shows how to check if payload is NullPayload correctly:

#[payload is org.mule.transport.NullPayload]

I actually needed to know if payload was not NullPayload, so my expression was:

#[!(payload is org.mule.transport.NullPayload)]

Works like a charm. :)

mathielo
  • 6,725
  • 7
  • 50
  • 63
  • Thanks @mathielo, I was going crazy. The [MULE-6427](https://www.mulesoft.org/jira/browse/MULE-6427) said it was fixed and even their [MEL expression page](http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips) says you should be able to use `#[payload == null]` but only your solution works for me. Many thanks again! – Doug Ayers Apr 02 '15 at 19:34
  • 1
    Thanks, you helped me :) Mulesoft is very poor documented :( – Dariusz Mydlarz Apr 09 '15 at 14:17
4

In Mule 3.7, (Studio 5.2) for a NullPayload, #[payload == null] now returns true. Interestingly, #[payload is NullPayload] returns false.

eebbesen
  • 5,070
  • 8
  • 48
  • 70
1

Try this to check:

#[payload == empty]

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
  • As in Collection.isEmpty() ? My payload is not a collection so there will be no method isEmpty(). Do you have the same issue with == null then? I can get around the issue by using instanceof. The main issue is that I should be able to use == null – jon lee Dec 05 '14 at 16:31
1

This works on version 3.5: #[payload is NullPayload]

eebbesen
  • 5,070
  • 8
  • 48
  • 70
0

This seems to be still true in the very lastest version of Mule as per this code.

This won't work if you are at a version < than 3.4

Víctor Romero
  • 5,107
  • 2
  • 22
  • 32
0

This is quite interesting.

The expression which is not working for you is working for me:

<when expression="#[!(payload == null)]">

and interestingly the other suggestions (listed below) are not giving the expected results:

<when expression="!(payload instanceof org.mule.transport.NullPayload)">
<when expression="#[!(payload is org.mule.transport.NullPayload)]">
<when expression="#[!(payload is NullPayload)]">
Krutik
  • 1,107
  • 13
  • 18