1. Create a class ErrorCode that will handle the error status and error
message
2. Implement an ErrorCodeResultProcessor

public class ErrorCodeResultProcessor implements
                ComponentEventResultProcessor<ErrorCode> {

        private final Response response;

        public ErrorCodeResultProcessor(Response response) {
                this.response = response;
        }

        public void processResultValue(ErrorCode value) throws IOException {
                if (value != null) {
                        this.response.sendError(value.getStatus(),
value.getMessage());
                }
        }

}

3. Add your processor to the list by contributing to
ComponentEventResultProcessor service

        public void contributeComponentEventResultProcessor(
                        @Traditional @ComponentInstanceProcessor
ComponentEventResultProcessor componentInstanceProcessor,
                        MappedConfiguration<Class,
ComponentEventResultProcessor> configuration) {

                configuration.addInstance(ErrorCode.class,
ErrorCodeResultProcessor.class);
        }

Now you can return an ErrorCode instance from you activation method, and it
should work as expected.

Regards
Christophe.

2009/10/7 Kalle Korhonen <kalle.o.korho...@gmail.com>

> On Wed, Oct 7, 2009 at 9:17 AM, cordenier christophe
> <christophe.corden...@gmail.com> wrote:
> > Thanks, but i didn't look that way because of what found in the Tapestry
> > documentation. I mean 'vestigal' like deprecated :)
> > I will have a try.
> > tapestry.start-page-name The logical name of the start page, the page
> that
> > is rendered for the *root URL*. This is normally "start". This
> functionality
> > is vestigal: it has been superceded by the use of Index pages.Christophe.
>
> Yes - certainly an area where documentation could be improved. I think
> Howard has a blog post on this (yes.. at
> http://tapestryjava.blogspot.com/2008/02/tapestry-5-index-pages.html)
> and I think the semantics between Start and Index were
> semi-unintentional. Nevertheless you can use it to your advantage, and
> since it's there maybe the simplest thing to do is to just document it
> properly.
>
> Kalle
>
>
> > 2009/10/7 Kalle Korhonen <kalle.o.korho...@gmail.com>
> >
> >> On Wed, Oct 7, 2009 at 1:24 AM, cordenier christophe
> >> <christophe.corden...@gmail.com> wrote:
> >> > Does it mean that since we have an index page in our application, 404
> >> will
> >> > never be thrown automatically ?
> >>
> >> There's a different between Start and Index page. Start page handles a
> >> request to context path only, but Index handles is sort of a catch all
> >> (try it: if you have a Start page, your application will return 404s
> >> for non-existent urls). Personally, I use a Start page for the root of
> >> the context, but Index pages for sub-folders.
> >>
> >> Kalle
> >>
> >> >
> >> > Christophe.
> >> >
> >> > 2009/10/6 Kalle Korhonen <kalle.o.korho...@gmail.com>
> >> >
> >> >> Don't think I can help you much, but I can verify the same sendError
> >> >> and error configurations work for me on Tomcat 5.5 (haven't tried on
> >> >> Tomcat 6).
> >> >>
> >> >> Kalle
> >> >>
> >> >>
> >> >> On Tue, Oct 6, 2009 at 3:05 AM, Jan Jirout <jjir...@indracompany.com
> >
> >> >> wrote:
> >> >> > Hi All,
> >> >> >
> >> >> > I'm playing some time with t5. I have meet simple problem. I hope
> that
> >> >> it's
> >> >> > not my fault.
> >> >> >
> >> >> > So.
> >> >> >
> >> >> > I would like to handle "Error 404" in my application so I have in
> >> >> web.xml:
> >> >> >
> >> >> >        <filter-mapping>
> >> >> >                <filter-name>app</filter-name>
> >> >> >                <url-pattern>/*</url-pattern>
> >> >> >                <dispatcher>REQUEST</dispatcher>
> >> >> >                <dispatcher>ERROR</dispatcher>
> >> >> >        </filter-mapping>
> >> >> >
> >> >> >        <error-page>
> >> >> >                <error-code>404</error-code>
> >> >> >                <location>/error404</location>
> >> >> >        </error-page>
> >> >> >
> >> >> >
> >> >> > My Index.java is:
> >> >> >
> >> >> >
> >> >> >    void onActivate(final String pageUrl) throws IOException {
> >> >> >        if (isKnownPage(pageUrl)) {
> >> >> >            //show page
> >> >> >        } else {
> >> >> >             response.sendError(404, null);
> >> >> >        }
> >> >> >    }
> >> >> >
> >> >> > If I access page "/hello"  then pageUrl property is "hello". If
> there
> >> is
> >> >> > page /hello then this page is normally processed. If I sendError
> then
> >> >> page
> >> >> > error404 should be shown. This Error page exists. So when I access
> >> /blah
> >> >> > then /error404 page is shown. It works fine with jetty. But it
> doesn't
> >> >> work
> >> >> > with tomcat 6.
> >> >> >
> >> >> > I have tried to debug it, and it seems to me, that information
> about
> >> >> content
> >> >> > type is lost. In class BufferedGZipOutputStream is already
> information
> >> >> about
> >> >> > content type lost but in class PageResponseRendererImpl is still
> >> present.
> >> >> >
> >> >> > thanks for help
> >> >> >
> >> >> > Jan
> >> >> >
> >> >> >
> >> >> >
> >> >> > Here is my stack trace:
> >> >> > SEVERE: Servlet.service() for servlet default threw exception
> >> >> > java.lang.NullPointerException
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.ResponseCompressionAnalyzerImpl.isCompressable(ResponseCompressionAnalyzerImpl.java:65)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $ResponseCompressionAnalyzer_1241954ff2c.isCompressable($ResponseCompressionAnalyzer_1241954ff2c.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.openResponseOutputStream(BufferedGZipOutputStream.java:77)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.checkForCutover(BufferedGZipOutputStream.java:70)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.write(BufferedGZipOutputStream.java:116)
> >> >> >        at
> sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
> >> >> >        at
> sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:263)
> >> >> >        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
> >> >> >        at
> >> java.io.OutputStreamWriter.write(OutputStreamWriter.java:190)
> >> >> >        at
> java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
> >> >> >        at java.io.BufferedWriter.write(BufferedWriter.java:212)
> >> >> >        at java.io.PrintWriter.write(PrintWriter.java:412)
> >> >> >        at java.io.PrintWriter.write(PrintWriter.java:429)
> >> >> >        at java.io.PrintWriter.print(PrintWriter.java:559)
> >> >> >        at org.apache.tapestry5.dom.Text.toMarkup(Text.java:59)
> >> >> >        at
> >> >> > org.apache.tapestry5.dom.Element.writeChildMarkup(Element.java:840)
> >> >> >        at
> org.apache.tapestry5.dom.Element.toMarkup(Element.java:356)
> >> >> >        at
> >> >> > org.apache.tapestry5.dom.Element.writeChildMarkup(Element.java:840)
> >> >> >        at
> org.apache.tapestry5.dom.Element.toMarkup(Element.java:356)
> >> >> >        at
> >> >> > org.apache.tapestry5.dom.Element.writeChildMarkup(Element.java:840)
> >> >> >        at
> org.apache.tapestry5.dom.Element.toMarkup(Element.java:356)
> >> >> >        at
> >> >> > org.apache.tapestry5.dom.Element.writeChildMarkup(Element.java:840)
> >> >> >        at
> org.apache.tapestry5.dom.Element.toMarkup(Element.java:356)
> >> >> >        at
> >> >> > org.apache.tapestry5.dom.Element.writeChildMarkup(Element.java:840)
> >> >> >        at
> org.apache.tapestry5.dom.Element.toMarkup(Element.java:356)
> >> >> >        at
> >> org.apache.tapestry5.dom.Document.toMarkup(Document.java:163)
> >> >> >        at org.apache.tapestry5.dom.Node.toMarkup(Node.java:80)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.MarkupWriterImpl.toMarkup(MarkupWriterImpl.java:57)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.PageResponseRendererImpl.renderPageResponse(PageResponseRendererImpl.java:67)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $PageResponseRenderer_1241954ff57.renderPageResponse($PageResponseRenderer_1241954ff57.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.DefaultRequestExceptionHandler.handleRequestException(DefaultRequestExceptionHandler.java:77)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $RequestExceptionHandler_1241954ff38.handleRequestException($RequestExceptionHandler_1241954ff38.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:42)
> >> >> >        at
> >> >> >
> $RequestHandler_1241954ff3a.service($RequestHandler_1241954ff3a.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778)
> >> >> >        at
> >> >> >
> $RequestHandler_1241954ff3a.service($RequestHandler_1241954ff3a.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767)
> >> >> >        at
> >> >> >
> $RequestHandler_1241954ff3a.service($RequestHandler_1241954ff3a.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85)
> >> >> >        at
> >> >> >
> $RequestHandler_1241954ff3a.service($RequestHandler_1241954ff3a.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
> >> >> >        at
> >> >> >
> $RequestHandler_1241954ff3a.service($RequestHandler_1241954ff3a.java)
> >> >> >        at
> >> >> >
> $RequestHandler_1241954ff2f.service($RequestHandler_1241954ff2f.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.upload.internal.services.MultipartServletRequestFilter.service(MultipartServletRequestFilter.java:44)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $HttpServletRequestHandler_1241954ff31.service($HttpServletRequestHandler_1241954ff31.java)
> >> >> >        at
> >> >> >
> >>
> org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $HttpServletRequestHandler_1241954ff31.service($HttpServletRequestHandler_1241954ff31.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $HttpServletRequestFilter_1241954ff2d.service($HttpServletRequestFilter_1241954ff2d.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $HttpServletRequestHandler_1241954ff31.service($HttpServletRequestHandler_1241954ff31.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $HttpServletRequestHandler_1241954ff31.service($HttpServletRequestHandler_1241954ff31.java)
> >> >> >        at
> >> >> >
> >> >>
> >>
> $HttpServletRequestHandler_1241954ff2b.service($HttpServletRequestHandler_1241954ff2b.java)
> >> >> >        at
> >> >> >
> org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
> >> >> >        at
> >> >> >
> >> >>
> >>
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
> >> >> >        at
> >> >> >
> >> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
> >> >> >        at java.lang.Thread.run(Thread.java:619)
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> >> >> For additional commands, e-mail: users-h...@tapestry.apache.org
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> >> For additional commands, e-mail: users-h...@tapestry.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to