2

我正在尝试在 GAE 上使用 Restlet。我有一个警卫,后面跟着根路由器。2 个角色授权器,一个用于管理员,另一个用于用户。然后是roleauthorizer后面的2个路由器,用于uri和资源类之间的路由。这很奇怪,因为路线不起作用。如果我使用 attachDefault 没关系,但对于带有 attach 的路线:什么都没有!

这是我的代码:

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 错误。你能帮助我吗 ?

4

0 回答 0