1

我正在使用 Jersey 的 Google App Engine 中部署一个示例应用程序。但是,当我尝试对 REST 资源执行 GET 或 POST 时,我收到 - 404 NOT FOUND 错误。看起来我错过了一些东西。

REST 资源代码:

    import javax.ws.rs.Consumes;
    import javax.ws.rs.GET;
    import javax.ws.rs.POST;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;

    import org.codehaus.jettison.json.JSONObject;

    @Path("/stream")
    public class StreamingResource {
        private static final Logger log = Logger
        .getLogger(FacebookStreamingResource.class.getName());

        @POST
        @Path("/callback")
        @Consumes(MediaType.APPLICATION_JSON)
        @Produces(MediaType.TEXT_PLAIN)
        public String putStreamData(JSONObject jsonEntity) {
            return jsonEntity.toString();
        }

        @GET
        @Path("/get")
        @Produces(MediaType.TEXT_PLAIN)
        public String getStreamData() {
            return "Get successful";
        }
    }

这是 web.xml 文件

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee               http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>SystemServiceServlet</servlet-name>
            <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
            <init-param>
                <param-name>services</param-name>
                <param-value />
            </init-param>
        </servlet>
        <servlet-mapping>
            <servlet-name>SystemServiceServlet</servlet-name>
            <url-pattern>/_ah/spi/*</url-pattern>
        </servlet-mapping>

        <servlet>
            <servlet-name>JerseyWebApplication</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
                <param-name>com.sun.jersey.config.property.packages</param-name>
                <param-value>com.vbv.fb</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>JerseyWebApplication</servlet-name>
            <url-pattern>/stream/*</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
    </web-app>

我已经包括以下罐子:

asm-3.1.jar jersey-client-1.12.jar jersey-core-1.12.jar jersey-json-1.12.jar jersey-server-1.12.jar jersey-servlet-1.12.jar jettison-1.1.jar jackson-core-asl -1.7.1.jar jackson-jaxrs-1.7.1.jar jackson-mapper-asl-1.7.1.jar jackson-xc-1.7.1.jar

App Engine SDK 版本为 1.7.0

任何建议将不胜感激 :)

4

1 回答 1

0

当我将 web.xml 中的 /stream/* 更改为 /* 时,它可以工作:)

于 2012-10-06T05:23:29.880 回答