为什么Restlet on GAE表示Component为NULL

Abh*_*ndi 8 java google-app-engine restlet

在对Restlet资源发出的每个请求中,我都会在Google App Engine日志中看到以下日志

21:38:50.059 javax.servlet.ServletContext log: ExampleAPIs: [Restlet] ServerServlet: component class is null
21:38:51.568 javax.servlet.ServletContext log: ExampleAPIs: [Restlet] Attaching application: com.example.api.ExampleAPIConfig@68ec99 to URI: /example/v1
Run Code Online (Sandbox Code Playgroud)

为什么说Component是null? 我同意我没有定义组件而是使用ServerResources并将它们映射到Application类中的路由器.但这就是根据Restlet GAE Edition文档应该如何完成的.

布线路线的应用等级

public Example extends Application {
    @Override
    public Restlet createInboundRoot() {
        router = new Router(getContext());
        CorsService corsService = new CorsService();         
        corsService.setAllowedOrigins( new HashSet<String>(Arrays.asList("http://example.com")));
        corsService.setAllowedCredentials(true);
        getServices().add(corsService);

         router.attach("/xyz", XYZ.class);
    }
}
Run Code Online (Sandbox Code Playgroud)

处理并返回JSON表示的服务器资源

public class XYZ extends ServerResource {

    private static final Logger logger = Logger.getLogger("API:Xyz");

    @Get(":json")
    public Representation handleGetRequest() {
         ..
         return new JsonRepresentation("{\"code\": 4008, \"description\": \"Something blah something\"}");
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么我做错了吗?

Mr_*_*que 0

您是否按照文档(下面的链接)中的说明配置了 servlet 配置文件。我认为 servlet 并不绑定到类。

https://restlet.com/technical-resources/restlet-framework/guide/2.3/editions/gae

更新

好吧,如果您更深入地了解文档: https://restlet.com/technical-resources/restlet-framework/javadocs/2.0/jee/ext/org/restlet/ext/servlet/ServerServlet.html
https://restlet.com /technical-resources/restlet-framework/javadocs/2.0/jee/api/org/restlet/Component.html 您可以看到该组件是可选的,但可能很有用,但也许在 GAE 实现中默认情况下没有该组件。