试图捕获response.body()文本,实际上是xml。
@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 application和in this groovy application中都有上面的代码。当我第一次看到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..
之类的内容,其中常规版本显示[00 11 00 ]
包含一长串数字。
最终,我试图从1个应用程序发送xml并在另一个应用程序上解析它,也许有一种简单得多的方法。目前对于为什么会发生这种奇怪的行为而感到困惑