You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Paul Wilton <Pa...@bbc.com> on 2010/04/14 16:05:27 UTC

#fragment being stripped from QueryParam that is a uri in JAX-RS method

Hi 
I am experiencing some unexpected behaviour when mapping a String
@QueryParam where the QueryParam is a URI with a #fragment at the end.

Given the method signature :

    @GET
    @Path("/resource")
    public Response getResource(@QueryParam("uri")String resourceURI) 

if the request is:
GET /resource?uri=http://some.resource.uri/blah#thing

The value set in the resourceURI String variable is
"http://some.resource.uri/blah"  not "
http://some.resource.uri/blah#thing"

This also occurs if an additional query param is passed in the request,
e.g.
GET /resource?uri=http://some.resource.uri/blah#thing&hello=1

I am using CXF 2.2.7   - is this a bug ?  I can see no valid reason for
stripping the uri #fragment

Thanks
Paul






This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
 
Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this

This e-mail has been sent by one of the following wholly-owned subsidiaries of the BBC:
 
BBC Worldwide Limited, Registration Number: 1420028 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World News Limited, Registration Number: 04514407 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World Distribution Limited, Registration Number: 04514408, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ

 
 

RE: #fragment being stripped from QueryParam that is a uri in JAX-RS method

Posted by Paul Wilton <Pa...@bbc.com>.
Okay - I think this is an issue / bug
V2.2.7

In org.apache.cxf.transport.http.AbstractHTTPDestination.setupMessage() 
- line 322 :
inMessage.put(Message.QUERY_STRING, req.getQueryString());

HttpServletRequest.getQueryString() is called to put the query string into the message, that is propagated through the CXF stack

However the tomcat 6 and Jetty implementations of getQueryString() strip all characters after and including a "#" in the query string

Hence if a request has 
/blah?uri=http://some.uri/#thing&hello=world

The query string set in the message is only
uri=http://some.uri/

so both the uri fragment and any following query parameters are lost.

The use of getQueryString is thus application server dependant and cannot be relied upon to get the query string accurately

Big issue for me - as I am building a large semantic web, web service where many resource URIs being passed around have #fragments in them to indicate predicates and class types. 

Cheers
Paul




-----Original Message-----
From: Paul Wilton [mailto:Paul.Wilton@bbc.com] 
Sent: 14 April 2010 15:05
To: users@cxf.apache.org; Sergey Beryozkin
Subject: #fragment being stripped from QueryParam that is a uri in JAX-RS method

Hi 
I am experiencing some unexpected behaviour when mapping a String
@QueryParam where the QueryParam is a URI with a #fragment at the end.

Given the method signature :

    @GET
    @Path("/resource")
    public Response getResource(@QueryParam("uri")String resourceURI) 

if the request is:
GET /resource?uri=http://some.resource.uri/blah#thing

The value set in the resourceURI String variable is
"http://some.resource.uri/blah"  not "
http://some.resource.uri/blah#thing"

This also occurs if an additional query param is passed in the request,
e.g.
GET /resource?uri=http://some.resource.uri/blah#thing&hello=1

I am using CXF 2.2.7   - is this a bug ?  I can see no valid reason for
stripping the uri #fragment

Thanks
Paul






This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
 
Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this

This e-mail has been sent by one of the following wholly-owned subsidiaries of the BBC:
 
BBC Worldwide Limited, Registration Number: 1420028 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World News Limited, Registration Number: 04514407 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World Distribution Limited, Registration Number: 04514408, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ

 
 

RE: #fragment being stripped from QueryParam that is a uri in JAX-RS method

Posted by Paul Wilton <Pa...@bbc.com>.
Yes indeed
But it is somewhat ambiguous - "character and terminated by a number
sign ("#") character or by the end of the URI"
Also a pretty old RFC that the sem-web world and web services have
overtaken...

Encoding far from an ideal solution - especially when it comes to
testing RESTful apis

I am of the opinion the "or by the end of the URI" interpretation is
more contemporary - 



-----Original Message-----
From: Sergey Beryozkin [mailto:sberyozkin@gmail.com] 
Sent: 14 April 2010 16:31
To: users@cxf.apache.org
Subject: Re: #fragment being stripped from QueryParam that is a uri in
JAX-RS method

Hi Paul

I'm wondering can this text from [1] explain it :

"

 The query component is indicated by the first question
   mark ("?") character and terminated by a number sign ("#") character
   or by the end of the URI.

"

I think if you have a query value encoded then you'll get it properly
decoded and '#' preserved.
You might want to use CXF HttpUtils.urlEncode

hope it helps, Sergey

[1] http://tools.ietf.org/html/rfc3986#section-3.4

On Wed, Apr 14, 2010 at 3:05 PM, Paul Wilton <Pa...@bbc.com>
wrote:

> Hi
> I am experiencing some unexpected behaviour when mapping a String
> @QueryParam where the QueryParam is a URI with a #fragment at the end.
>
> Given the method signature :
>
>    @GET
>    @Path("/resource")
>    public Response getResource(@QueryParam("uri")String resourceURI)
>
> if the request is:
> GET /resource?uri=http://some.resource.uri/blah#thing
>
> The value set in the resourceURI String variable is
> "http://some.resource.uri/blah"  not "
> http://some.resource.uri/blah#thing"
>
> This also occurs if an additional query param is passed in the
request,
> e.g.
> GET /resource?uri=http://some.resource.uri/blah#thing&hello=1
>
> I am using CXF 2.2.7   - is this a bug ?  I can see no valid reason
for
> stripping the uri #fragment
>
> Thanks
> Paul
>
>
>
>
>
>
> This e-mail (and any attachments) is confidential and may contain
personal
> views which are not the views of the BBC unless specifically stated.
If you
> have received it in error, please delete it from your system. Do not
use,
> copy or disclose the information in any way nor act in reliance on it
and
> notify the sender immediately.
>
> Please note that the BBC monitors e-mails sent or received. Further
> communication will signify your consent to this
>
> This e-mail has been sent by one of the following wholly-owned
subsidiaries
> of the BBC:
>
> BBC Worldwide Limited, Registration Number: 1420028 England,
Registered
> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
> BBC World News Limited, Registration Number: 04514407 England,
Registered
> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
> BBC World Distribution Limited, Registration Number: 04514408,
Registered
> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
>
>
>
>

Re: #fragment being stripped from QueryParam that is a uri in JAX-RS method

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Paul

I'm wondering can this text from [1] explain it :

"

 The query component is indicated by the first question
   mark ("?") character and terminated by a number sign ("#") character
   or by the end of the URI.

"

I think if you have a query value encoded then you'll get it properly
decoded and '#' preserved.
You might want to use CXF HttpUtils.urlEncode

hope it helps, Sergey

[1] http://tools.ietf.org/html/rfc3986#section-3.4

On Wed, Apr 14, 2010 at 3:05 PM, Paul Wilton <Pa...@bbc.com> wrote:

> Hi
> I am experiencing some unexpected behaviour when mapping a String
> @QueryParam where the QueryParam is a URI with a #fragment at the end.
>
> Given the method signature :
>
>    @GET
>    @Path("/resource")
>    public Response getResource(@QueryParam("uri")String resourceURI)
>
> if the request is:
> GET /resource?uri=http://some.resource.uri/blah#thing
>
> The value set in the resourceURI String variable is
> "http://some.resource.uri/blah"  not "
> http://some.resource.uri/blah#thing"
>
> This also occurs if an additional query param is passed in the request,
> e.g.
> GET /resource?uri=http://some.resource.uri/blah#thing&hello=1
>
> I am using CXF 2.2.7   - is this a bug ?  I can see no valid reason for
> stripping the uri #fragment
>
> Thanks
> Paul
>
>
>
>
>
>
> This e-mail (and any attachments) is confidential and may contain personal
> views which are not the views of the BBC unless specifically stated. If you
> have received it in error, please delete it from your system. Do not use,
> copy or disclose the information in any way nor act in reliance on it and
> notify the sender immediately.
>
> Please note that the BBC monitors e-mails sent or received. Further
> communication will signify your consent to this
>
> This e-mail has been sent by one of the following wholly-owned subsidiaries
> of the BBC:
>
> BBC Worldwide Limited, Registration Number: 1420028 England, Registered
> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
> BBC World News Limited, Registration Number: 04514407 England, Registered
> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
> BBC World Distribution Limited, Registration Number: 04514408, Registered
> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
>
>
>
>