Jersey Web Service发送415状态代码

时间:2014-04-26 09:28:25

标签: java web-services servlets http-status-codes jersey-1.0

我为使用servlets创建的Jave EE Web应用程序创建了一个使用jersey的web服务。我发现我得到了415 error code

我通常会重定向到另一个servletjsp,这在我的app中是技术上的servlet。我应该使用mime-type吗?

  SEVERE: A message body reader for Java class javax.servlet.http.HttpServletRequest,   and Java type interface javax.servlet.http.HttpServletRequest, and MIME media type application/octet-stream was not found.
   The registered message body readers compatible with the MIME media type are:
   application/octet-stream ->
   com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
   com.sun.jersey.core.impl.provider.entity.FileProvider
   com.sun.jersey.core.impl.provider.entity.InputStreamProvider
   com.sun.jersey.core.impl.provider.entity.DataSourceProvider
   com.sun.jersey.core.impl.provider.entity.RenderedImageProvider
   */* ->
   com.sun.jersey.core.impl.provider.entity.FormProvider
   com.sun.jersey.core.impl.provider.entity.StringProvider
   com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
   com.sun.jersey.core.impl.provider.entity.FileProvider
   com.sun.jersey.core.impl.provider.entity.InputStreamProvider
   com.sun.jersey.core.impl.provider.entity.DataSourceProvider
   com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
   com.sun.jersey.core.impl.provider.entity.ReaderProvider
   com.sun.jersey.core.impl.provider.entity.DocumentProvider
   com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
   com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
   com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
   com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
   com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
   com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
   com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
   com.sun.jersey.core.impl.provider.entity.EntityHolderReader
   com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
   com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General

这是Google Chrome中的network标签:

 Remote Address:127.0.0.1:8180
 Request URL:http://localhost:8180/GoogleMapsLoadingTest/MainService?   
 scenario=c&operation=1&objkey=000001&objtype=EQUI&gisuniqkey=fsfsfsfs2436353535
 Request Method:GET
 Status Code:415 Unsupported Media Type
 Request Headersview source
 Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
 Accept-Encoding:gzip,deflate,sdch
 Accept-Language:en-US,en;q=0.8,en-AU;q=0.6,en-GB;q=0.4,te;q=0.2
 Cache-Control:max-age=0
 Connection:keep-alive
 Cookie:JSESSIONID=6ECE1D6B441026B523FA64E66F869C55
 DNT:1
 Host:localhost:8180
 User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)     
 Chrome/34.0.1847.132 Safari/537.36
 Query String Parametersview sourceview URL encoded
 scenario:c
 operation:1
 objkey:000001
 objtype:EQUI
 gisuniqkey:fsfsfsfs2436353535
 Response Headersview source
 Content-Length:0
 Date:Sat, 26 Apr 2014 10:48:33 GMT
 Server:Apache-Coyote/1.1     

更新:

删除了代码的所有注释,并将servlet添加到web.xml文件中:

    SEVERE: Servlet /GoogleMapsLoadingTest threw load() exception
    com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
at  com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1274)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1186)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1081)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5320)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
 at java.util.concurrent.FutureTask.run(FutureTask.java:262)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:744)

甚至建议将我的servlet包用作web服务的那个?

1 个答案:

答案 0 :(得分:4)

将@Context属性添加到服务方法的 HttpServletRequest 参数