PDA

View Full Version : Howto reach AMFHeader in Interceptor?



GeHe
Sep 2nd, 2009, 05:07 AM
Hello,

the title says it all. I have registered an MessageInterceptor and try to get
the header out. But i can not reach them through the MessageProcessingContext context or Message inputMessage.
By debugging i noticed that in the MessageBrokerFilter they are in the ActionContext.requestMessage.requestHeaders. How can i get them in the Interceptor?


Regards
GeHe

GeHe
Sep 2nd, 2009, 08:32 AM
I also noticed, that outgoing header are not received, not set in the outgoing message?

jeremyg484
Sep 2nd, 2009, 05:42 PM
Can you provide more details as to what exactly isn't there that you are expecting? You should definitely be able to get to the headers through the Message interface.

GeHe
Sep 3rd, 2009, 03:57 AM
Thank you for response. I have written a testclient to try spring blazeds integration with headers.



import flex.messaging.io.amf.client.AMFConnection;
import junit.framework.TestCase;

public class TestBaseService extends TestCase {

public void testHelo() throws Exception {
AMFConnection connection = new AMFConnection();
connection.connect("myurl");
connection.addAmfHeader("key", "value");
Object result = connection.call("myservice.hello");
}
}


But in the interceptor



import org.springframework.flex.core.MessageInterceptor;
import org.springframework.flex.core.MessageProcessingCon text;

import flex.messaging.messages.Message;

public class FlexInterceptor implements MessageInterceptor {

@Override
public Message postProcess(MessageProcessingContext context, Message inputMessage,
Message outputMessage) {
outputMessage.setHeader("key_out", "value_out");
return outputMessage;
}

@Override
public Message preProcess(MessageProcessingContext context, Message inputMessage) {
// control incoming msgs
String header = (String) inputMessage.getHeader("key");

return inputMessage;
}

}


i do net geht the header "key" (and the set header "key_out" does not get out). When i debug just before the interceptor (flex.messaging.endpoints.amf.MessageBrokerFilter. invoke(final ActionContext context)) i can see the header in the context.requestMessage.requestHeaders.

Conclusion: I expected the header to retrieve by inputMessage.getHeader("key"); - it is there, but i do not get it.

ShaunakDesai
Nov 5th, 2009, 02:35 PM
I haven't seen any API method to get to a specific header yet. But, there is a getHeaders() method which returns a Map for the message headers. You should be able to then use the get("headerNameAsKey") to get the value of a specific message meader.

Code snippet:
inputMessage.getHeaders().get("key");

or... directly get the list of values and iterate through...

Collection headers = message.getHeaders().values();
for(Object header:headers) {
// read the header or do something
}

To set the header the method is :
inputMessage.setHeaders(Map map)