我有球衣客户端代码如下
public static void callWebServicePost(String xml) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
try {
MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("xml", xml);
System.out.println(service.path("rest").path("path1")
.path("path2")
.accept(MediaType.TEXT_PLAIN)
.post(String.class, formData));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8080/store").build();
}
现在,当我调用方法 callWebServicePost 并将 xml 字符串传递给它时,我得到了跟随异常
java.net.SocketException: Unexpected end of file from server
和堆栈 tarace 如下
com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: Unexpected end of file from server
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
at com.tainosystems.main.WebServiceClient.callWebServicePost(WebServiceClient.java:71)
at com.tainosystems.main.WebServiceClient.main(WebServiceClient.java:99)
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:769)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:766)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:249)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
... 6 more