cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Curran <daniel.cur...@dotech.com>
Subject Re: Return Error Code Based on Pipeline Content
Date Thu, 13 Apr 2006 17:13:56 GMT
It turns out that my transform was setup incorrectly.

Instead of throwing an exception for a status code of 200, I was getting 
the default status code of 200 back as I was returning well formatted XML.

I am now running up against a problem of correctly catching my thrown 
exception. When an exception is thrown at runtime via XSLT it is caught 
as an org.apache.cocoon.ProcessingException.

What this does is cause all of the different exceptions I am throwing to 
be treated as a ProcessingException by the sitemap.

<map:selector name="exception" 
src="org.apache.cocoon.selection.XPathExceptionSelector">
          <exception name="200" 
class="com.dotech.util.StatusCode200Exception"/>
          <exception name="201" 
class="com.dotech.util.StatusCode201Exception"/>
          <exception name="202" 
class="com.dotech.util.StatusCode202Exception"/>
          <exception name="404" 
class="com.dotech.util.StatusCode404Exception"/>
          <exception name="405" 
class="com.dotech.util.StatusCode405Exception"/>
          <exception name="406" 
class="com.dotech.util.StatusCode406Exception"/>
          <exception name="500" 
class="com.dotech.util.StatusCode500Exception"/>
          <exception name="501" 
class="com.dotech.util.StatusCode501Exception"/>
</map:selector>

None of the above selections end up matching.

I have been attemping to use the the java code for the exception I am 
throwing is -

public class ThrowException{
    public static void statusCode200() throws StatusCode200Exception {
       throw new  StatusCode200Exception("200");
    }

    ... other methods for the different status codes in the same pattern ...
}
class StatusCode200Exception extends Exception {
     public StatusCode200Exception(String error){
       super(error);
    }

    ... other status types in same pattern ...

}

My question now becomes how would I go about trapping the portion of the 
processing exception with a xpath expression.

I have tried something like -
<map:selector name="exception" 
src="org.apache.cocoon.selection.XPathExceptionSelector">
    <exception name="process" class="org.apache.cocoon.ProcessingException">
       <xpath name="200" test="getMessage=200"/>
    </exception>
</map:selector>

But I the test is not matching correctly. I must be doing something 
wrong with my xpath test. Any ideas?

Thanks,
Dan

Daniel Curran wrote:
> Since I need to make a choice between a number of different exceptions 
> to throw I used a xalan java extension, and then an exception selector 
> in the handle-errors section.
>
> This did the trick. In the transform I have defined 
> <exception:statusCode200/> which will cause Java to throw a 
> StatusCode200Exception which I can pick up in the handle-errors 
> section and return <map:serialize type="xml" status-code="200"/>
>
> Using the java extension allows me to easily define which error code 
> that I wish to throw and to pick based on an xsl:if or xsl:choose.
>
> Thanks for the advice, it worked out great,
> Dan
>
> Joerg Heinicke wrote:
>> On 10.04.2006 08:34, Bertrand Delacretaz wrote:
>>
>>> I don't think there is a standard way of throwing Exceptions from 
>>> XSLT code, but calling a small Java extension class from XSLT to 
>>> throw the Exception should do the trick, if you need to do this from 
>>> XSLT.
>>
>> I could not read from his message that he needs exceptions from XSLT, 
>> but there is an easy solution for it: <xsl:message terminate="yes"/>.
>>
>> Regards,
>>
>> Jörg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org



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


Mime
View raw message