Micronaut HttpResponse 主体 CompositeByteBuf 类型抛出 io.netty.util.IllegalReferenceCountException: refCnt: 0
Micronaut HttpResponse body CompositeByteBuf type throws io.netty.util.IllegalReferenceCountException: refCnt: 0
我正在使用 Micronaut @Client
调用外部服务 returns 我回应
FullNettyClientHttpResponse
类型,它的正文形式为 CompositeByteBuf(freed, components=1);
我想将 CompositeByteBuf
转换为人类可读的 toString
消息,但它因 IllegalReferenceCountException
而失败。请提供我如何在此处获取短信的建议。
@Client(value = "url")
public interface MyClient {
@Post(consumes = MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_XML)
HttpResponse call(String body);
}
class service{
void method(){
HttpResponse httpResponse = client.call(request);// returns FullNettyClientHttpResponse with body "Optional[CompositeByteBuf(freed, components=1)]"
Optional<CompositeByteBuf> reBody = httpResponse.getBody(CompositeByteBuf.class);
if(reBody.isPresent()){
CompositeByteBuf b=reBody.get();
byte[] req = new byte[b.readableBytes()];
b.readBytes(req);
String body = new String(req, CharsetUtil.UTF_8).substring(0, req.length -
System.getProperty("line.separator").length());
System.out.println("server receive order : " + body);
}
}
我尝试使用 toString 获取消息,但因 IllegalReferenceCountException 而失败。
b.toString(Charset.defaultCharset()); // Method threw 'io.netty.util.IllegalReferenceCountException' exception.
toString returns CompositeByteBuf.
b.toString(); //CompositeByteBuf(freed, components=1);
如果你想让 micronaut 保留响应的主体,你必须在客户端指定主体类型。
例如:
HttpResponse<String> call(String body);
我正在使用 Micronaut @Client
调用外部服务 returns 我回应
FullNettyClientHttpResponse
类型,它的正文形式为 CompositeByteBuf(freed, components=1);
我想将 CompositeByteBuf
转换为人类可读的 toString
消息,但它因 IllegalReferenceCountException
而失败。请提供我如何在此处获取短信的建议。
@Client(value = "url")
public interface MyClient {
@Post(consumes = MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_XML)
HttpResponse call(String body);
}
class service{
void method(){
HttpResponse httpResponse = client.call(request);// returns FullNettyClientHttpResponse with body "Optional[CompositeByteBuf(freed, components=1)]"
Optional<CompositeByteBuf> reBody = httpResponse.getBody(CompositeByteBuf.class);
if(reBody.isPresent()){
CompositeByteBuf b=reBody.get();
byte[] req = new byte[b.readableBytes()];
b.readBytes(req);
String body = new String(req, CharsetUtil.UTF_8).substring(0, req.length -
System.getProperty("line.separator").length());
System.out.println("server receive order : " + body);
}
}
我尝试使用 toString 获取消息,但因 IllegalReferenceCountException 而失败。
b.toString(Charset.defaultCharset()); // Method threw 'io.netty.util.IllegalReferenceCountException' exception.
toString returns CompositeByteBuf.
b.toString(); //CompositeByteBuf(freed, components=1);
如果你想让 micronaut 保留响应的主体,你必须在客户端指定主体类型。
例如:
HttpResponse<String> call(String body);