struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Balakrishnan, Vijay" <VBalakrish...@newedgenetworks.com>
Subject RE: Struts and Commons Chain
Date Mon, 08 Dec 2003 21:55:32 GMT
The Intercepting filter concept is what JBoss uses I think with their
interceptor stack with both pre and post processing.You can change the order
in which the Interceptors are processed by changing it in the jboss.xml
file.Since these interceptors are stateless, the values are stored in thread
context.They use the Interceptor interface.

Vijay

-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of Vic Cekvenich
Sent: Monday, December 08, 2003 5:16 AM
To: struts-user@jakarta.apache.org
Subject: Re: Struts and Commons Chain



> This is very interesting I think.
> .V
> 
> Hookom, Jacob wrote:
> 
>> I was looking at chain's implementation, instead of executing the 
>> commands
>> with the visitor pattern, wouldn't a more powerful/flexible method be to
>> implement it using a filter pattern?
>>
>> See:
>>
http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.

>>
>> html
>>
>>
>> Sample Chain:
>> CommandServletStart
>> CommandExceptionHandler
>> CommandStoreState
>> CommandExceptionThrower
>>
>> -- 
>>
>> CommandStart.execute(Context ctx, Chain chain) throws Exception
>> {
>>     ServletContext srvCtx = (ServletContext) ctx;
>>     String usrId = srvCtx.getRequestScope().getParameter("id"));
>>     String newName = srvCtx.getRequestScope().getParameter("name"));
>>
>>     // get user and save state
>>     User user = SomeService.getUser(usrId);
>>     String oldName = user.getName();
>>     
>>     // set new state and execute
>>     try
>>     {
>>         user.setName(newName);
>>         ctx.setAttribute("user", user);
>>         chain.executeNext(ctx);
>>     }
>>     catch (Exception e)
>>     {
>>         // on error, rollback change
>>         user.setName(oldName);
>>         throw e;
>>     }
>> }
>>
>> -- 
>>
>> CommandExceptionHandler.execute(Context ctx, Chain chain) throws 
>> Exception
>> {
>>     try
>>     {
>>         chain.executeNext(ctx);
>>     }
>>     catch (SQLException e)
>>     {
>>         chain.executeNext(ctx);
>>     }
>>     // let unhandled exceptions go up
>> }
>>
>> CommandExceptionThrower.execute(Context ctx, Chain chain) throws 
>> Exception
>> {
>>     throw new SQLException();
>> }
>>
>> With this, you would not have to change your inheritance to add behavior
>> (going from a command to a filter).  The given command would already know
>> best on how to handle itself and since it calls the next item in the 
>> chain,
>> we can also wrap the context to take care of situations where we want to
>> have listener type behavior.
>>
>> The chain could also allow for runtime manipulation by the commands, to
>> insert additional commands to handle errors.
>>
>> chain.insert("SomeCommand").insert("AnotherCommand).executeNext(ctx);
>>
>> --------
>> Jacob Hookom
>> Senior Programmer/Analyst
>> McKesson Medical-Surgical
>> Golden Valley, MN
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message