You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Tobia <to...@linux.it> on 2007/06/27 15:13:20 UTC

Calling map:handle-errors from flowscript

Hello

How can I invoke the default handler for, say, 404 Not Found errors from
my flowscript?

Sometimes I can only determine that a certain URL refers to a
non-existant resource from flowscript.  I'd like the user to see the
default error page configured in <map:handle-errors>

I've tried the following, but none of them seem to work:

	cocoon.sendStatus(404)
	cocoon.response.setStatus(404)
	cocoon.response.sendError(404)
	throw new Packages.java.io.FileNotFoundException()
	throw new Packages.org.apache.cocoon.ResourceNotFoundException("")

The problem with the (send|set)(Status|Error) is that they don't invoke
the exception handlers defined in the sitemap.  The problem with
throwing new exceptions is that they are wrapped in a JavaScriptException
and thus are reported as a 500 error, while I need a 404.

Any ideas?


Tobia

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


Re: Calling map:handle-errors from flowscript

Posted by Tobia Conforto <to...@linux.it>.
Joerg Heinicke wrote:
> Tobia Conforto wrote:
> > throw new Packages.org.apache.cocoon.ResourceNotFoundException("")
> >
> > produces the following Java stacktrace:
> >
> > org.mozilla.javascript.JavaScriptException
> > Caused by: org.mozilla.javascript.WrappedException
> > Caused by: org.apache.cocoon.ProcessingException
> > Caused by: org.mozilla.javascript.JavaScriptException
>
> This looks familiar: https://issues.apache.org/jira/browse/COCOON-1205.
> The exceptions are not kept, but swallowed. Can you confirm this?

It doesn't look like the same thing to me, but I'm not sure.


Tobia

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


Re: Calling map:handle-errors from flowscript

Posted by Joerg Heinicke <jo...@gmx.de>.
On 10.07.2007 12:49, Tobia Conforto wrote:

> It doesn't seem to work, or I can't get it to work.  Throwing a new
> ResourceNotFoundException produces the following Java stacktrace:
> 
> 	org.mozilla.javascript.JavaScriptException
> 	Caused by: org.mozilla.javascript.WrappedException
> 	Caused by: org.apache.cocoon.ProcessingException
> 	Caused by: org.mozilla.javascript.JavaScriptException

This looks familiar: https://issues.apache.org/jira/browse/COCOON-1205.
The exceptions are not kept, but swallowed. Can you confirm this?

Joerg

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


Re: Calling map:handle-errors from flowscript

Posted by Tobia Conforto <to...@linux.it>.
Joerg Heinicke wrote:
> Tobia wrote:
> > cocoon.sendStatus(404)
> > cocoon.response.setStatus(404)
> > cocoon.response.sendError(404)
> > throw new Packages.java.io.FileNotFoundException()
> > throw new Packages.org.apache.cocoon.ResourceNotFoundException("")
> >
> > The problem with the (send|set)(Status|Error) is that they don't
> > invoke the exception handlers defined in the sitemap.  The problem
> > with throwing new exceptions is that they are wrapped in a
> > JavaScriptException and thus are reported as a 500 error, while I
> > need a 404.
>
> Did you have a look at the documentation?
> It talks about "unrolling" an exception. Does this work?

It doesn't seem to work, or I can't get it to work.  Throwing a new
ResourceNotFoundException produces the following Java stacktrace:

	org.mozilla.javascript.JavaScriptException
	Caused by: org.mozilla.javascript.WrappedException
	Caused by: org.apache.cocoon.ProcessingException
	Caused by: org.mozilla.javascript.JavaScriptException

The exception selector is configured to unroll as much as possible, but
the JavaScriptException seems to be "unrollable".


Anyways, I solved the problem using the XPathExceptionSelector.

Flowscript:

	throw 'not-found'

Sitemap:

<selector name="exception" src="org.apache.cocoon.selection.XPathExceptionSelector">
  <exception name="not-found" class="org.apache.cocoon.ResourceNotFoundException"/>
  <exception name="flowscript" class="org.mozilla.javascript.JavaScriptException">
    <xpath name="not-found" test="starts-with(message, 'not-found ')"/>
  </exception>
  <exception class="java.lang.Throwable" unroll="true"/>
</selector>


Tobia

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


Re: Calling map:handle-errors from flowscript

Posted by Joerg Heinicke <jo...@gmx.de>.
On 27.06.2007 15:13, Tobia wrote:

> 	cocoon.sendStatus(404)
> 	cocoon.response.setStatus(404)
> 	cocoon.response.sendError(404)
> 	throw new Packages.java.io.FileNotFoundException()
> 	throw new Packages.org.apache.cocoon.ResourceNotFoundException("")
> 
> The problem with the (send|set)(Status|Error) is that they don't invoke
> the exception handlers defined in the sitemap.  The problem with
> throwing new exceptions is that they are wrapped in a JavaScriptException
> and thus are reported as a 500 error, while I need a 404.

Did you have a look at the documentation [1]? It talks about "unrolling" 
an exception. Does this work?

Joerg

[1] http://cocoon.apache.org/2.1/userdocs/concepts/errorhandling.html

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