我正在尝试在GAE上使用Restlet。我有一个后卫根路由器的后卫。 2 roleAuthorizer,一个用于admin,另一个用于用户。然后在角色授权器后面有2个路由器,用于uri和ressource类之间的路由。这很奇怪,因为这条路线不起作用。如果我使用attachDefault它没关系,但对于带附加的路由:没有!
这是我的代码:
public synchronized Restlet createInboundRoot() {
Router rootRouter = new Router(getContext());
pubRouter = new Router(getContext());
String version="/book/v"+System.getProperty("API_VERSION");
pubRouter.attachDefault(BookRessource.class);
pubRouter.attach(version+"/book",BookRessource.class);
RoleAuthorizer ra1 = new RoleAuthorizer();
ra1.getAuthorizedRoles().add(MyEnroler.DEVELOPER);
ra1.getAuthorizedRoles().add(MyEnroler.ADMINISTRATOR);
ra1.setNext(pubRouter);
rootRouter.attach(version, ra1);
adminRouter = new Router(getContext());
String developerVersion="/admin/v1";
adminRouter.attach(developerVersion+"/developer", DeveloperRessource.class);
adminRouter.attach(developerVersion+"/method",MethodRessource.class);
RoleAuthorizer ra2 = new RoleAuthorizer();
ra2.getAuthorizedRoles().add(MyEnroler.ADMINISTRATOR);
ra2.setNext(adminRouter);
rootRouter.attach(developerVersion, ra2);
ChallengeAuthenticator guard=
new ChallengeAuthenticator( getContext(),ChallengeScheme.HTTP_BASIC,"OPA");
guard.setVerifier(new MyVerifier());
guard.setEnroler(new MyEnroler());
guard.setNext(rootRouter);
return guard;
}
和我的“web.xml”的摘录:
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
如果我想试试这个:http://domain.appspot.com/api/book/v1/book,我收到了404错误。 你能帮助我吗 ?