我已經設置了一個App Engine Restlet Project(v 2.2.2),它爲不同的用戶返回一個html或json響應(web或android客戶端)和一個db的不同數據。我已經實現了HTTP基本認證。這一切都很好。新組件的Restlet web.xml配置
我的基本設置ATM(我已經簡化它OFC):
MyApplication.java
public class MyApplication extends Application {
private ChallengeAuthenticator authenticatior;
private ChallengeAuthenticator createAuthenticator() {...}
public boolean authenticate(Request request, Response response) {...}
@Override
public Restlet createInboundRoot() {
this.authenticatior = createAuthenticator();
Router router = new Router(getContext());
router.attachDefault(MyRestlet.class);
authenticatior.setNext(router);
return authenticatior;
}
MyRestlet.java
public class MyRestlet extends ServerResource {
@Get("json")
public Representation getJSON() {
MyApplication app = (MyApplication) getApplication();
if (!app.authenticate(getRequest(), getResponse())) {
// Not authenticated
return null;
}
else {
return data;
}
@Get("html")
public String getHTML() {...}
}
的web.xml
<?xml ...>
<display-name>MyName</display-name>
<context-param>
<param-name>org.restlet.application</param-name>
<param-value>x.MyApplication</param-value>
</context-param>
<servlet>
<servlet-name>MyRestlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyRestlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
現在我想添加加密並創建密鑰/證書。我的導遊是這個tutorial。我想先嚐試添加一個簡單的組件,然後使用HTTP並將此端口更改爲8183,如tutorial所示。我現在玩了很多,看起來不能讓我的組件工作。所以我的問題是:我會在哪裏把這個main-Method(以下代碼來自教程)?我應該在哪個類中插入它,或者我應該創建一個單獨的服務器類,以及對web.xml所需的更改是什麼樣的(我沒有發現太多關於此的內容,並且我懷疑這是中心問題)?任何幫助表示讚賞!
public static void main(String[] args) throws Exception {
// Create a new Restlet component and add a HTTP server connector to it
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
// Then attach it to the local host
component.getDefaultHost().attach("/trace", Part05.class);
// Now, let's start the component!
// Note that the HTTP server connector is also automatically started.
component.start();
}