我是新來的Restlet框架。 我創建了一個小型的Java EE應用程序,但它給我一個錯誤「未找到(404)」「未找到(404)」錯誤的Restlet
public class MailServerApplication extends Application { @Override public Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("http://localhost:8084/accounts/{accountId}/mails/{mailId}", MailServerResource.class); return router; } } //////////////////////////////// public class MailServerResource extends ServerResource { @Override protected Representation get() throws ResourceException { DomRepresentation result = null; try { result = new DomRepresentation(); result.setIndenting(true); Document doc = result.getDocument(); Node mailElt = doc.createElement("mail"); doc.appendChild(mailElt); Node statusElt = doc.createElement("status"); statusElt.setTextContent("received"); mailElt.appendChild(statusElt); Node subjectElt = doc.createElement("subject"); subjectElt.setTextContent("Message to self"); mailElt.appendChild(subjectElt); Node contentElt = doc.createElement("content"); contentElt.setTextContent("Doh!"); mailElt.appendChild(contentElt); } catch (IOException e) { } return result; } @Override protected Representation put(Representation representation) throws ResourceException { DomRepresentation mailRep = new DomRepresentation(representation); Document doc; try { doc = mailRep.getDocument(); Element mailElt = doc.getDocumentElement(); Element statusElt = (Element) mailElt .getElementsByTagName("status").item(0); Element subjectElt = (Element) mailElt.getElementsByTagName( "subject").item(0); Element contentElt = (Element) mailElt.getElementsByTagName( "content").item(0); Element accountRefElt = (Element) mailElt.getElementsByTagName( "accountRef").item(0); System.out.println("Status: " + statusElt.getTextContent()); System.out.println("Subject: " + subjectElt.getTextContent()); System.out.println("Content: " + contentElt.getTextContent()); System.out.println("Account URI: " + accountRefElt.getTextContent()); } catch (IOException e) { throw new ResourceException(e); } return 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)
謝謝。
此錯誤意味着服務器頁面無法找到。您確定您輸入了正確的網址,並且可以訪問嗎? – AbdullahC 2011-04-20 09:21:04
你用什麼URL訪問它?另外,你的'router.attach()'調用可能不應該指定所有http:// host:port的東西。相反,嘗試使用'router.attach(「/ accounts/{accountId}/mail/{mailId}」)'。 – 2011-04-21 03:11:51