WebORB : Passing headers from the Client to the Server

Passing custom headers from the client to the server is made very easy using RemoteObjects and WebORB for .NET.

1. Initially during the construction of the RemoteObject in the client-code, we add an eventlistener for the Invoke event on the RemoteObject:

this.service.addEventListener( InvokeEvent.INVOKE, ServiceDelegateCallManager.handleInvoke );

2. In the handler we add the header:

public static function handleInvoke( event:InvokeEvent ) : void
var message:AbstractMessage = event.message as AbstractMessage;
message.headers.MBUserID = User.current.userId;

3. On the server its really easy to retrieve the custom headers side by side with the default Flex DataServices headers. In the respective method called on the server we are now able to retrieve the added header with a mere 3 lines of code:

using Weborb; // to import ORBConstants
using Weborb.Util; // to import ThreadContext

Hashtable props = ThreadContext.getProperties();
Hashtable headers = (Hashtable)props[ ORBConstants.REQUEST_HEASDERS ];
String mbUserID = (String)headers[ “MBUserID” ]

Thanks to Mark Pillar from MidnightCoders for providing the insight in WebORB to do this.
If you are interested in reading more about Flex and .NET security, please check out Mark’s article on Adobe.com – its and excellent primer on this topic (http://www.adobe.com/devnet/flex/articles/net_security.html)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s