Débora
Débora

Reputation: 5952

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?

Upvotes: 3

Views: 4006

Answers (1)

shlomi33
shlomi33

Reputation: 1568

Seems like your client closed the socket before actually reading the response from the server

Upvotes: 3

Related Questions