gpt4 book ai didi

java - Jersey-Server 响应未能发送字节 []

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:23 29 4
gpt4 key购买 nike

我想发送 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 block 最后一行的系统输出表明 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();

我该如何解决这个问题?

最佳答案

看起来您的客户端在实际读取来自服务器的响应之前关闭了套接字

关于java - Jersey-Server 响应未能发送字节 [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25012617/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com