You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Tarjei Huse <ta...@scanmine.com> on 2008/09/23 16:05:45 UTC

JAX-RS: How to encode an url in an url

Hi, I got a service where I want to expose a resource that is defined by
an url to a rssfeed, something like:

    @GET
    @Path("/{URL}/")
    public Subscriber getSubscriber(@PathParam("URL") String url) {
       ... do something with the url.
    }

Now, this does not work with normal urls, nor with urlencoded urls. Why
urlencoded values do not work I do not know, but for normal values, it
seems obvious (they contain '/'s). I've also tried base64 encoding the
urls, but that didn't work either because sometimes the base64 encoded
string contains slashes as well.

So, is there a "correct" way to do this or should I just map directly to
database ids or use request parameters whenever I need to deal with urls?

Kind regards,
Tarjei

Re: JAX-RS: How to encode an url in an url

Posted by Sergey Beryozkin <se...@iona.com>.
Tarjei,

Does what Eoghan suggested works for you ?
If not then it will have to be fixed in CXF

Cheers, Sergey

----- Original Message ----- 
From: "Eoghan Glynn" <eo...@iona.com>
To: <us...@cxf.apache.org>
Sent: Tuesday, September 23, 2008 3:12 PM
Subject: Re: JAX-RS: How to encode an url in an url



You've tried hex-encoding the URL forward-slashes (as "%2F"), or?

I'm using an old version of Jersey (0.6-ea) on another project, and I'm 
happily accepting hex-encoded URIs as part of a resource parameter.

Cheers,
Eoghan


Tarjei Huse wrote:
> Hi, I got a service where I want to expose a resource that is defined by
> an url to a rssfeed, something like:
> 
>     @GET
>     @Path("/{URL}/")
>     public Subscriber getSubscriber(@PathParam("URL") String url) {
>        ... do something with the url.
>     }
> 
> Now, this does not work with normal urls, nor with urlencoded urls. Why
> urlencoded values do not work I do not know, but for normal values, it
> seems obvious (they contain '/'s). I've also tried base64 encoding the
> urls, but that didn't work either because sometimes the base64 encoded
> string contains slashes as well.
> 
> So, is there a "correct" way to do this or should I just map directly to
> database ids or use request parameters whenever I need to deal with urls?
> 
> Kind regards,
> Tarjei

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAX-RS: How to encode an url in an url

Posted by Sergey Beryozkin <se...@iona.com>.
Thanks for opening the JIRA - I can't promise how fast I'll look at it but it'll definitely be fixed before the next 2.1.x release 
(will probably happen in about 2 weeks or so), alongside with the couple of other pending issues...

Cheers, Sergey

----- Original Message ----- 
From: "Tarjei Huse" <ta...@scanmine.com>
To: <us...@cxf.apache.org>
Sent: Wednesday, September 24, 2008 8:55 AM
Subject: Re: JAX-RS: How to encode an url in an url


> Eoghan Glynn wrote:
>> Tarjei Huse wrote:
>>> Eoghan Glynn wrote:
>>>> You've tried hex-encoding the URL forward-slashes (as "%2F"), or?
>>>>
>>>> I'm using an old version of Jersey (0.6-ea) on another project, and
>>>> I'm happily accepting hex-encoded URIs as part of a resource parameter.
>>> Lucky you :)
>>
>> Just giving a data point that suggests hex-encoding the embedded URL
>> probably /should/ work in CXF, as it does so in the reference
>> implementation of JAX-RS.
>>
>>> I tried:
>>> GET
>>> http://localhost:8080/service/newsletter/http%3A%2F%2Ftest.com%3Frss%3Doijoij
>>>
>>>
>>> For the service:
>>> @GET
>>>     @Path("/{URL}")
>>>     public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}
>>
>> Presumably you've annotated the resource class with
>> @Path("/newsletter"), or?
> Yes. The service responds if I use a non-hex-encoded value.
>
> I guess I'll have to file a bug on this.
>
> Kind regards,
> Tarjei
>>
>> /Eoghan
>>
>>> and got:
>>> <ns1:XMLFault>
>>> <ns1:faultstring>
>>> .No operation matching request path
>>> /newsletter/http://test.com?rss=oijoij/ is found, ContentType : */*,
>>> Accept :
>>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
>>> </ns1:faultstring>
>>> </ns1:XMLFault>
>>>
>>> I also tried to add @Encoded to the method like this:
>>>     @GET
>>>     @Path("/{URL}")
>>>     @Encoded
>>>     public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}
>>>
>>> But it didn't help. The fault comes from:
>>>     at
>>> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:195)
>>>
>>>     at
>>> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:65)
>>>
>>>     at
>>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
>>>
>>>
>>>
>>> Any tips?
>>>
>>> kind regards,
>>> Tarjei
>>>
>>>> Cheers,
>>>> Eoghan
>>>>
>>>>
>>>> Tarjei Huse wrote:
>>>>> Hi, I got a service where I want to expose a resource that is
>>>>> defined by
>>>>> an url to a rssfeed, something like:
>>>>>
>>>>>     @GET
>>>>>     @Path("/{URL}/")
>>>>>     public Subscriber getSubscriber(@PathParam("URL") String url) {
>>>>>        ... do something with the url.
>>>>>     }
>>>>>
>>>>> Now, this does not work with normal urls, nor with urlencoded urls.
>>>>> Why
>>>>> urlencoded values do not work I do not know, but for normal values, it
>>>>> seems obvious (they contain '/'s). I've also tried base64 encoding the
>>>>> urls, but that didn't work either because sometimes the base64 encoded
>>>>> string contains slashes as well.
>>>>>
>>>>> So, is there a "correct" way to do this or should I just map
>>>>> directly to
>>>>> database ids or use request parameters whenever I need to deal with
>>>>> urls?
>>>>>
>>>>> Kind regards,
>>>>> Tarjei
>>>> ----------------------------
>>>> IONA Technologies PLC (registered in Ireland)
>>>> Registered Number: 171387
>>>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
>>>> Ireland
>>
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland 

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAX-RS: How to encode an url in an url

Posted by Tarjei Huse <ta...@scanmine.com>.
Eoghan Glynn wrote:
> Tarjei Huse wrote:
>> Eoghan Glynn wrote:
>>> You've tried hex-encoding the URL forward-slashes (as "%2F"), or?
>>>
>>> I'm using an old version of Jersey (0.6-ea) on another project, and
>>> I'm happily accepting hex-encoded URIs as part of a resource parameter.
>> Lucky you :)
>
> Just giving a data point that suggests hex-encoding the embedded URL
> probably /should/ work in CXF, as it does so in the reference
> implementation of JAX-RS.
>
>> I tried:
>> GET
>> http://localhost:8080/service/newsletter/http%3A%2F%2Ftest.com%3Frss%3Doijoij
>>
>>
>> For the service:
>> @GET
>>     @Path("/{URL}")
>>     public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}
>
> Presumably you've annotated the resource class with
> @Path("/newsletter"), or?
Yes. The service responds if I use a non-hex-encoded value.

I guess I'll have to file a bug on this.

Kind regards,
Tarjei
>
> /Eoghan
>
>> and got:
>> <ns1:XMLFault>
>> <ns1:faultstring>
>> .No operation matching request path
>> /newsletter/http://test.com?rss=oijoij/ is found, ContentType : */*,
>> Accept :
>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
>> </ns1:faultstring>
>> </ns1:XMLFault>
>>
>> I also tried to add @Encoded to the method like this:
>>     @GET
>>     @Path("/{URL}")
>>     @Encoded
>>     public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}
>>
>> But it didn't help. The fault comes from:
>>     at
>> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:195)
>>
>>     at
>> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:65)
>>
>>     at
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
>>
>>
>>
>> Any tips?
>>
>> kind regards,
>> Tarjei
>>
>>> Cheers,
>>> Eoghan
>>>
>>>
>>> Tarjei Huse wrote:
>>>> Hi, I got a service where I want to expose a resource that is
>>>> defined by
>>>> an url to a rssfeed, something like:
>>>>
>>>>     @GET
>>>>     @Path("/{URL}/")
>>>>     public Subscriber getSubscriber(@PathParam("URL") String url) {
>>>>        ... do something with the url.
>>>>     }
>>>>
>>>> Now, this does not work with normal urls, nor with urlencoded urls.
>>>> Why
>>>> urlencoded values do not work I do not know, but for normal values, it
>>>> seems obvious (they contain '/'s). I've also tried base64 encoding the
>>>> urls, but that didn't work either because sometimes the base64 encoded
>>>> string contains slashes as well.
>>>>
>>>> So, is there a "correct" way to do this or should I just map
>>>> directly to
>>>> database ids or use request parameters whenever I need to deal with
>>>> urls?
>>>>
>>>> Kind regards,
>>>> Tarjei
>>> ----------------------------
>>> IONA Technologies PLC (registered in Ireland)
>>> Registered Number: 171387
>>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
>>> Ireland
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland


Re: JAX-RS: How to encode an url in an url

Posted by Eoghan Glynn <eo...@iona.com>.
Tarjei Huse wrote:
> Eoghan Glynn wrote:
>> You've tried hex-encoding the URL forward-slashes (as "%2F"), or?
>>
>> I'm using an old version of Jersey (0.6-ea) on another project, and
>> I'm happily accepting hex-encoded URIs as part of a resource parameter.
> Lucky you :)

Just giving a data point that suggests hex-encoding the embedded URL 
probably /should/ work in CXF, as it does so in the reference 
implementation of JAX-RS.

> I tried:
> GET
> http://localhost:8080/service/newsletter/http%3A%2F%2Ftest.com%3Frss%3Doijoij
> 
> For the service:
> @GET
>     @Path("/{URL}")
>     public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}

Presumably you've annotated the resource class with 
@Path("/newsletter"), or?

/Eoghan

> and got:
> <ns1:XMLFault>
> <ns1:faultstring>
> .No operation matching request path
> /newsletter/http://test.com?rss=oijoij/ is found, ContentType : */*,
> Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
> </ns1:faultstring>
> </ns1:XMLFault>
> 
> I also tried to add @Encoded to the method like this:
>     @GET
>     @Path("/{URL}")
>     @Encoded
>     public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}
> 
> But it didn't help. The fault comes from:
>     at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:195)
>     at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:65)
>     at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
> 
> 
> Any tips?
> 
> kind regards,
> Tarjei
> 
>> Cheers,
>> Eoghan
>>
>>
>> Tarjei Huse wrote:
>>> Hi, I got a service where I want to expose a resource that is defined by
>>> an url to a rssfeed, something like:
>>>
>>>     @GET
>>>     @Path("/{URL}/")
>>>     public Subscriber getSubscriber(@PathParam("URL") String url) {
>>>        ... do something with the url.
>>>     }
>>>
>>> Now, this does not work with normal urls, nor with urlencoded urls. Why
>>> urlencoded values do not work I do not know, but for normal values, it
>>> seems obvious (they contain '/'s). I've also tried base64 encoding the
>>> urls, but that didn't work either because sometimes the base64 encoded
>>> string contains slashes as well.
>>>
>>> So, is there a "correct" way to do this or should I just map directly to
>>> database ids or use request parameters whenever I need to deal with
>>> urls?
>>>
>>> Kind regards,
>>> Tarjei
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAX-RS: How to encode an url in an url

Posted by Tarjei Huse <ta...@scanmine.com>.
Eoghan Glynn wrote:
>
> You've tried hex-encoding the URL forward-slashes (as "%2F"), or?
>
> I'm using an old version of Jersey (0.6-ea) on another project, and
> I'm happily accepting hex-encoded URIs as part of a resource parameter.
Lucky you :)

I tried:
GET
http://localhost:8080/service/newsletter/http%3A%2F%2Ftest.com%3Frss%3Doijoij

For the service:
@GET
    @Path("/{URL}")
    public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}

and got:
<ns1:XMLFault>
<ns1:faultstring>
.No operation matching request path
/newsletter/http://test.com?rss=oijoij/ is found, ContentType : */*,
Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
</ns1:faultstring>
</ns1:XMLFault>

I also tried to add @Encoded to the method like this:
    @GET
    @Path("/{URL}")
    @Encoded
    public Newsletters getPagesForUrl(@PathParam("URL") String URL) {}

But it didn't help. The fault comes from:
    at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:195)
    at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:65)
    at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)


Any tips?

kind regards,
Tarjei

>
> Cheers,
> Eoghan
>
>
> Tarjei Huse wrote:
>> Hi, I got a service where I want to expose a resource that is defined by
>> an url to a rssfeed, something like:
>>
>>     @GET
>>     @Path("/{URL}/")
>>     public Subscriber getSubscriber(@PathParam("URL") String url) {
>>        ... do something with the url.
>>     }
>>
>> Now, this does not work with normal urls, nor with urlencoded urls. Why
>> urlencoded values do not work I do not know, but for normal values, it
>> seems obvious (they contain '/'s). I've also tried base64 encoding the
>> urls, but that didn't work either because sometimes the base64 encoded
>> string contains slashes as well.
>>
>> So, is there a "correct" way to do this or should I just map directly to
>> database ids or use request parameters whenever I need to deal with
>> urls?
>>
>> Kind regards,
>> Tarjei
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland


Re: JAX-RS: How to encode an url in an url

Posted by Eoghan Glynn <eo...@iona.com>.
You've tried hex-encoding the URL forward-slashes (as "%2F"), or?

I'm using an old version of Jersey (0.6-ea) on another project, and I'm 
happily accepting hex-encoded URIs as part of a resource parameter.

Cheers,
Eoghan


Tarjei Huse wrote:
> Hi, I got a service where I want to expose a resource that is defined by
> an url to a rssfeed, something like:
> 
>     @GET
>     @Path("/{URL}/")
>     public Subscriber getSubscriber(@PathParam("URL") String url) {
>        ... do something with the url.
>     }
> 
> Now, this does not work with normal urls, nor with urlencoded urls. Why
> urlencoded values do not work I do not know, but for normal values, it
> seems obvious (they contain '/'s). I've also tried base64 encoding the
> urls, but that didn't work either because sometimes the base64 encoded
> string contains slashes as well.
> 
> So, is there a "correct" way to do this or should I just map directly to
> database ids or use request parameters whenever I need to deal with urls?
> 
> Kind regards,
> Tarjei

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland