You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by harrisgilliam <ha...@gmail.com> on 2013/04/03 21:52:54 UTC

RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

I am using Tomee+ 1.5.1 which bundles CXF 2.6.3.  I have configured
RequestDispatcherProvider as a provider..

dispatcherName = "jsp"
useClassNames = true
saveParametersAsAttributes = true

It correctly redirects the response object to a JSP for processing but none
of the query parameters are saved in the HttpServletRequest so they are not
available to the JSP.

According to http://cxf.apache.org/docs/jax-rs-redirection.html these
parameters should be available and as attributes when
saveParametersAsAttributes = true

Any ideas what wrong ?




--
View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 11/04/13 10:43, Sergey Beryozkin wrote:
> Hi
> On 11/04/13 02:00, harrisgilliam wrote:
>> Ok.. I figured it out... Query parameters who's value was set due to a
>> @DefaultValue annotation are not in the HttpServletRequest... which
>> now that
>> I think about it... makes sense.
>>
>> I still need those query parameters in my JSPs so I had to add a @Context
>> HttpServletRequest argument to the methods in my resource classes and
>> then
>> call setAttribute on the passed in HttpServletRequest manually.
> You may be able to simplify that a bit and update Message.QUERY_STRING
> property on a current Message (in case of a given query parameter
> missing) from a cxf provider (in CXF 2.6.x it is RequestHandler)
>>
>> Everything works as expected now.
>>
>> Thanks for your help :-)
>>
> Welcome, by the way I wonder if the runtime has to take care of
> providing the default values via related UriInfo methods or not, I do
> not see anything in the spec but it kind of makes sense, let me
> investigate a bit more.
>
I was reminded that UriInfo has to expose the actual request URI 
details, so we can not modify UriInfo output based on the @DefaultValue 
values.

Thanks, Sergey
>> ---Harris
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5726146.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>



Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 11/04/13 02:00, harrisgilliam wrote:
> Ok.. I figured it out... Query parameters who's value was set due to a
> @DefaultValue annotation are not in the HttpServletRequest... which now that
> I think about it... makes sense.
>
> I still need those query parameters in my JSPs so I had to add a @Context
> HttpServletRequest argument to the methods in my resource classes and then
> call setAttribute on the passed in HttpServletRequest manually.
You may be able to simplify that a bit and update Message.QUERY_STRING 
property on a current Message (in case of a given query parameter 
missing) from a cxf provider (in CXF 2.6.x it is RequestHandler)
>
> Everything works as expected now.
>
> Thanks for your help :-)
>
Welcome, by the way I wonder if the runtime has to take care of 
providing the default values via related UriInfo methods or not, I do 
not see anything in the spec but it kind of makes sense, let me 
investigate a bit more.

Thanks, Sergey

> ---Harris
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5726146.html
> Sent from the cxf-user mailing list archive at Nabble.com.



Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by harrisgilliam <ha...@gmail.com>.
Ok.. I figured it out... Query parameters who's value was set due to a
@DefaultValue annotation are not in the HttpServletRequest... which now that
I think about it... makes sense.

I still need those query parameters in my JSPs so I had to add a @Context
HttpServletRequest argument to the methods in my resource classes and then
call setAttribute on the passed in HttpServletRequest manually.

Everything works as expected now.

Thanks for your help :-)

---Harris




--
View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5726146.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 05/04/13 17:17, harrisgilliam wrote:
> It is not a form... the query parameters are available in the resource
> class.. ie: they are injected into the parameters of the methods annotated
> with @GET
>
> Is there a way to configure LoggingFeature without using Spring?  I have a
> requirement that I cannot use Spring.
>
> I am configuring the providers in my openejb-jar.xml file. Will this work?
>
> <?xml version="1.0"?>
> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
>      <pojo-deployment
> class-name="com.scholastic.education.s3.core.comm.director.webapp.DirectorResource">
>          <properties>
> cxf.jaxrs.providers=com.scholastic.education.s3.core.comm.common.jaxrs.StandardJSONProvider,com.scholastic.education.s3.core.comm.common.cxf.JSPProvider
>              cxf.jaxrs.features=logging
>          </properties>
>      </pojo-deployment>
> </openejb-jar>
>

I guess "cxf.jaxrs.features=org.apache.cxf.feature.LoggingFeature" or 
"cxf.jaxrs.in.interceptors=org.apache.cxf.interceptor.LoggingInInterceptor" 
should do it,

this can also be simplified with the annotations, adding 
"@org.apache.cxf.annotations.Logging" to the root resource class should do

> NOTE: com.scholastic.education.s3.core.comm.common.cxf.JSPProvider is
> RequestDispatcherProvider modified with extra debugging statements.
>
OK. FYI, I've double checked that the query parameters are available to 
response filters, example, see
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/FormatResponseHandler.java

I've just put a breakpoint there and it was hit, when using 
@MessageContext or directly @UriInfo.

Can you also do few more checks:
- are any other of UriInfo properties (those also set from the provider) 
available as HTTP attributes ?
- in your modified provider, do 
"System.out.println(org.apache.cxf.phase.PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage()
     .get(org.apache.cxf.message.Message.QUERY_STRING));" - if the query 
is available then it will be printed

Thanks, Sergey

>
> ---Harris
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5725910.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by harrisgilliam <ha...@gmail.com>.
It is not a form... the query parameters are available in the resource
class.. ie: they are injected into the parameters of the methods annotated
with @GET

Is there a way to configure LoggingFeature without using Spring?  I have a
requirement that I cannot use Spring.

I am configuring the providers in my openejb-jar.xml file. Will this work?

<?xml version="1.0"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
    <pojo-deployment
class-name="com.scholastic.education.s3.core.comm.director.webapp.DirectorResource">
        <properties>
cxf.jaxrs.providers=com.scholastic.education.s3.core.comm.common.jaxrs.StandardJSONProvider,com.scholastic.education.s3.core.comm.common.cxf.JSPProvider
            cxf.jaxrs.features=logging
        </properties>
    </pojo-deployment>
</openejb-jar>

NOTE: com.scholastic.education.s3.core.comm.common.cxf.JSPProvider is
RequestDispatcherProvider modified with extra debugging statements.


---Harris




--
View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5725910.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 04/04/13 18:39, harrisgilliam wrote:
> Hi,
>
> All of my query parameters are single valued.  I actually grabbed the source
> for RequestDispatcherProvider, added a bunch of debug logging statements and
> used my modified version.  What I see is that the call to
> UriInfo.getQueryParameters returns an empty MultivaluedMap
>
> For some reason my query params are not there :-/
>
> The code in RequestDispatcherProvider does as you say but there aren't any
> query parameters to save.
>
Is it a form payload that you are dealing with by any chance ? Can you 
please confirm the query parameters are even available, you can add 
LoggingFeature to jaxrs:features ?

Cheers, Sergey
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5725852.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by harrisgilliam <ha...@gmail.com>.
Hi,

All of my query parameters are single valued.  I actually grabbed the source
for RequestDispatcherProvider, added a bunch of debug logging statements and
used my modified version.  What I see is that the call to
UriInfo.getQueryParameters returns an empty MultivaluedMap

For some reason my query params are not there :-/

The code in RequestDispatcherProvider does as you say but there aren't any
query parameters to save.




--
View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789p5725852.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by Sergey Beryozkin <sb...@gmail.com>.
Actually - RequestDispatcherProvider does save all request parameters as 
HTTP attributes, except that when it saves them as attributes it tries 
to be smart and if a query has more than a single value it appends an 
"Array" suffix to the attribute name, example, if we have
?a=a1

then the provider does request.setAttribute("a", "a1")

and in case of

?a=a1&a=a2

it does

request.setAttribute("aArray", new String[]{"a1", "a2"})

It does it only for query and matrix parameters, I think this in itself 
has to be fixed and the multivalued URI parameters should always have 
their values saved as String[], to be consistent with the fact that in 
case of HTTP parameters, getParametersMap returns a Map with String[] values

Do you have single or multi-value query parameters ? In the former case 
it should work - in the latter too - though the current convention of 
needs to be dropped and the code fixed as suggested above

Cheers, Sergey

> Hi
> On 03/04/13 22:52, harrisgilliam wrote:
>> I am using Tomee+ 1.5.1 which bundles CXF 2.6.3. I have configured
>> RequestDispatcherProvider as a provider..
>>
>> dispatcherName = "jsp"
>> useClassNames = true
>> saveParametersAsAttributes = true
>>
>> It correctly redirects the response object to a JSP for processing but
>> none
>> of the query parameters are saved in the HttpServletRequest so they
>> are not
>> available to the JSP.
>>
>> According to http://cxf.apache.org/docs/jax-rs-redirection.html these
>> parameters should be available and as attributes when
>> saveParametersAsAttributes = true
>>
>> Any ideas what wrong ?
>>
> This is a bug - I can see they are still saved as HTTP parameters - I'll
> get that fixed, please watch
> https://issues.apache.org/jira/browse/CXF-4944
>
> Thanks, Sergey
>
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: RequestDispatcherProvider not saving QueryParameters in HttpServletRequest

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 03/04/13 22:52, harrisgilliam wrote:
> I am using Tomee+ 1.5.1 which bundles CXF 2.6.3.  I have configured
> RequestDispatcherProvider as a provider..
>
> dispatcherName = "jsp"
> useClassNames = true
> saveParametersAsAttributes = true
>
> It correctly redirects the response object to a JSP for processing but none
> of the query parameters are saved in the HttpServletRequest so they are not
> available to the JSP.
>
> According to http://cxf.apache.org/docs/jax-rs-redirection.html these
> parameters should be available and as attributes when
> saveParametersAsAttributes = true
>
> Any ideas what wrong ?
>
This is a bug - I can see they are still saved as HTTP parameters - I'll 
get that fixed, please watch
https://issues.apache.org/jira/browse/CXF-4944

Thanks, Sergey

>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RequestDispatcherProvider-not-saving-QueryParameters-in-HttpServletRequest-tp5725789.html
> Sent from the cxf-user mailing list archive at Nabble.com.