You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lars Huttar <la...@sil.org> on 2003/12/30 21:50:41 UTC

how to throw (not propagate) an error?

Hi all,
I'm working on an application that uses user authentication/authorization.
Rather than using the Authentication Framework,
I'm handling auth/auth myself in the sitemap.

When a request is processed, the pipeline that matches the
request calls the authorization pipeline. The authorization
pipeline returns the requested data if the user is logged in
and authorized; otherwise, it returns data indicating an
authorization failure.

Problem: every pipeline that calls the authorization pipeline
has to know how to handle the two possible types of returned
data, and respond accordingly. The authorization pipeline
might even be called two or three levels deep in the call stack,
and all intervening pipelines have to know about the possible
failure condition and how to handle it.

This is a classic case where error handling helps: the authorization
pipeline should be able to throw an error condition, which is
caught by an error handler <map:handle-errors>, and none of
the other code needs to be able to handle error data instead of
the usual data.

But my problem is, how to throw my own error?
I see there is a "notify" generator,
http://cocoon.apache.org/2.1/userdocs/generators/error-generator.html
so I can invoke
  <map:generate type="notifying" />
somehow in my authorization pipeline when auth fails;
but how do I control what kind of error is generated?
And anyway, the documentation says this generator can only
be used within a <handle-errors> section, i.e. you can't
throw an error with it until an error condition already exists.

So to throw my own error, do I have to create an XSP page with
Java code in it to throw an error? If so could someone
give me an example?
Or is there some kind of error-throwing instruction for the sitemap?

Thanks,
Lars


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


Re: how to throw (not propagate) an error?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 06.01.2004 22:41, Lars Huttar wrote:

>>-----Original Message-----
>>From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de]
>>
>>The XSP code is transformed into a method generate() which throws the 
>>ProcessingException. So you don't have to care about it.
>>
>>Joerg
> 
> 
> Can you explain this?
> In what way do I not need to care about it? (And what is "it"?)

An XSP is transformed via XSLT to a Java file. The XSLT can be found at 
http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/src/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl 
(or at the same place in your Cocoon source you have anywhere on your 
disk of course). You can see, that most of the stuff goes into the method

public void generate() throws SAXException, IOException, ProcessingException

So "throw new ProcessingException()" simply works and "you don't have to 
care about it".

> Right now, I'm sometimes getting LanguageExceptions, saying that
> I have unreachable code:
>       this.contentHandler.endElement(
> I guess this is caused by my "throw" which precedes the endElement method
> call in the generated Java code.
> Can you suggest what I should do differently?

No, sorry, I can't help. You only can look at the generated Java code 
(must lying around in the working directory) and see what's gone wrong. 
Maybe you also look into the stylesheet to understand why it's gone 
wrong. And this exactly the problem I personally have with XSP: It 
doesn't really abstract from implementation details and you often came 
to such errors. A much more annoying issue is the handling of 
xsp:attribute's: http://nagoay.apache.org/bugzilla/show_bug.cgi?id=15841.

Joerg

>>On 30.12.2003 22:58, Lars Huttar wrote:
>>
>>
>>>Never mind, I think I got it... it was actually very easy
>>>once I realized that throwing an exception from Java code
>>>in an XSP page might not be hard. (Guess I have some
>>>Javaphobia. I don't want to get bogged down too much in
>>>the underlying details of Cocoon.)
>>>
>>>Anyway, I merely put the following in my (generated) XSP 
>>
>>action page:
>>
>>>            <xsp:logic>
>>>              <!-- Generate exception to be caught in sitemap -->
>>>              throw new ProcessingException("Authorization 
>>
>>failed.");
>>
>>>            </xsp:logic>
>>>
>>>I figured this would give me all sorts of errors such as
>>>not declaring/catching the exception... but it didn't; instead
>>>it just COMPLETELY WORKED!
>>>Blow me over.
>>>
>>>Lars


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


RE: how to throw (not propagate) an error?

Posted by Lars Huttar <la...@sil.org>.

> -----Original Message-----
> From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de]
> Sent: Monday, January 05, 2004 7:00 PM
> To: users@cocoon.apache.org
> Subject: Re: how to throw (not propagate) an error?
> 
> 
> The XSP code is transformed into a method generate() which throws the 
> ProcessingException. So you don't have to care about it.
> 
> Joerg

Can you explain this?
In what way do I not need to care about it? (And what is "it"?)

Right now, I'm sometimes getting LanguageExceptions, saying that
I have unreachable code:
      this.contentHandler.endElement(
I guess this is caused by my "throw" which precedes the endElement method
call in the generated Java code.
Can you suggest what I should do differently?

Thanks,
Lars

> On 30.12.2003 22:58, Lars Huttar wrote:
> 
> > Never mind, I think I got it... it was actually very easy
> > once I realized that throwing an exception from Java code
> > in an XSP page might not be hard. (Guess I have some
> > Javaphobia. I don't want to get bogged down too much in
> > the underlying details of Cocoon.)
> > 
> > Anyway, I merely put the following in my (generated) XSP 
> action page:
> >             <xsp:logic>
> >               <!-- Generate exception to be caught in sitemap -->
> >               throw new ProcessingException("Authorization 
> failed.");
> >             </xsp:logic>
> > 
> > I figured this would give me all sorts of errors such as
> > not declaring/catching the exception... but it didn't; instead
> > it just COMPLETELY WORKED!
> > Blow me over.
> > 
> > Lars
> > 
> > 
> > 
> >>-----Original Message-----
> >>From: Lars Huttar [mailto:lars_huttar@sil.org]
> >>Sent: Tuesday, December 30, 2003 2:51 PM
> >>To: Cocoon Users List (E-mail)
> >>Subject: how to throw (not propagate) an error?
> >>
> >>
> >>Hi all,
> >>I'm working on an application that uses user 
> >>authentication/authorization.
> >>Rather than using the Authentication Framework,
> >>I'm handling auth/auth myself in the sitemap.
> >>
> >>When a request is processed, the pipeline that matches the
> >>request calls the authorization pipeline. The authorization
> >>pipeline returns the requested data if the user is logged in
> >>and authorized; otherwise, it returns data indicating an
> >>authorization failure.
> >>
> >>Problem: every pipeline that calls the authorization pipeline
> >>has to know how to handle the two possible types of returned
> >>data, and respond accordingly. The authorization pipeline
> >>might even be called two or three levels deep in the call stack,
> >>and all intervening pipelines have to know about the possible
> >>failure condition and how to handle it.
> >>
> >>This is a classic case where error handling helps: the authorization
> >>pipeline should be able to throw an error condition, which is
> >>caught by an error handler <map:handle-errors>, and none of
> >>the other code needs to be able to handle error data instead of
> >>the usual data.
> >>
> >>But my problem is, how to throw my own error?
> >>I see there is a "notify" generator,
> >>http://cocoon.apache.org/2.1/userdocs/generators/error-gener
ator.html
>>so I can invoke
>>  <map:generate type="notifying" />
>>somehow in my authorization pipeline when auth fails;
>>but how do I control what kind of error is generated?
>>And anyway, the documentation says this generator can only
>>be used within a <handle-errors> section, i.e. you can't
>>throw an error with it until an error condition already exists.
>>
>>So to throw my own error, do I have to create an XSP page with
>>Java code in it to throw an error? If so could someone
>>give me an example?
>>Or is there some kind of error-throwing instruction for the sitemap?


---------------------------------------------------------------------
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


Re: how to throw (not propagate) an error?

Posted by Joerg Heinicke <jo...@gmx.de>.
The XSP code is transformed into a method generate() which throws the 
ProcessingException. So you don't have to care about it.

Joerg

On 30.12.2003 22:58, Lars Huttar wrote:

> Never mind, I think I got it... it was actually very easy
> once I realized that throwing an exception from Java code
> in an XSP page might not be hard. (Guess I have some
> Javaphobia. I don't want to get bogged down too much in
> the underlying details of Cocoon.)
> 
> Anyway, I merely put the following in my (generated) XSP action page:
>             <xsp:logic>
>               <!-- Generate exception to be caught in sitemap -->
>               throw new ProcessingException("Authorization failed.");
>             </xsp:logic>
> 
> I figured this would give me all sorts of errors such as
> not declaring/catching the exception... but it didn't; instead
> it just COMPLETELY WORKED!
> Blow me over.
> 
> Lars
> 
> 
> 
>>-----Original Message-----
>>From: Lars Huttar [mailto:lars_huttar@sil.org]
>>Sent: Tuesday, December 30, 2003 2:51 PM
>>To: Cocoon Users List (E-mail)
>>Subject: how to throw (not propagate) an error?
>>
>>
>>Hi all,
>>I'm working on an application that uses user 
>>authentication/authorization.
>>Rather than using the Authentication Framework,
>>I'm handling auth/auth myself in the sitemap.
>>
>>When a request is processed, the pipeline that matches the
>>request calls the authorization pipeline. The authorization
>>pipeline returns the requested data if the user is logged in
>>and authorized; otherwise, it returns data indicating an
>>authorization failure.
>>
>>Problem: every pipeline that calls the authorization pipeline
>>has to know how to handle the two possible types of returned
>>data, and respond accordingly. The authorization pipeline
>>might even be called two or three levels deep in the call stack,
>>and all intervening pipelines have to know about the possible
>>failure condition and how to handle it.
>>
>>This is a classic case where error handling helps: the authorization
>>pipeline should be able to throw an error condition, which is
>>caught by an error handler <map:handle-errors>, and none of
>>the other code needs to be able to handle error data instead of
>>the usual data.
>>
>>But my problem is, how to throw my own error?
>>I see there is a "notify" generator,
>>http://cocoon.apache.org/2.1/userdocs/generators/error-generator.html
>>so I can invoke
>>  <map:generate type="notifying" />
>>somehow in my authorization pipeline when auth fails;
>>but how do I control what kind of error is generated?
>>And anyway, the documentation says this generator can only
>>be used within a <handle-errors> section, i.e. you can't
>>throw an error with it until an error condition already exists.
>>
>>So to throw my own error, do I have to create an XSP page with
>>Java code in it to throw an error? If so could someone
>>give me an example?
>>Or is there some kind of error-throwing instruction for the sitemap?


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


RE: how to throw (not propagate) an error?

Posted by Lars Huttar <la...@sil.org>.
Never mind, I think I got it... it was actually very easy
once I realized that throwing an exception from Java code
in an XSP page might not be hard. (Guess I have some
Javaphobia. I don't want to get bogged down too much in
the underlying details of Cocoon.)

Anyway, I merely put the following in my (generated) XSP action page:
            <xsp:logic>
              <!-- Generate exception to be caught in sitemap -->
              throw new ProcessingException("Authorization failed.");
            </xsp:logic>

I figured this would give me all sorts of errors such as
not declaring/catching the exception... but it didn't; instead
it just COMPLETELY WORKED!
Blow me over.

Lars


> -----Original Message-----
> From: Lars Huttar [mailto:lars_huttar@sil.org]
> Sent: Tuesday, December 30, 2003 2:51 PM
> To: Cocoon Users List (E-mail)
> Subject: how to throw (not propagate) an error?
> 
> 
> Hi all,
> I'm working on an application that uses user 
> authentication/authorization.
> Rather than using the Authentication Framework,
> I'm handling auth/auth myself in the sitemap.
> 
> When a request is processed, the pipeline that matches the
> request calls the authorization pipeline. The authorization
> pipeline returns the requested data if the user is logged in
> and authorized; otherwise, it returns data indicating an
> authorization failure.
> 
> Problem: every pipeline that calls the authorization pipeline
> has to know how to handle the two possible types of returned
> data, and respond accordingly. The authorization pipeline
> might even be called two or three levels deep in the call stack,
> and all intervening pipelines have to know about the possible
> failure condition and how to handle it.
> 
> This is a classic case where error handling helps: the authorization
> pipeline should be able to throw an error condition, which is
> caught by an error handler <map:handle-errors>, and none of
> the other code needs to be able to handle error data instead of
> the usual data.
> 
> But my problem is, how to throw my own error?
> I see there is a "notify" generator,
> http://cocoon.apache.org/2.1/userdocs/generators/error-generator.html
> so I can invoke
>   <map:generate type="notifying" />
> somehow in my authorization pipeline when auth fails;
> but how do I control what kind of error is generated?
> And anyway, the documentation says this generator can only
> be used within a <handle-errors> section, i.e. you can't
> throw an error with it until an error condition already exists.
> 
> So to throw my own error, do I have to create an XSP page with
> Java code in it to throw an error? If so could someone
> give me an example?
> Or is there some kind of error-throwing instruction for the sitemap?
> 


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