Servlet Filter Came To The Rescue

In my previous post I outlined a couple of limitations that Flex HTTPService class has in dealing with Restful style web services. After giving it some thought, I came up with a solution that will allow me to continue to use Flex with Restful style web services without changes to the backend. The core of the solution is the idea of intercepting the incoming request on the server side using Servlet filter and use the Decorator pattern to adapt the needs of the service Restful web services. The solution consists of the following parts:

  1. Servlet filter to intercept incoming Restful style web service requests
  2. Develop a custom HttpServletRequest wrapper class that converts information like method name or header from the request parameters into right format that the server side web service handlers require.
  3. Develop a custom HttpServletResponse wrapper to convert all status code to 200 so flex will be able to get to response body

The above solution is very specific to my application and the willingness to bend some rules in making Restful web services calls from the Flex front end. Basically each web service request will append a request parameter with an agreed upon name between client and the server. Only when this special request parameter is present, the the Servlet filter will trigger the usage of request wrapper and response wrapper. The other issue with status code is since my Restful web service APIs return an error message in an XML structure in the response body, which allows the Flex client to find out what’s wrong.

With this solution, I am able to continue to Flex to develop my application UI.

Happy flexing everyone.

This entry was posted in Flex, Java and tagged . Bookmark the permalink.

One Response to Servlet Filter Came To The Rescue

  1. Ivan Schneider says:

    Interesting post. I’m willing to implement a solution similar to yours, would it be possible to get access to the code you mentioned to serve as a starting point ?

Leave a Reply

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

You are commenting using your 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