httpClient - > HTTP / 1.1 500内部服务器错误

时间:2013-03-14 22:15:19

标签: java rest httpclient put http-error

当我尝试使用HttpClient在我的REST客户端应用程序中执行PUT / POST时,我总是收到此错误( HTTP / 1.1 500内部服务器错误)。

你知道它可能是什么样的错误吗?这不是代码中的错误吗? 它告诉我在服务器.. 如果你需要我的一些代码,那就请求它!

由于

这是我在服务器日志中收到的消息:

[#|2013-03-15T09:34:32.508+0000|WARNING|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=115;_ThreadName=Thread-2;|StandardWrapperValve[ServletAdaptor]: PWC1406: Servlet.service() for servlet ServletAdaptor threw exception
org.codehaus.jackson.JsonParseException: Unexpected character ('A' (code 65)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: org.apache.catalina.connector.CoyoteInputStream@7fd86c92; line: 1, column: 2]
    at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)
    at org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:2084)
    at org.codehaus.jackson.impl.Utf8StreamParser._nextTokenNotInObject(Utf8StreamParser.java:600)
    at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:486)
    at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2761)
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2682)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
    at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
    at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
    at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
    at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$VoidOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:166)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
|#]

3 个答案:

答案 0 :(得分:2)

您的服务器收到请求,但处理它的逻辑(如果是java,一个servlet)会导致错误。您必须获取服务器日志并查找堆栈跟踪,错误消息等...

答案 1 :(得分:2)

我已经用不同的方式解决了我的问题。

我是这样做的:

    httpPut.addHeader("Accept", "application/json");
    httpPut.addHeader("Content-type", "application/json");

    List <NameValuePair> nvps = new ArrayList <NameValuePair>();

    nvps.add(new BasicNameValuePair("Accept", "application/json"));
    nvps.add(new BasicNameValuePair("Content-Type", "application/json"));

    nvps.add(new BasicNameValuePair("userID", "user1"));
    nvps.add(new BasicNameValuePair("firstName", "teste"));
    nvps.add(new BasicNameValuePair("lastName", "Alves"));

    httpPut.setEntity(new UrlEncodedFormEntity(nvps));

    HttpResponse response = httpclient.execute(httpPut);

现在我这样做了:

        httpPut.addHeader("Content-type", "application/json");
        httpPut.addHeader("Accept", "application/json");

        JSONObject obj = new JSONObject();  
            obj.put("userID", "user1");
            obj.put("firstName", "Antonio");
            obj.put("lastName", "Alves");

        StringEntity se = new StringEntity(obj.toString());
        se.setContentEncoding("UTF-8");
        se.setContentType("application/json");
        httpPut.setEntity(se);

        HttpResponse response = httpclient.execute(httpPut);

一切都很顺利......

答案 2 :(得分:0)

如果您尝试使用HTTP标头解决方案的选项不足,请尝试将以下密钥添加到Windows注册表中的Internet Explorer中,如果您看到“内部服务器错误”之前的“没有此类窗口异常”。以下为我解决了这个问题。

Selenium - NoSuchWindowException in IE 11