top of page

IllegalArgumentException while consuming message from AMQ by showing junk characters

java.lang.IllegalArgumentException: Session variable "��_ #org.mule.session.DefaultMuleSession. .�v�_�a� _sr_

flowConstructt_ Lorg/mule/api/construct/FlowConstruct" is malfomed and cannot be read

at org.mule.session.LegacySessionHandler.retrieveSessionInfoFromMessage(LegacySessionHandler.java:79)

You might have seen the following issue when dealing with Mule and AMQ’s. There might be multiple reasons on why Mule server will complain.

  • Mule internally uses a mechanism to set all the session variables in an encoded string and sets in property. This encoded string will contain the key value pairs.

  • There is also have a mechanism to set the outbound properties on a Mule message and retrieve those information via properties concept of AMQ.

Mule when it consumes message from AMQ, it tries to parse the parameters. While parsing the outbound properties. It specifically decodes property.

While decoding it sets the key and value to Mule session variable.

In most of the scenarios, above error will be thrown if we have set any session variable with Because there is a logic to tokenize on ; and parse the key and value. If there is any value with semicolon then it will be treated as a key value pair and tries to parse. If parsing fails then it will result in IllegalArgumentException

 

public MuleSession retrieveSessionInfoFromMessage(MuleMessage message) throws MuleException

{

MuleSession session = new DefaultMuleSession();

String sessionId = message.getInboundProperty(MuleProperties.MULE_SESSION_ID_PROPERTY);

Object sessionHeader = message.getInboundProperty(MuleProperties.MULE_SESSION_PROPERTY);

if (sessionId != null)

{

throw new IllegalStateException(

"This session handler does not know how to look up session information for session id: "

+ sessionId);

}

if (sessionHeader != null)

{

String sessionString;

try

{

sessionString = new String((byte[]) decoder.transform(sessionHeader), message.getEncoding());

}

catch (UnsupportedEncodingException e)

{

sessionString = new String((byte[]) decoder.transform(sessionHeader));

}

if (logger.isDebugEnabled())

{

logger.debug("Parsing session header: " + sessionString);

}

String pair;

String name;

String value;

for (StringTokenizer stringTokenizer = new StringTokenizer(sessionString, ";"); stringTokenizer.hasMoreTokens();)

{

pair = stringTokenizer.nextToken();

int i = pair.indexOf("=");

if (i == -1)

{

throw new IllegalArgumentException(

CoreMessages.sessionValueIsMalformed(pair).toString());

}

name = pair.substring(0, i).trim();

value = pair.substring(i + 1).trim();

session.setProperty(name, value);

if (logger.isDebugEnabled())

{

logger.debug("Added MuleSession variable: " + pair);

}

}

}

return session;

}

 

Solution: Best possible solution would be to remove all the session variables from the Mule message. If not at least remove the session variables which can possibly contain ; and = inside value.

In our case, we were setting the entire payload which was map. This map internally contained semicolon which was causing it to break.


Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Social Icon
bottom of page