【发布时间】: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