试图捕获实际上是 xml 的 response.body() 文本。
@Get(uri="/testxml")
public String testxml() {
System.out.println("Reading Response body test");
HttpResponse response = streamClient.test();
CompositeByteBuf content = (CompositeByteBuf) response.body();
byte[] bytes = new byte[content.readableBytes()];
int readerIndex = content.readerIndex();
content.getBytes(readerIndex, bytes);
String read = new String(bytes).trim();
//System.out.println("RES"+ read);
return read;
}
我在这个java micronaut 应用程序和这个 groovy 应用程序中都有上面的代码。它出现在我第一次看到 Java 应用程序http://localhost:8081/orders/testxml 时:
<?xml version="1.0" encoding="utf-8"?><current_orders><order><name>a1</name><description>a1</description><price>12.2200000000000006394884621840901672840118408203125</price></order></current_orders>
但是对java的任何额外尝试都会导致
{"message":"Internal Server Error: refCnt: 0"}
并跟踪显示:
Reading Response body test
09:32:04.799 [nioEventLoopGroup-1-8] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: refCnt: 0
io.netty.util.IllegalReferenceCountException: refCnt: 0
at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1446)
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1376)
at io.netty.buffer.AbstractByteBuf.checkDstIndex(AbstractByteBuf.java:1401)
at io.netty.buffer.CompositeByteBuf.getBytes(CompositeByteBuf.java:854)
at io.netty.buffer.CompositeByteBuf.getBytes(CompositeByteBuf.java:44)
at io.netty.buffer.AbstractByteBuf.getBytes(AbstractByteBuf.java:487)
at io.netty.buffer.CompositeByteBuf.getBytes(CompositeByteBuf.java:1744)
at comparison.java.groovy.controller.OrdersController.testxml(OrdersController.java:71)
at comparison.java.groovy.controller.$OrdersControllerDefinition$$exec4.invokeInternal(Unknown Source)
at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:145)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:2401)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:237)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:123)
at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildResultEmitter$13(RoutingInBoundHandler.java:1255)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.internal.operators.flowable.FlowableSwitchIfEmpty.subscribeActual(FlowableSwitchIfEmpty.java:32)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.Flowable.subscribe(Flowable.java:14429)
at io.micronaut.http.context.ServerRequestTracingPublisher.lambda$subscribe$0(ServerRequestTracingPublisher.java:53)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:53)
at io.micronaut.http.context.ServerRequestTracingPublisher.subscribe(ServerRequestTracingPublisher.java:53)
at io.reactivex.internal.operators.flowable.FlowableFromPublisher.subscribeActual(FlowableFromPublisher.java:29)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.Flowable.subscribe(Flowable.java:14426)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:260)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:225)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Groovy 应用程序似乎并没有实际加载任何内容,经过进一步检查,我注意到在 Java 中的原始表示形式为:
byte[] bytes = new byte[content.readableBytes()];
System.out.println("Bytes = "+bytes);
出来的东西就像[h87aa..
groovy 版本显示[00 11 00 ]
一长串数字一样。
最终我试图从一个应用程序发送 xml 并在另一个应用程序上解析它,也许有一个更简单的方法。目前坚持为什么会发生这种奇怪的行为