Reputation: 3512
I have this "itch" I'm thinking in writing a filter that will intercept requests and extract the parameters then transform those parameters to attributes so that they arrive to the BusinessLogic (BO) layer as the type of objects that they should be(e.g Long, ObjectDTO, String, etc), currently the way I'm handling it is that the BO receives the request extracts the parameters, performs validation on nulls
and transforms them accordingly to the appropriate type. Is my new approach a more convenient one, I've read this The Essentials of Filters and also I would like to hear more uses of filters than those mentioned in the article.
The reason I thought of this is because when dealing with doGet
the user could omit parameters so I would use the filter to set them if missing, any opinions?
Upvotes: 1
Views: 287
Reputation: 269637
Many web frameworks do something like this.
For example, along with many other functions, the Struts filter determines what Action
is being invoked by the request. It uses reflection to determine the properties of the Action
, whether they are writable, and their type. It then processes the name of each parameter, and if it matches a property of the action, it tries to coerce the parameter value to an instance of the property's type. If that's successful, the Action
property is set with the resulting value. After the Action
has been configured properly, the filter invokes it.
The process may sound complicated, but really, I haven't done justice to the level of complexity. I'd suggest you check out what existing web frameworks can do for you before trying to write your own. Even if you have don't have a budget, and enjoy learning through bitter experience, studying other frameworks will help you re-invent a better framework of your own.
Upvotes: 2