泽西岛 1.91.x 404 错误

Jersey 1.91.x 404 Error

我在发出休息请求时收到 404 错误。我的环境详细信息如下:

球衣 1.91.1

阿帕奇 Tomcat/7.0.42

Javajdk1.7.0_80

我的web.xml看起来像这样

<web-app>
<display-name>Archetype Created Web Application</display-name>
<listener>
    <listener-class>com.company.gcs.zanshin.notificationengine.web.ContextStarter</listener-class>
</listener>
<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.company.gcs.zanshin.notificationengine.web</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/operations/*</url-pattern>
</servlet-mapping>

当我开始时 tomcat 我看到 jersey 正在加载所有资源 类 正在正确加载

INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
May 20, 2016 5:33:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Executables\tomcats\NotificationEngine\webapps\notification
May 20, 2016 5:33:03 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Executables\tomcats\NotificationEngine\webapps\notification\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
May 20, 2016 5:33:09 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [312] milliseconds.
May 20, 2016 5:33:09 PM com.sun.jersey.api.core.servlet.WebAppResourceConfig init
INFO: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
May 20, 2016 5:33:12 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class com.company.gcs.zanshin.notificationengine.web.ExcelRestPoints
  class com.company.gcs.zanshin.notificationengine.web.FileRestPoints
  class   com.company.gcs.zanshin.notificationengine.web.NotificationRestPoints
  class com.company.gcs.zanshin.notificationengine.web.WordRestPoints
  class com.company.gcs.zanshin.notificationengine.web.EmailRestPoints
May 20, 2016 5:33:12 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
May 20, 2016 5:33:12 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:42 PM'
May 20, 2016 5:33:13 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 20, 2016 5:33:13 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 20, 2016 5:33:13 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9893 ms

HTTP 请求

POST http://localhost:8080/notification/operations/file/upload HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 144
Accept: application/json, text/plain, */*
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryYeOKGTo9xFMhvjUB
Referer: http://localhost:8080/notification/ui/index.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,ur;q=0.6,hi;q=0.4,ar;q=0.2

HTTP 响应

HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Fri, 20 May 2016 12:25:50 GMT

Java 计划

@Path("/operations")
class FileRestPoints {

    @Path("/file/upload")
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    public def upload(
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail,
            @FormDataParam("notificationId") String notificationId)
    {
        FileUploader uploader = new FileUploader();

        String fileName = fileDetail.getFileName();

        def resp = uploader.upload(notificationId,fileName,uploadedInputStream)

        return toJson(resp);
    }
}

我通过在 url 中提供两次 操作 来解决它,例如 localhost:8080/notification/operations/operations/file/upload。这是因为在 web.xml 和 Java class.

中都有关键字 operations