2016-06-22 33 views
7

上到的Restlet資源的每個請求,我看到了谷歌應用程序引擎日誌以下日誌爲什麼的Restlet GAE上說,組件爲空

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: [email protected] to URI: /example/v1 

爲什麼它說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); 
    } 
} 

服務器資源負責處理,並返回一個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\"}"); 
    } 
} 

有什麼我做錯了嗎?

回答

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實現它沒有一個是默認的。

+0

是的,我做到了。我跟着它的書。有趣的是我正在運行它沒有問題,但這些日誌嚇跑了我 – Atrix1987