2013-03-14 99 views
0

當我嘗試在我的REST客戶端應用程序中使用HttpClient執行PUT/POST時,我總是收到此錯誤(HTTP/1.1 500內部服務器錯誤) 。httpClient - > 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: [email protected]; 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) 
|#] 
+1

你有你的服務應用程序的代碼?我不認爲這可以使用客戶端代碼重現。 – Sachin 2013-03-14 22:17:52

回答

2

你的服務器接收該請求,而是對其進行處理(如果Java中,一個servlet)導致錯誤的邏輯。您必須獲得服務器日誌並查找堆棧跟蹤,錯誤消息等。

+0

我正在使用Glassfish 3.1.2。我怎麼能看到這個? – user2144555 2013-03-14 22:24:09

+0

我以另一種方式解決了這個問題,但是無論如何,請閱讀服務器日誌幫助我。 – user2144555 2013-03-15 11:04:09

2

我已經通過以不同方式執行PUT來解決我的問題。

我在做這樣的:

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); 

而且所有都很好...

0

如果您運行的嘗試使用HTTP Header嘗試解決方案的選項,如果您看到「沒有這樣的窗口例外」,並被500內部服務器錯誤搶先,請嘗試將以下密鑰添加到Windows註冊表中的Internet Explorer。以下解決了我的問題。

Selenium - NoSuchWindowException in IE 11