1
votes

Let me explain my configuration:

  1. ActiveMQ 5.12.0

  2. AnyPoint Studio 5.2.1

  3. Mule 3.6.1

    Flow of application:

Config

I am using FunctionalTestCase to post and retrieve a message from queue.

 MuleClient client = muleContext.getClient();
 String productAsJson = "{\"name\":\"Widget\",  \"price\":9.99,  \"weight\":1.0,  \"sku\":\"abcd-12345\"}";
 client.dispatch("http://localhost:8081/products", productAsJson, null);
 MuleMessage result = client.request("jms://products", RECEIVE_TIMEOUT);

What is happening is the message is getting posted but when I try to retrieve it, I get the string "{NullPayLoad}".

After stepping back through the flow, I have discovered the message payload, when using the Mule Client, is not making the queue. While looking through the admin console for ActiveMQ, I discovered the message details is "{NullPayload}". When I check using the Advance Risk Client, the JSON message is getting posted correctly.

Any suggestions would be greatly appreciated.

Russ

1

1 Answers

3
votes

It's NullPayload when using the MuleClient because by default the http operation will be GET and wont be expecting a body to parse.

The MuleClient is more suited to working with Mule transport infrastructure such as the JMS transport or the old http transport. I don't think it plays nice with the new http listener module.

Normally with the transports you can set the method via a property but that doesnt seem to work with the http:listener:

        MuleMessage message = getTestMuleMessage();
        message.setPayload(productAsJson);
        message.setProperty("http.method", "POST", PropertyScope.INBOUND);

        client.send("http://localhost:8089/products", message);

I would suggest using a standard HTTP client such as Apache HTTP client etc. and set the method to POST/PUT or whatever method you need to use that expects a body.