我想发送byte []到Jersey客户端.这是我的方法.
@POST
@Path("/userinfo/")
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response getResponse(String userID) {
byte[] val=null;
Response rezponse=null;
try {
val=getResponse(userID);//this returns a valid byte []
System.out.println("arry len : "+val.length);
rezponse=Response.ok(val).build();
System.out.println("before response is null : "+(rezponse==null));
} catch (Exception e) {
e.printStackTrace();
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
return rezponse;
}
系统在try块的最后一行中指出rezponse对象不为null,并且返回的字节数组具有数据.但是,这将引发以下异常.
SEVERE: An I/O error has occurred while writing a response message entity to the container output stream.
org.glassfish.jersey.server.internal.process.MappableException: ClientAbortException: java.net.SocketException: Connection reset
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:96)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:574)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:381)
...
这是我的客户要求.
Client client = ClientBuilder.newClient();
WebTarget target = client.target(SERVER_URL);// String:SERVER_URL referes to the path
WebTarget getDomainPath = target.path("userinfo");
Builder getBuilder=getDomainPath.request();
Response response = getBuilder.post(Entity.entity("USER_005",MediaType.APPLICATION_OCTET_STREAM));
byte[] ins = (byte[]) response.getEntity();
我怎么解决这个问题?
解决方法:
好像您的客户端在实际从服务器读取响应之前关闭了套接字