Mule flat file mapping: “com.mulesoft.flatfile.lexical.WriteException – effective length * is greater than * for component…” – alternative solution

This falls under the category “strange error messages” in Mule. Normaly you would think that the data you send is bigger than the longest allowed value, but in my case it was because I was trying to map a value from an array without setting a index

Tested in Anypoint Studio 7.11.1 and Mule 4.3

Testing a simple web app in Mule with JUnit

A simple JUnit test for when you just can’t remember the Mule JUnit testing syntax 😉

Mule flow
A Mule flow that takes a username as input and concatenates it with a “Hello”. The request is done by a GET call:

Flow code

       doc:name="HTTP Listener Configuration">
           value="#['Hello '+message.inboundProperties.'http.query.params'.username]" 
           doc:name="Set Payload">

Java test code:

import org.junit.Test;
import org.mule.DefaultMuleMessage;
import org.mule.api.MuleMessage;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;

import junit.framework.Assert;

public class MyTests extends FunctionalTestCase {
	public void testMyFlow() throws Exception {
        // Get the Mule Context
		MuleClient muleClient = muleContext.getClient();
        // Create an empty test Mule message
		DefaultMuleMessage message = 
                        new DefaultMuleMessage(null, muleContext);
        // Make a call to the tested web service
		MuleMessage responseMessage = muleClient.send(
        // Get response as a string
		String responsePayload = responseMessage.getPayloadAsString();
        // Assert response
		Assert.assertEquals("Hello Niklas", responsePayload);
	protected String[] getConfigFiles() {
         // Path to the Mule configuration file that is being tested
		return new String[]{"src/main/app/helloworld.xml"};


Tested on OSX 10.15.7, Mule 3.9.4, and JUnit 4.13

A simple chat application with javascript and ActiveMQ using STOMP messaging

Here is a small chat program that can be used for building a rich chat application, or if you just want a very simple chat program for your friends. It contains sending and receiving STOMP messages from an Apache ActiveMQ topic.

* Apace ActiveMQ server which can be found here: Usually no configuration needed. Just start the server (./activemq start) and everything should work ok
* Stomp.js. A helper script for handling the WebSocket communication between ActiveMQ and your javascript application. This script can be found here, courtesy of Jeff Mesnil and Mark Broadbent:


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>A simple ActiveMQ chat application</title>
    <script src="stomp.js"></script>
    <script src="index.js"></script>
    <textarea id="chat" rows="10" cols="35"></textarea>
    <br />
    <input id="message" size="40" type="text">
    <br />
    <button id="send" type="button" onclick="send()">Send</button>


// Setup websocket connection
const client = Stomp.client("ws://localhost:61614/stomp", "v11.stomp");
// Setup header options
const headers = {id: 'JUST.FCX', ack: 'client'};

// Connect to ActiveMQ (via websocket)
client.connect("admin", "admin", function () {
    // Setup subscription of topic (/topic/chat)
        function (message) {
            const msg = message.body;
            // Add message to textarea
            document.getElementById("chat").value += msg + "\n";
            // Acknowledge the message
        }, headers);

function send() {
    const message = document.getElementById("message");
    // Send message to topic (/topic/chat)
    client.send("/topic/chat", {}, message.value);
    // Reset input field
    message.value = "";

Tested on OSX 10.15.7 and Apache ActiveMQ v5.16.3