Restlet 2.1.0、Java SE バージョンでプロトタイピングを行っていますが、ServerResource クラスを URL にマッピングする際に問題が発生しています。Router.attach メソッドを使用してかなりの数のバリエーションを試しましたが、何も機能しませんでした。
私の現在のコードは次のようになります。
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final Router router = new Router();
router.attach("/hello", FirstServerResource.class);
router.attach("/json", Json.class);
Application myApp = new Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
router.setContext(getContext());
return router;
};
};
new Server(Protocol.HTTP, 8182, myApp).start();
}
参照するhttp://localhost:8182/hello
と、テンプレートが正しく一致しません。http://localhost:8182/hello
ソース コードをデバッグすると、一致ロジックが要求されたリソースを単に ではなく と見なすことがわかります/hello
。これが発生する Restlet コードは次のとおりです。
// HttpInboundRequest.java
// Set the resource reference
if (resourceUri != null) {
setResourceRef(new Reference(getHostRef(), resourceUri));
if (getResourceRef().isRelative()) {
// Take care of the "/" between the host part and the segments.
if (!resourceUri.startsWith("/")) {
setResourceRef(new Reference(getHostRef().toString() + "/"
+ resourceUri));
} else {
setResourceRef(new Reference(getHostRef().toString()
+ resourceUri));
}
}
setOriginalRef(getResourceRef().getTargetRef());
}
上記のコードでは、 Resource がrelativeと見なされるため、要求され/hello
たリソースが完全な URL に変更されます。ここで明らかな何かが欠けていますが、完全に困惑しています。