Http使用泽西不能正常工作获取Web服务请求

时间:2015-05-20 01:51:00

标签: java web-services rest web.xml jersey-1.0

我知道这个问题已被多次回答并相信我,我已经尝试了所有的解决方案,但我仍然没有运气。 我的所有jar文件都是相同的(jersey-client-1.17,jersey-server-1.17,jersey-multipart-1.17,jersey-servlet-1.17,mimepull-1.6,jersey-json-1.17,jsr311-api-1.1.1)。 服务器端是我的软件包,其中 PostREST 是使用Multipartform实体的rest api。 这是我的堆栈跟踪:

20-May-2015 06:15:47.119 SEVERE [tomcat-http--5] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:147)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

20-May-2015 06:15:47.119 SEVERE [tomcat-http--5] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet jersey.rest
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:147)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

这是我的web.xml:

<servlet>
<servlet-name>jersey.rest</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>serverside</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey.rest</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>`

PostREST课程:

@Path("posts")

公共类PostREST {

Logger log = LogManager.getLogManager().getLogger("PostREST");

@GET
@Path("/{radius}/{lat}/{long}")
@Produces(MediaType.APPLICATION_JSON)
public String getPosts(@PathParam("radius") Double rad, @PathParam("lat") Double lat, @PathParam("long") Double longitude) throws JSONException
{
//  List<Posts> L = DataAccessUtil.getAll(Posts.class);

    List<Posts> L = DataAccessUtil.getPosts(Posts.class, rad, lat, longitude);

    System.out.println("Size: " + L.size());

    JSONObject jobject = new JSONObject();
    JSONArray jposts = new JSONArray();

    for (Posts p : L)
    {
        JSONObject temp = new JSONObject();

        Users tempU = new Users();
        tempU = p.getUsers();

        temp.put("Name", tempU.getUsername());
        temp.put("Post", p.getPost());
        temp.put("Longitude", p.getLongitude());
        temp.put("Latitude", p.getLatitude());
        temp.put("Date", p.getDateCreated());
        temp.put("Radius", p.getRadius());
        temp.put("Post ID", p.getPostId());

        jposts.add(temp);



    }

    jobject.put("Posts", jposts);
//  jobject.put("Comments", jcomments);
    System.out.println("JOBJECT: " + jobject);
    return jobject.toString(); 
}

@POST
@Path("/{name}")
@Consumes("multipart/*")
@Produces(MediaType.APPLICATION_JSON)
public Response addPost(@PathParam("name") String name, @FormDataParam("Content") String jobject, @FormDataParam("exist") String exist, @FormDataParam("extension") String extension, @FormDataParam("length") String length, @FormDataParam("picture") InputStream in) throws JSONException, IOException 
{
System.out.println(jobject);
System.out.println("First Char: " + (int)jobject.trim().charAt(0));
String newstr = jobject.substring(jobject.indexOf('{'));
System.out.println("Now First Char: " + (int)newstr.trim().charAt(0));
JSONObject Obj1 = new JSONObject(newstr);
double lat = Obj1.getDouble("Latitude");
double longitude = Obj1.getDouble( "Longitude" );
String post = Obj1.getString("Post");
double rad = Obj1.getDouble("Radius");

0 个答案:

没有答案