Search code examples
urlmatchrouterrestlet

Restlet Router can not match my url request


I have question.

When I request some URL to server, Server receive URL request. (client: android)

For example, client request URL is http://address:8182/signupUser.

Absolutely i believe that signupUser method is called. (please, refer below my method form.)

@Post("signupUser")
public string XXXX(Representation entity){
..
}

Of course, Server message in eclipse console is very collect.

However router call other method "confirmUser".

I'm so confused. all URI matching is perfect. But, router is not work well.

please, refer bellow my currently source.

public class serverApplication extends Application {
    public Restlet createInboundRoot(){
        Router router = new Router(getContext());

        router.attach("/signupUser", UserResource.class);
        router.attach("/confirmUser", UserResource.class);
    }
}

Actually, i not familiar with English. I hope that my question is delivered to you exactly.

Please, help me....


Solution

  • basically, your sample code will work better as follow:

    @Post
    public string XXXX(Representation entity){
    ..
    }
    

    The @Post annotation(or @Get, etc) is not a container for path routing instruction. This is the job of the Router.

    The main idea is that:

    1. define your paths and paths template thanks to Router instance(s)
    2. because a resource is identified by its URI, attach to eachd istinct path a distinct Java class.

    For some more ideas:

    1. Routers leverage the hierarchical nature of URIs. You can define nodes in your tree (a node is another router), and attach Filter before a Router in order to mutualize behavior for a whole sub-tree. For example, you can protect a set of admin resources:

      Router adminRouter = new Router(getContext()); admin.attach("/users/"); admin.attach("/users/{user}"); //etc.

      // attach adminRouter to the /admin root path, and protect it ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "realm"); guard.setNext(adminRouter); // attach the guarded admin router rootRouter.attach("/admin", guard);

    2. For example: "/contacts/{contact}" means the "the resource that represents a single contact". "/contacts" represents the list of contacts. Technically speaking, you can attach the same Java class (as you did in your sample code), but you will end up with complicated code. A ServerResource class really represents a resource and helps handling its state using the whole set of accepted methods (GET to retrieve the state, PUT to store it, DELETE to remove it, etc).

    I hope this is a little bit clearer.

    As pointed by the other answers, annotations accept media types parameters (support also query values). I suggest you to have a look at this page: http://restlet.com/learn/guide/2.2/core/resource/