1

I need to add a prefix to every message that goes out. I can do it using a method, but would like to just have the transformer handle it.

The problem is the message needs to be prefixed with control code characters that I can't really type out and then some additional text.

For example:

private final static char EOT = (char) 4;
private final static char STX = (char) 2;
private final static char ETX = (char) 3;
private final static String additionalText = "          -0000 9305";

See: http://en.wikipedia.org/wiki/C0_and_C1_control_codes

Then the message would be prefixed with:

EOT + additionalText + ETX;

However, I can't find how to typecast the control codes in a SpEL expression used in the transformer:

<int:transformer
    id="prefixAdder"
    input-channel="initialMessage"
    output-channel="prefixAdded"
    expression="'#{(char) 4}' + '          -0000 9305' + '#{(char) 3}' + payload"/>
4

1 に答える 1

0

SpEL はそれを直接サポートしていません。<bean/>制御データの前に を追加して、 を使用できますexpression="@prefixer.prefixPreamble(payload)"

public class Prefixer {
    public String prefix(String payload) {
        return prefix + payload;
    }
}
于 2013-01-24T15:51:07.970 に答える