Java &引用;未找到(404)“;restlet中的错误

Java &引用;未找到(404)“;restlet中的错误,java,rest,restlet,java-ee-5,Java,Rest,Restlet,Java Ee 5,我不熟悉restlet框架。 我创建了一个小的JavaEE应用程序,但它给了我一个错误“NotFound(404)” 公共类MailServerApplication扩展了应用程序{ @凌驾 public Restlet createInboundRoot(){ 路由器=新路由器(getContext()); 路由器。附加(“http://localhost:8084/accounts/{accountId}/mails/{mailId},MailServerResource.class); 返

我不熟悉restlet框架。 我创建了一个小的JavaEE应用程序,但它给了我一个错误“NotFound(404)”

公共类MailServerApplication扩展了应用程序{ @凌驾 public Restlet createInboundRoot(){ 路由器=新路由器(getContext()); 路由器。附加(“http://localhost:8084/accounts/{accountId}/mails/{mailId},MailServerResource.class); 返回路由器; } } //////////////////////////////// 公共类MailServerResource扩展了ServerResource{ @凌驾 受保护的表示get()引发ResourceException{ DomRepresentation结果=null; 试一试{ 结果=新的DomRepresentation(); 结果:设置缩进(真); Document doc=result.getDocument(); 节点mailElt=doc.createElement(“邮件”); 儿童医生(mailElt); 节点状态elt=doc.createElement(“状态”); statusElt.setTextContent(“已接收”); mailElt.appendChild(statusElt); 节点subjectElt=doc.createElement(“主题”); subjectElt.setTextContent(“自我信息”); mailElt.appendChild(主题英语); 节点contentElt=doc.createElement(“内容”); setTextContent(“Doh!”); mailElt.appendChild(contentElt); }捕获(IOE异常){ } 返回结果; } @凌驾 受保护的表示法放置(表示法)引发ResourceException{ DomRepresentation mailRep=新的DomRepresentation(表示); 文件文件; 试一试{ doc=mailRep.getDocument(); Element maillet=doc.getDocumentElement(); 元素状态elt=(元素)maillet .getElementsByTagName(“状态”)。项(0); Element subjectElt=(Element)mailElt.getElementsByTagName( “主体”)。第(0)项; 元素contentElt=(元素)maillet.getElementsByTagName( “内容”)。第(0)项; 元素accountRefElt=(元素)mailElt.getElementsByTagName( “accountRef”)。第(0)项; System.out.println(“状态:+statusElt.getTextContent()); System.out.println(“主题:+subjectElt.getTextContent()); System.out.println(“内容:+contentElt.getTextContent()); System.out.println(“帐户URI:+accountRefElt.getTextContent()); }捕获(IOE异常){ 抛出新的ResourceException(e); } 返回null; } } 但是如果我运行/调试它。它给出了以下错误:

Exception in thread "main" Not Found (404) - Not Found at org.restlet.resource.ClientResource.handle(ClientResource.java:858) at org.restlet.resource.ClientResource.handle(ClientResource.java:763) at org.restlet.resource.ClientResource.get(ClientResource.java:496) at MailClient.main(MailClient.java:19) 未找到线程“main”中的异常(404)-未找到 位于org.restlet.resource.ClientResource.handle(ClientResource.java:858) 位于org.restlet.resource.ClientResource.handle(ClientResource.java:763) 位于org.restlet.resource.ClientResource.get(ClientResource.java:496) MailClient.main(MailClient.java:19)
谢谢。

除了发表评论外,您是如何启动Restlet应用程序的?使用服务器类,如下所示:

public class MailServerApplication extends Application {
  (...)
  public static void main(String[] args) {
    try {
      Server server = new Server(Protocol.HTTP, 8084);
      server.setNext(new MailServerApplication());
      server.start();

      System.out.println("Press a key to stop");
      System.in.read();
    } catch(Exception ex) {
      ex.printStackTrace();
    }
  }
}
正如您所说,您开发了一个JavaEE应用程序,也许您使用了servlet扩展?在这种情况下,还可以考虑servlet级别的映射

使用第一种方法,我使用org.restlet.jar和org.restlet.ext.xml.jar(版本2.0.5,jee edition)使应用程序正常工作。我使用url访问它

希望对你有帮助。 蒂埃里

你好,谢谢河马。
实际上,问题出在url中。
我不得不修改下面的行

router.attach("http://localhost:8084/accounts/{accountId}/mails/{mailId}", MailServerResource.class); 路由器。附加(“http://localhost:8084/accounts/{accountId}/mails/{mailId},MailServerResource.class); 进入这条线

router.attach("/accounts/{accountId}/mails/{mailId}", MailServerResource.class); 附加(“/accounts/{accountId}/mails/{mailId}”,MailServerResource.class); 如果您使用用于JavaSE的restlet框架,那么第一个url就可以了。但对于web应用程序(JavaEE),您必须使用服务器的相对路径


再次感谢您的帮助。

此错误意味着找不到服务器页面。您确定输入了正确的URL,并且可以访问它吗?您使用什么URL访问它?另外,您的
router.attach()
调用可能不应该指定所有内容。相反,尝试只使用
router.attach(“/accounts/{accountId}/mails/{mailId}”)
。 router.attach("/accounts/{accountId}/mails/{mailId}", MailServerResource.class);