[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tapestry-user
Subject:    Re: Request Filter with ApplicationStateManager
From:       Peter Stavrinides <p.stavrinides () albourne ! com>
Date:       2007-12-05 15:21:38
Message-ID: 4756C202.40500 () albourne ! com
[Download RAW message or body]

Hi Richard,

Thanks a lot for your response! on your first point, I have tried this 
with no luck... so your second observation may be more likely,  although 
the documentation just leaves me with more questions, i'm not convinced 
that the state manager should ever turn up null, but it's not a big deal 
I will simply avoid the RequestFilter.

Thanks again,
Peter

Richard Kirby wrote:
> Hi Peter,
> 
> My guess is that for a RequestFilter, you need to ensure that your 
> filter is contributed after the default Tap5 filter that wires up the 
> HttpServletRequest object to the Tap5 Request object (which is what is 
> causing the NPE). However, I think on reading the RequestHandler 
> pipeline section of 
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/request.html 
> that this is probably done as the final step in the pipeline (ie the 
> terminator) before passing onto the MasterDispatcher service that 
> processes the Dispatcher pipeline. In other words, you can't do what 
> you want to do.
> 
> Not done any Tap5 coding yet so I may be wrong but hopefully I have 
> given you a pointer.
> 
> Cheers
> 
> Richard
> 
> Peter Stavrinides wrote:
> > Hi,
> > 
> > Perhaps I haven't phrased this question quite right since I didn't 
> > get a response... Let me try it again.
> > 
> > What I have is two contributions, a RequestFilter and a Dispatcher 
> > (the code is just about identicle) both services have a dependancy on 
> > the ApplicationStateManager, so I wire it by injecting it via the 
> > constructor:
> > 
> > //contribution
> > public void 
> > contributeMasterDispatcher(OrderedConfiguration<Dispatcher> 
> > configuration,
> > @InjectService("AccessController") Dispatcher 
> > accessController) {
> > configuration.add("AccessController", accessController, 
> > "before:PageRender");
> > }
> > 
> > //constructor
> > public AccessController(ApplicationStateManager asm){
> > this.asm_ = asm;
> > }
> > 
> > The Dispatcher seems to work perfectly, this simple test:
> > 
> > if(asm_.exists(UserAsoObject.class))
> > 
> > returns true/false, my state manager is working, however for the 
> > RequestFilter, with virtually identical code, the same test returns a 
> > NPE instead. I just wan't to understand where I am going wrong.
> > 
> > Thanks again,
> > Peter
> > 
> > Peter Stavrinides wrote:
> > > Hi All,
> > > 
> > > I can get hold of the ApplicationStateManager using the Dispatcher 
> > > interface without a problem, however the same code fails using the 
> > > Tapestry RequestFilter interface?  specifically  
> > > *if(asm_.exists(**UserAsoObject.class)**)) *returns a NPE. Would 
> > > this be a bug or shouldn't I be using it here in this way?
> > > 
> > > public class AccessController implements RequestFilter {
> > > /* Our state manager. */
> > > private ApplicationStateManager asm_;
> > > 
> > > public AccessController(ApplicationStateManager asm){
> > > this.asm_ = asm;
> > > }
> > > 
> > > @Override
> > > public boolean service(Request request, Response response, 
> > > RequestHandler handler)
> > > throws IOException {
> > > *if(asm_.exists(UserAsoObject.class)) {*
> > > UserAsoObject userObject = 
> > > asm_.get(UserAsoObject.class);
> > > }
> > > return handler.service(request,response);
> > > }
> > > 
> > > 
> > > produced the following stack trace:
> > > 
> > > java.lang.NullPointerException
> > > at $Request_116a49796f3.getContextPath($Request_116a49796f3.java)
> > > at $Request_116a49796d5.getContextPath($Request_116a49796d5.java)
> > > at 
> > > org.apache.tapestry.internal.services.ClasspathAssetAliasManagerImpl.toClientURL(ClasspathAssetAliasManagerImpl.java:90) \
> > >  
> > > at 
> > > $ClasspathAssetAliasManager_116a4979724.toClientURL($ClasspathAssetAliasManager_116a4979724.java) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.ClasspathAssetFactory.buildClientURL(ClasspathAssetFactory.java:84) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.ClasspathAssetFactory.clientURL(ClasspathAssetFactory.java:59) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.ClasspathAssetFactory.access$000(ClasspathAssetFactory.java:33) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.ClasspathAssetFactory$1.toClientURL(ClasspathAssetFactory.java:102) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.PageRenderSupportImpl.addStylesheetLink(PageRenderSupportImpl.java:109) \
> > >  
> > > at 
> > > org.apache.tapestry.services.TapestryModule$17.renderMarkup(TapestryModule.java:1322) \
> > >  
> > > at 
> > > $MarkupRenderer_116a4979727.renderMarkup($MarkupRenderer_116a4979727.java) 
> > > 
> > > at 
> > > org.apache.tapestry.internal.services.PageMarkupRendererImpl.renderPageMarkup(PageMarkupRendererImpl.java:64) \
> > >  
> > > at 
> > > $PageMarkupRenderer_116a497971d.renderPageMarkup($PageMarkupRenderer_116a497971d.java) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.PageResponseRendererImpl.renderPageResponse(PageResponseRendererImpl.java:56) \
> > >  
> > > at 
> > > $PageResponseRenderer_116a49796f4.renderPageResponse($PageResponseRenderer_116a49796f4.java) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.DefaultRequestExceptionHandler.handleRequestException(DefaultRequestExceptionHandler.java:60) \
> > >  
> > > at 
> > > $RequestExceptionHandler_116a49796e7.handleRequestException($RequestExceptionHandler_116a49796e7.java) \
> > >  
> > > at 
> > > org.apache.tapestry.services.TapestryModule$2.service(TapestryModule.java:536) 
> > > 
> > > at 
> > > $RequestHandler_116a49796ec.service($RequestHandler_116a49796ec.java)
> > > at 
> > > org.apache.tapestry.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:79) \
> > >  
> > > at 
> > > $RequestHandler_116a49796ec.service($RequestHandler_116a49796ec.java)
> > > at 
> > > org.apache.tapestry.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:94) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:85) \
> > >  
> > > at 
> > > org.apache.tapestry.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:77) \
> > >  
> > > at 
> > > org.apache.tapestry.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:107) \
> > >  
> > > at 
> > > $RequestHandler_116a49796ec.service($RequestHandler_116a49796ec.java)
> > > at 
> > > $RequestHandler_116a49796e4.service($RequestHandler_116a49796e4.java)
> > > at 
> > > org.apache.tapestry.services.TapestryModule$11.service(TapestryModule.java:921) \
> > >  
> > > at 
> > > $HttpServletRequestHandler_116a49796e3.service($HttpServletRequestHandler_116a49796e3.java) \
> > >  
> > > at 
> > > org.apache.tapestry.TapestryFilter.doFilter(TapestryFilter.java:164)
> > > at 
> > > org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089) \
> > >  
> > > at 
> > > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365) 
> > > 
> > > at 
> > > org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
> > > 
> > > at 
> > > org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) 
> > > 
> > > at 
> > > org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712) 
> > > 
> > > at 
> > > org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:406)
> > > at 
> > > org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211) \
> > >  
> > > at 
> > > org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) 
> > > 
> > > at 
> > > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) 
> > > 
> > > at org.mortbay.jetty.Server.handle(Server.java:295)
> > > at 
> > > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:503)
> > > at 
> > > org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:827) \
> > >  
> > > at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:511)
> > > at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:210)
> > > at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:379)
> > > at 
> > > org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:361) 
> > > 
> > > at 
> > > org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442) \
> > >  
> > > 
> > > 
> > > Here is the contribution:
> > > /**
> > > public void 
> > > contributeRequestHandler(OrderedConfiguration<RequestFilter> 
> > > configuration,
> > > @InjectService("TimingFilter") RequestFilter filter,      
> > > @InjectService("AccessController") RequestFilter accessController) {
> > > configuration.add("Timing", filter);
> > > configuration.add("AccessController", accessController, 
> > > "before:PageRender");
> > > }
> > > 
> > > Kind regards,
> > > Peter
> > > 
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic