【问题标题】:Why does Restlet on GAE says Component is NULL为什么 GAE 上的 Restlet 说 Component 是 NULL
【发布时间】:2016-10-24 21:07:22
【问题描述】:

对于对 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

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

布线应用类

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);
    }
}

处理并返回 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\"}");
    }
}

我做错了什么吗?

【问题讨论】:

    标签: java google-app-engine restlet


    【解决方案1】:

    您是否按照文档(以下链接)中的说明配置了您的 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 实现中默认情况下它没有。

    【讨论】:

    • 是的,我做到了。我跟着这本书。有趣的是我运行它没有问题,但这些日志吓坏了我
    猜你喜欢
    • 2014-08-21
    • 2011-01-10
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    相关资源
    最近更新 更多