简体   繁体   中英

Jersey-Server response failed to send byte []

I want to send byte[] to Jersey Client. Here is my approach.

@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;
}

The system out in the last line of try block states the rezponse object is not null and the returning byte array is having data. How ever, this throws exception as following.

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

Here is my Client request.

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

How can I solve this problem?

好像客户端在实际从服务器读取响应之前关闭了套接字

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM