Re: TapestryException in @Inject service method(), does it behave like component action exception?

2014-10-07 Thread Chris Mylonas
Cool, thanks for picking it up Kalle.  It was driving me nuts at the wrong  
times of the day and again before lunch :)


JIRA - https://issues.apache.org/jira/browse/TAP5-2396


On Wed, 08 Oct 2014 15:12:08 +1100, Kalle Korhonen  
 wrote:



On Tue, Oct 7, 2014 at 7:30 PM, Chris Mylonas  wrote:


Hi Tapestry Users,
help! :)
I am trying really hard to not get a TapestryException which I keep
getting for some custom handling that 5.4 includes.
I'm trying to get a custom FooterException thrown but it's always
OperationException...->...TapestryException..->..RenderQueueException
I have tried catching exceptions in setupRender as well and re-throwing  
my

custom exception.

At the end you'll see a stack trace - it always has a FooterException at
the bottom with a TapestryException one above it.  I want to get that
exception that TapestryException wraps around.
Am I suppose to just make my contributed request exception handler  
method
take the TapestryException and handle it further from there?   I will  
try

that now.
If the exception happens at the service layer, is it always wrapped in a
TapestryException, however when an exception occurs on an action within  
a

component, it bubbles up?



That looks like a bug - the handler should unwrap it to the specific
exception type. Unfortunately, the DefaultExceptionHandler doesn't
currently recognize TapestryException which is a clear oversight. Can you
open an issue and I'll fix it.

Kalle





Thanks for reading.



My contributed request exception handler,

AppModule.java

public void  
contributeRequestExceptionHandler(MappedConfiguration
Class> configuration) {
//configuration.add(TapestryException.class, Contact.class); //
this works but I don't want it
configuration.add(FooterException.class, About.class);
}



This is the service method I catch an exception and re-throw my custom
exception.

@Override
public Footer getById(Long id) {
Footer fetched = null;
try {
Query query = session.createQuery("from Footer where id =
:id");
query.setParameter("id", id);
query.setMaxResults(1);
fetched = (Footer) query.list().get(0);
} catch (NullPointerException | NoResultException |
IndexOutOfBoundsException npe) {
thrown new FooterException() ;
}
return fetched;
}


I've mucked around with this resorting to:

Layout.java

@Property
@Inject
@Symbol(SymbolConstants.APPLICATION_VERSION)
private String appVersion;

void onException() {
throw new RuntimeException(
"Layout threw this exception deliberately to make  
Tapestry

display the current exception report page."
+ " It's the page that displays exceptions you
didn't catch.");
}


Layout.tml


http://www.w3.org/1999/xhtml";
  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd";
  xmlns:p="tapestry:parameter"
  lang="en">





href="${context:img/favicon/favicon.png}"

/>
















FooterComponent.java

public class FooterComponent {

@Property
private Footer footer;

@Inject
private FooterService tapestryFooterService;

void setupRender() {
footer = tapestryFooterService.getById(new Long(1)); //force it
to get 1st item which doesn't exist
}

void onException() {
throw new RuntimeException(
"FooterComponent threw this exception deliberately to  
make

Tapestry display the current exception report page."
+ " It's the page that displays exceptions you didn't
catch.");
}
}


Index.java

public class Index
{
@Property
@Inject
@Symbol(SymbolConstants.TAPESTRY_VERSION)
private String tapestryVersion;

void onException() {
throw new RuntimeException(
"Index threw this exception deliberately to make  
Tapestry

display the current exception report page."
+ " It's the page that displays exceptions you
didn't catch.");
}
}





Stack trace:
13:17:16.185 [277461231@qtp-209021619-0] ERROR
t.render.org.opencsta.pages.Index - Render queue error in
SetupRender[Index:layout.footercomponent]: org.apache.tapestry5.ioc.
internal.util.TapestryException
org.apache.tapestry5.ioc.internal.util.TapestryException: null
at org.apache.tapestry5.internal.structure.
ComponentPageElementImpl$AbstractPhase.invoke(
ComponentPageElementImpl.java:155) ~[tapestry-core-5.4-beta-22.jar:na]
at org.apache.tapestry5.internal.structure.
ComponentPageElementImpl$SetupRenderPhase.render(
ComponentPageElementImpl.java:183) ~[tapestry-core-5.4-beta-22.jar:na]
at  
org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:79)

~[tapestry-core-5.4-beta-22.jar:na]
at org.apache.tapestry5.internal.services.PageRenderQueueImpl.
render(P

Re: TapestryException in @Inject service method(), does it behave like component action exception?

2014-10-07 Thread Kalle Korhonen
On Tue, Oct 7, 2014 at 7:30 PM, Chris Mylonas  wrote:

> Hi Tapestry Users,
> help! :)
> I am trying really hard to not get a TapestryException which I keep
> getting for some custom handling that 5.4 includes.
> I'm trying to get a custom FooterException thrown but it's always
> OperationException...->...TapestryException..->..RenderQueueException
> I have tried catching exceptions in setupRender as well and re-throwing my
> custom exception.
>
> At the end you'll see a stack trace - it always has a FooterException at
> the bottom with a TapestryException one above it.  I want to get that
> exception that TapestryException wraps around.
> Am I suppose to just make my contributed request exception handler method
> take the TapestryException and handle it further from there?   I will try
> that now.
> If the exception happens at the service layer, is it always wrapped in a
> TapestryException, however when an exception occurs on an action within a
> component, it bubbles up?
>

That looks like a bug - the handler should unwrap it to the specific
exception type. Unfortunately, the DefaultExceptionHandler doesn't
currently recognize TapestryException which is a clear oversight. Can you
open an issue and I'll fix it.

Kalle



>
> Thanks for reading.
>
>
>
> My contributed request exception handler,
>
> AppModule.java
>
> public void contributeRequestExceptionHandler(MappedConfiguration Class> configuration) {
> //configuration.add(TapestryException.class, Contact.class); //
> this works but I don't want it
> configuration.add(FooterException.class, About.class);
> }
>
>
>
> This is the service method I catch an exception and re-throw my custom
> exception.
>
> @Override
> public Footer getById(Long id) {
> Footer fetched = null;
> try {
> Query query = session.createQuery("from Footer where id =
> :id");
> query.setParameter("id", id);
> query.setMaxResults(1);
> fetched = (Footer) query.list().get(0);
> } catch (NullPointerException | NoResultException |
> IndexOutOfBoundsException npe) {
> thrown new FooterException() ;
> }
> return fetched;
> }
>
>
> I've mucked around with this resorting to:
>
> Layout.java
>
> @Property
> @Inject
> @Symbol(SymbolConstants.APPLICATION_VERSION)
> private String appVersion;
>
> void onException() {
> throw new RuntimeException(
> "Layout threw this exception deliberately to make Tapestry
> display the current exception report page."
> + " It's the page that displays exceptions you
> didn't catch.");
> }
>
>
> Layout.tml
>
> 
> http://www.w3.org/1999/xhtml";
>   xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd";
>   xmlns:p="tapestry:parameter"
>   lang="en">
>
> 
> 
> 
> 
>  href="${context:img/favicon/favicon.png}"
> />
> 
>
> 
>
>
>
> 
>
> 
>
> 
>
> 
> 
>
>
> FooterComponent.java
>
> public class FooterComponent {
>
> @Property
> private Footer footer;
>
> @Inject
> private FooterService tapestryFooterService;
>
> void setupRender() {
> footer = tapestryFooterService.getById(new Long(1)); //force it
> to get 1st item which doesn't exist
> }
>
> void onException() {
> throw new RuntimeException(
> "FooterComponent threw this exception deliberately to make
> Tapestry display the current exception report page."
> + " It's the page that displays exceptions you didn't
> catch.");
> }
> }
>
>
> Index.java
>
> public class Index
> {
> @Property
> @Inject
> @Symbol(SymbolConstants.TAPESTRY_VERSION)
> private String tapestryVersion;
>
> void onException() {
> throw new RuntimeException(
> "Index threw this exception deliberately to make Tapestry
> display the current exception report page."
> + " It's the page that displays exceptions you
> didn't catch.");
> }
> }
>
>
>
>
>
> Stack trace:
> 13:17:16.185 [277461231@qtp-209021619-0] ERROR
> t.render.org.opencsta.pages.Index - Render queue error in
> SetupRender[Index:layout.footercomponent]: org.apache.tapestry5.ioc.
> internal.util.TapestryException
> org.apache.tapestry5.ioc.internal.util.TapestryException: null
> at org.apache.tapestry5.internal.structure.
> ComponentPageElementImpl$AbstractPhase.invoke(
> ComponentPageElementImpl.java:155) ~[tapestry-core-5.4-beta-22.jar:na]
> at org.apache.tapestry5.internal.structure.
> ComponentPageElementImpl$SetupRenderPhase.render(
> ComponentPageElementImpl.java:183) ~[tapestry-core-5.4-beta-22.jar:na]
> at 
> org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:79)
> ~[tapestry-core-5.4-beta-22.jar:na]
> at org.apache.tapestry5.internal.services.PageRende