Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 644
Débora Avatar asked Apr 24 '26 00:04

Débora


1 Answers

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

like image 90
shlomi33 Avatar answered Apr 26 '26 13:04

shlomi33



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!