cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5104) JAX-RS not injecting contexts after resuming a suspended continuation
Date Tue, 09 Jul 2013 13:13:48 GMT

    [ https://issues.apache.org/jira/browse/CXF-5104?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13703237#comment-13703237
] 

Sergey Beryozkin commented on CXF-5104:
---------------------------------------

I had a test where the assumption was made that original Continuations would be persisted
during the initial request, so no context would be required on resuming the call and original
code was written with that assumption in mind.

This only affects the code depending on CXF continuations. It has been fixed now. Note, if
the request was suspended from a subresource instance then you'd still have to use PhaseInterceptorChain,
or switch to using AsyncResponse
                
> JAX-RS not injecting contexts after resuming a suspended continuation
> ---------------------------------------------------------------------
>
>                 Key: CXF-5104
>                 URL: https://issues.apache.org/jira/browse/CXF-5104
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>         Environment: CXF 2.7.5, MAC-OSX 10.7.5, Tomcat 7.0.41, Spring 3.0.7
>            Reporter: Sharath P
>              Labels: async, continuation, jax-rs
>         Attachments: AsyncResource.java, beans.xml, CXF-5104.patch, JsonBean.java, web.xml
>
>
> Problem:
> In order to use continuations, I have a 'MessageContext' injected into the JAX-RS resource
using @Context annotation.  When the request is initially handled,  JAX-RS properly sets the
thread-local MessageContext (ThreadLocalMessageContext) for that particular instance of thread,
and am able to retrieve the ContinuationProvider (in my case org.apache.cxf.transport.http.Servlet3ContinuationProvider)
from context.  Once I suspend the continuation and resume the same later, however, the thread-local
MessageContext instance is not being set and therefore am unable to retrieve the resumed continuation
(as  ThreadLocalMessageContext is null through which continuation provider has to be retrieved).

> Possible Fix:
> Looks like the cause of the problem is in org.apache.cxf.jaxrs.JAXRSInvoker.invoke(Exchange,
Object, Object) implementation, when a continuation is resumed, wasSuspended would be true
and there is a conditional block which injects params and contexts only when wasSuspended
= false.  Extracting the injection of the params and contexts out of this conditional block
would fix the issue as so:
> ******
> boolean wasSuspended = exchange.remove(REQUEST_WAS_SUSPENDED) != null;
>         
> if (!wasSuspended) {    
>     pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), inMessage);       
> }
> final boolean contextsAvailable = cri.contextsAvailable();
> final boolean paramsAvailable = cri.paramsAvailable();
> if (contextsAvailable || paramsAvailable) {
>     Object realResourceObject = ClassHelper.getRealObject(resourceObject);
>     if (paramsAvailable) {
>         JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
>     }
>     if (contextsAvailable) {
>         InjectionUtils.injectContexts(realResourceObject, cri, inMessage);
>     }
> }
> if (cri.isRoot()) {
>     ProviderInfo<?> appProvider = 
>         (ProviderInfo<?>)exchange.getEndpoint().get(Application.class.getName());
>     if (appProvider != null) {
>         InjectionUtils.injectContexts(appProvider.getProvider(),
>                                       appProvider,
>                                       inMessage);
>     }
> }
> ******

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message