我已经设置了一个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();
}