开发者

MessageHeaders get lost at HttpOutboundGateway

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;
  开发者_JAVA百科  }

    @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"/>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜