gpt4 book ai didi

java - Micronaut HttpResponse 主体 CompositeByteBuf 类型抛出 io.netty.util.IllegalReferenceCountException : refCnt: 0

转载 作者:行者123 更新时间:2023-12-02 09:13:51 26 4
gpt4 key购买 nike

我正在使用 Micronaut @Client调用返回我响应的外部服务 类型 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 返回 CompositeByteBuf。

b.toString(); //CompositeByteBuf(freed, components=1);

最佳答案

如果您希望 micronaut 保留响应的正文,则必须在客户端中指定正文类型。

例如:

HttpResponse<String> call(String body);

关于java - Micronaut HttpResponse 主体 CompositeByteBuf 类型抛出 io.netty.util.IllegalReferenceCountException : refCnt: 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59169871/

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