在RESTlet框架中获取错误HTTP ERROR 404

时间:2011-05-12 11:29:40

标签: java web-services rest restlet

我是restlet框架的新手。我只是创建我的第一个应用程序,但我得到如下错误:

HTTP错误404 访问/ hellofourthtrial /你好的问题。原因:NOT_FOUND

我的代码如下:


HelloWorldResource.java

package hellofourthtrial;

import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class HelloWorldResource extends ServerResource{

    @Get
    public String represent() {
        return "in the represent";
    }

}

FirstStepsApplication.java

package hellofourthtrial;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;
import org.restlet.Server;

public class FirstStepsApplication extends Application{

    /**
     * Creates a root Restlet that will receive all incoming calls.
     */
    @Override
    public synchronized Restlet createInboundRoot() {
        // Create a router Restlet that routes each call to a
        // new instance of HelloWorldResource.
        Router router = new Router(getContext());
        // Defines only one route
        router.attach("/hello", HelloWorldResource.class);
        return router;
    }

    public static void main(String[] args) {
        try {
          Server server = new Server(Protocol.HTTP, 8888);
          server.setNext(new FirstStepsApplication());
          server.start();

          System.out.println("Press a key to stop");
          System.in.read();
        } catch(Exception ex) {
          ex.printStackTrace();
        }
      }

}

的web.xml

<context-param>
    <param-name>org.restlet.application</param-name>
    <param-value>
        hellofourthtrial.FirstStepsApplication
    </param-value>
</context-param>


<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>/*</url-pattern>
</servlet-mapping>

我在eclipse中开发了这个项目,并将其作为Web应用程序运行。当我将其作为Web应用程序运行时,我在控制台中得到以下输出

May 12, 2011 11:22:23 AM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
May 12, 2011 11:22:23 AM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed C:\Users\Admin\workspace2\HelloFourthTrial\war\WEB-INF/appengine-web.xml
May 12, 2011 11:22:23 AM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed C:\Users\Admin\workspace2\HelloFourthTrial\war\WEB-INF/web.xml
May 12, 2011 4:52:24 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The server is running at http://localhost:8888/

我真的卡住了,我无法弄清楚我哪里出错了。任何帮助都将受到高度赞赏

2 个答案:

答案 0 :(得分:0)

当您致电该应用程序时,请在您的网址中尝试http://localhost:8888/HelloFourthTrial/hello

答案 1 :(得分:0)

我看不到你将'HelloFourthTrial'绑定到路径的位置...你是否尝试过访问没有该子串(= http://localhost:8888/hello)的URL?