views:

24

answers:

1

I implemented the Message interface to include some headers for use with a HeaderValueRouter on server side.

Within one VM this works (tested using a filter between two endpoints).

But if I send the message through HttpOutboundGatway my fields get stripped (not included in the HttpRequest). And therefor the routing information is lost on server side.

Am I not supposed to manipulate headers?

public class TaskMessage implements Message<String> {

    private MessageHeaders headers;
    private String payload;

    public TaskMessage(String taskId, String boxId, String payload) {
        super();
        this.taskId = taskId;
        this.boxId = boxId;
        this.payload = payload;
        StringMessage sm = new StringMessage(payload);
        Set<String> keySet = sm.getHeaders().keySet();

        HashMap<String, Object> map = new HashMap<String, Object>();
        for (String key : keySet) {
            map.put(key, sm.getHeaders().get(key));
        }
        map.put("taskId", taskId);
        map.put("boxId", boxId);
        headers = new MessageHeaders(map);
    }
    @Override
    public MessageHeaders getHeaders() {
        return headers;
    }

    @Override
    public String getPayload() {
        return payload;
    }
}

EDIT:

The version is 1.0.3

The part of my configuration is:

<si:inbound-channel-adapter ref="jdbcInputAdapter" method="fetchData" channel="msgChannel">
    <si:poller max-messages-per-poll="1"> 
        <si:interval-trigger interval="5000" />
    </si:poller>
</si:inbound-channel-adapter>

<http:outbound-gateway id="httpChannelAdapter" auto-startup="true" request-timeout="1000" request-channel="msgChannel" reply-channel="replyChannel" default-url="http://localhost:8080/taskserver/gateway"/&gt;
+1  A: 

The version you are using does not support (custom) header serialization. The solution would be to craft a request that contains all the information needed and pass it along as the payload. The new REST based http support in version 2.0.x does support header mapping and also exposes extension points for converting messages (including headers).

As a side note, it is quite uncommon to have to implement a custom Message, so instead of doing that I'd create a message using MessageBuilder

MessageBuilder.withPayload("foo").setHeader("taskId", "someTaskId").build();

In general not all headers can be transferred with all protocols, so if you want to use a distributed system it is usually more flexible to pack all information you need to send into the payload.

iwein
@iwein I added version and config (partial) to the question. I would like to know why the headers are stripped from my message. Thanks in advance.
stacker
answer updated accordingly
iwein
@iwein thanks a lot, I changed the pay load to o map of string,string this works now
stacker