problem with character slash contained in path parameter value

6 messages Options
Embed this post
Permalink
webpost

problem with character slash contained in path parameter value

Reply Threaded More More options
Print post
Permalink
Hi,
I am having following problem with RESTlet 1.1.6 (and even with the version 2 m5): if my path parameter value contains the slash (/) and even the value is URL encoded, my resource class isn't called.

@Path("/supplemental/{doctype}/{entryid}")
public class SupplementalResource {
...}

Let say my entryid is "AAA/BB", the URL encoded form is "AAA%2FBB".

Can someone tell me if this is a bug?

Thanks for your reply in advance.
hvtranho.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2414227
StephanKoo

Re: problem with character slash contained in path parameter value

Reply Threaded More More options
Print post
Permalink
Hi hvtranho,

You mean the JAX-RS extension? Then you are right, it seems to be a bug.
Because workspace seems a little bit crashed I can analyse anything now.

best regards
   Stephan

[hidden email] schrieb:

> Hi,
> I am having following problem with RESTlet 1.1.6 (and even with the version 2 m5): if my path parameter value contains the slash (/) and even the value is URL encoded, my resource class isn't called.
>
> @Path("/supplemental/{doctype}/{entryid}")
> public class SupplementalResource {
> ...}
>
> Let say my entryid is "AAA/BB", the URL encoded form is "AAA%2FBB".
>
> Can someone tell me if this is a bug?
>
> Thanks for your reply in advance.
> hvtranho.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2414526
StephanKoo

Re: problem with character slash contained in path parameter value

Reply Threaded More More options
Print post
Permalink
In reply to this post by webpost
Hi hvtranho,

I've created a test case and I can't reproduce your problem. See class
org.restlet.test.jaxrs.services.tests.PathParamTest3 . You could just
start the JUnit test case.
Perhaps something decoded the path before the JAX-RS extension got it.
Do you tried another connector? I don't know which connector is used in
the tes cases.

best regards
   Stephan

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2414911
webpost

RE: Re: problem with character slash contained in path parameter value

Reply Threaded More More options
Print post
Permalink
Hi Stephan,
I can't find your test class, but I have create following classes to show how I am using Restlet and the extension:

import org.restlet.Context;
import org.restlet.ext.jaxrs.JaxRsApplication;
public class MdWebServiceJaxRsApplication extends JaxRsApplication {

    public MdWebServiceJaxRsApplication(Context context) {

        super(context);

        this.add(new MdWebServiceApplication());
        //this.setGuard(...);
        //this.setRoleChecker(...);
    }
}
-------------------------------------
import javax.ws.rs.core.Application;
import java.util.Set;
import java.util.HashSet;
public class MdWebServiceApplication extends Application {

    public Set<Class<?>> getClasses() {

        Set<Class<?>> rrcs = new HashSet<Class<?>>();
rrcs.add(TestResource.class);

        return rrcs;
    }
}
-------------------------------------------
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;

/**
 * Created by IntelliJ IDEA.
 * User: hvtranho
 * Date: Nov 6, 2009
 * Time: 1:40:40 PM
 * To change this template use File | Settings | File Templates.
 */
@Path("/mytestpath/entity/{id}")
public class TestResource {

    @GET
    @Produces("application/xml")
    public Response getSupplementalAsXml(@PathParam("id") String id) {

        return Response.ok(id, MediaType.APPLICATION_XML).build();
    }
   
}
------------------------------------

and the test class:

public class ClientApp {

    String URLPREFIX = "http://localhost:8080/mws";

    /**
     *
     * @param args
     */
    public static void main(String args[]) {
        org.junit.runner.JUnitCore.main("gov.nasa.gsfc.gcmd.mdwebservice.rest.ClientApp");
    }

    @Test
    public void getTestResource() throws Exception {
        Client client = new Client(Protocol.HTTP);

        String id = URLEncoder.encode("PMEL/NOAA", "UTF-8");

        System.out.println(id);

        String url = URLPREFIX + "/mytestpath/entity/" + id;

        System.out.println(url);

        Request r = new Request();
        r.setResourceRef(url);
        r.setMethod(Method.GET);

        r.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(MediaType.APPLICATION_XML));

        Response response = client.handle(r);

        System.out.println(response.getStatus());

        if (response.isEntityAvailable()) {
            response.getEntity().write(System.out);
        }
    }
}

-----------------------------------------

I received this test result:

PMEL%2FNOAA
http://localhost:8080/mws/mytestpath/entity/PMEL%2FNOAA
Nov 6, 2009 3:02:43 PM com.noelios.restlet.http.StreamClientHelper start
INFO: Starting the HTTP client
Bad Request (400) - Bad Request

I am using Apache Tomcat 5.5.27, jdk 1.50_20 on Mac OS X 10.5.8

Best regards,
Hoan-Vu Tran-Ho.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2415231
StephanKoo

Re: problem with character slash contained in path parameter value

Reply Threaded More More options
Print post
Permalink
Hi Hoan-Vu Tran-Ho,
> I can't find your test class
I've created the testcase in the trunk on 2009-11-05 in the trunk, not
in a milestone. It is in the project org.restlet.test
> String id = URLEncoder.encode("PMEL/NOAA", "UTF-8");
>  
You have to encode as in URL required ("/" to "%2F"), not with UTF-8.

best regards
   Stephan

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2415441
webpost

RE: problem with character slash contained in path parameter value

Reply Threaded More More options
Print post
Permalink
In reply to this post by webpost
Hi Stephan,
thanks for your help, but that was a problem with Tomcat: it treats '%2F' as a slash. My coworker found the solution from this page:
https://jira.jboss.org/jira/browse/JBSEAM-3990

Best Regards,
Hoan-Vu Tran-Ho.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2418684