You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by cuartz <ca...@gmail.com> on 2009/10/09 01:55:04 UTC

Tapestry5 IoC and Request problem

Hello everybody, i had a problem trying to use the tapestr5 IoC from tapestry
4 pages, its a big system whit tpaestry5 and tapestry 4 pages, when i call a
service that handles the request (org.apache.tapestry5.services.Request)
from tapestry5 pages everything is ok, but when i call this service from a
tapestry4 page i get a java.lang.RuntimeException, everithing is ok but when
the service call some method from the request i get this error.

i hope someone can help me, believe me i try a lot of diferent methods to
solve this but i simply cant. 


java.lang.NullPointerException
Stack Trace:

    *
org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:76)
    *
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
    *
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
    *
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
    *
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
    *
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
    *
org.apache.tapestry5.ioc.internal.services.PerThreadServiceCreator.createObject(PerThreadServiceCreator.java:48) 
-- 
View this message in context: http://www.nabble.com/Tapestry5-IoC-and-Request-problem-tp25813570p25813570.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry5 IoC and Request problem

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 09 Oct 2009 14:24:28 -0300, cuartz <ca...@gmail.com>  
escreveu:

> Thanks Thiago, let me see if i understand, so in my tapestry 4 page i  
> use the storeServletRequestResponse method to store them and then i call  
> my service?

I guess so.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Tapestry5 IoC and Request problem

Posted by cuartz <ca...@gmail.com>.
Thanks Thiago, let me see if i understand, so in my tapestry 4 page i use the
storeServletRequestResponse method to store them and then i call my service?
i guess im missing something here



Thiago H. de Paula Figueiredo wrote:
> 
> Em Thu, 08 Oct 2009 20:55:04 -0300, cuartz <ca...@gmail.com>  
> escreveu:
> 
>> Hello everybody,
> 
> Hi!
> 
>> i had a problem trying to use the tapestr5 IoC from tapestry 4 pages,  
>> its a big system whit tpaestry5 and tapestry 4 pages, when i call a  
>> service that handles the request (org.apache.tapestry5.services.Request)
>> from tapestry5 pages everything is ok, but when i call this service from  
>> a tapestry4 page i get a java.lang.RuntimeException, everithing is ok  
>> but when the service call some method from the request i get this error.
> 
> I guess this happens because Request is a shadow service: actually, when  
> you use an injected instance of it, you're calling  
> RequestGlobals.getRequest(). This method returns a Request instance set  
> during Tapestry 5 request processing. Whan a request is handled by  
> Tapestry 4, RequestGlobal, which is a perthread service, doesn't have the  
> Request set, then you have your exception. One possible solution is to  
> invoke RequestGlobals.storeRequestResponse(Request request, Response  
> response) yourself before Request is used.
> 
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tapestry5-IoC-and-Request-problem-tp25813570p25824956.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry5 IoC and Request problem

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 08 Oct 2009 20:55:04 -0300, cuartz <ca...@gmail.com>  
escreveu:

> Hello everybody,

Hi!

> i had a problem trying to use the tapestr5 IoC from tapestry 4 pages,  
> its a big system whit tpaestry5 and tapestry 4 pages, when i call a  
> service that handles the request (org.apache.tapestry5.services.Request)
> from tapestry5 pages everything is ok, but when i call this service from  
> a tapestry4 page i get a java.lang.RuntimeException, everithing is ok  
> but when the service call some method from the request i get this error.

I guess this happens because Request is a shadow service: actually, when  
you use an injected instance of it, you're calling  
RequestGlobals.getRequest(). This method returns a Request instance set  
during Tapestry 5 request processing. Whan a request is handled by  
Tapestry 4, RequestGlobal, which is a perthread service, doesn't have the  
Request set, then you have your exception. One possible solution is to  
invoke RequestGlobals.storeRequestResponse(Request request, Response  
response) yourself before Request is used.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Tapestry5 IoC and Request problem

Posted by cuartz <ca...@gmail.com>.
Still i have the same issue, maybe i wasnt clear or im to frustrated to think
clear and understend what happends, for exampe i have this code:

t5page.java------

@InjectService
MyService myService

Object OnActivate(){
   myService.getData();
}

t4page.java-------

void initialize(){
   MyService myservice = registry.getService(MyService.class);
   myService.getData();
}

myServiceImpl.java
private Request request;
public MyServiceImpl(Request request) {
    this.request=request
   
System.out.println("<<<<<<<<<<<<<<<<<<"+request.isRequestedSessionIdValid());//
<--- the system breaks when execute this line from the t4page.java
     }
public void getData(){
..... anything
}
}


the system is a little bit more complex than this, so maybe my mistake is on
appModule, tapestryfilter, Registry or somwhere else but supose everything
is ok, i want to know if this example should work, with Thiago's advice my
t4page look like this but still i have the same exception

t4page.java implements Thiago advice jej-------

void preInitialize() {
    RequestGlobals requestGlobals =
registry.getService(RequestGlobals.class);
    requestGlobals.storeServletRequestResponse(getRequest(), getResponse());
}
void initialize() {
   MyService myservice = registry.getService(MyService.class);
   myService.getData();
}





-- 
View this message in context: http://www.nabble.com/Tapestry5-IoC-and-Request-problem-tp25813570p25826840.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry5 IoC and Request problem

Posted by cuartz <ca...@gmail.com>.
Ok thanks, now i understand, unfortunately i cant change that parameter on
the services, but now that i know whats happends i can think on a solution,
if someone had a solution or an advice let me know.
Thanks Kalle and Thiago
-- 
View this message in context: http://www.nabble.com/Tapestry5-IoC-and-Request-problem-tp25813570p25861180.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry5 IoC and Request problem

Posted by Kalle Korhonen <ka...@gmail.com>.
That's because the injected request shadow in your service doesn't
have the real request backing it up since the request wasn't processed
by Tapestry5 but Tapestry 4. It's the same situation if call a service
from say a Quartz job - you never had the request in the first place.
You need to do it the old-fashioned way in this, i.e. pass in a
HttpServletRequest object as part of the arguments of a service
operation and use that request object in your service.

Kalle

On Thu, Oct 8, 2009 at 4:55 PM, cuartz <ca...@gmail.com> wrote:
>
> Hello everybody, i had a problem trying to use the tapestr5 IoC from tapestry
> 4 pages, its a big system whit tpaestry5 and tapestry 4 pages, when i call a
> service that handles the request (org.apache.tapestry5.services.Request)
> from tapestry5 pages everything is ok, but when i call this service from a
> tapestry4 page i get a java.lang.RuntimeException, everithing is ok but when
> the service call some method from the request i get this error.
>
> i hope someone can help me, believe me i try a lot of diferent methods to
> solve this but i simply cant.
>
>
> java.lang.NullPointerException
> Stack Trace:
>
>    *
> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:76)
>    *
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
>    *
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
>    *
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
>    *
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
>    *
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
>    *
> org.apache.tapestry5.ioc.internal.services.PerThreadServiceCreator.createObject(PerThreadServiceCreator.java:48)
> --
> View this message in context: http://www.nabble.com/Tapestry5-IoC-and-Request-problem-tp25813570p25813570.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Tapestry5 IoC and Request problem

Posted by cuartz <ca...@gmail.com>.
Someone who can help??? i accept any advice
-- 
View this message in context: http://www.nabble.com/Tapestry5-IoC-and-Request-problem-tp25813570p25859358.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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