Restore ServerResource Method Parameters

This is probably a really stupid / simple question with such an obvious answer that it seems not worth mentioning in the compilation. Where and how (if at all) can Restet pass parameters to methods in ServerResource classes?

Given this class:

public class FooServerResource extends ServerResource {
    @Get
    public String foo(String f) {
        return f;
    }
}

and the router application router.attach("/foo", FooServerResource.class);

I know that if I use the Restlet client connector, I could create a proxy for this class and call methods directly, but what if I make calls to this ServerResource from some other non-java language, for example. Php?

+3
source share
2 answers

You can access the request parameters using the link to the resource. Typically, something like this:

@Get
public String foo() {
    Form queryParams = getReference().getQueryAsForm();
    String f = queryParams.getFirstValue("f");
    return f;
}

( , GET), , ( , ) getRequest() ServerResource.

+8

hi

, Restlet " " . , ( , )
, . , , Restlet ( - ), , , Observer , sth. . , , . Restlet . , ( ?)

, Application Restlet , , , ..

sth.

protected Application initObjLinkage(){

    Context cx = this.getContext();
    Client cli = cx.getClientDispatcher();
    Application app = cli.getApplication() ;
    return app;
}

Application ( ), ...

Method cbMethod = app.getClass().getMethod("getFoo", parameterTypes) ;
CallbackIntf getmethodFoo = ( CallbackIntf )cbMethod.invoke( app, arguments );
String str = getmethodFoo()

, , -. , , .
... , {no/some} :)

+1
source

Source: https://habr.com/ru/post/1770513/


All Articles