有人知道在调用 / user 网址后为什么会被列出列出的异常?这很奇怪,因为所有工作都是预期的(上游服务处理来自下游的响应并发送到客户端的响应)。使用Ratpack 1.4.1
。完整代码可用:https://github.com/peterjurkovic/ratpack-demo
修改
我刚刚尝试降级到版本1.3.3
并且使用此版本的Ratpack它没有发生。 Github issue created。
编辑2:
该问题应在下一版1.4.2
中解决。
public class DownstreamUserService {
Logger log = LoggerFactory.getLogger(DownstreamUserService.class);
private HttpClient httpClient;
private ObjectMapper mapper;
private URI downstreamServerUri;
@Inject
public DownstreamUserService(HttpClient httpClient, Config config, ObjectMapper mapper) {
this.httpClient = httpClient;
this.mapper = mapper;
try {
downstreamServerUri = new URI("http://" + config.getHost() + ":" + config.getPort() + "/endpoint");
} catch (URISyntaxException e) {
log.error("",e);
throw new RuntimeException(e);
}
}
public Promise<User> load(){
return httpClient.get( downstreamServerUri )
.onError(e -> log.info("Error",e))
.map( res -> mapper.readValue(res.getBody().getBytes(), User.class));
}
}
服务器
public class App {
static Logger log = LoggerFactory.getLogger(App.class);
public static void main(String[] args) throws Exception {
RatpackServer.start(s -> s
// bindings..
.handlers( chain -> chain
.get("user", c -> {
DownstreamUserService service = c.get(DownstreamUserService.class);
service.load().then( user -> c.render( json(user) ));
})
}
}
堆栈跟踪:
[2016-08-28 22:58:24,979] WARN [ratpack-compute-1-2] i.n.c.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.PrematureChannelClosureException: channel gone inactive with 1 missing response(s)
at io.netty.handler.codec.http.HttpClientCodec$Decoder.channelInactive(HttpClientCodec.java:261)
at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:220)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:255)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:241)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:234)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1329)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:255)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:241)
at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:908)
at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:744)
at io.netty.util.concurrent.SingleThreadEventExecutor.safeExecute(SingleThreadEventExecutor.java:451)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:306)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:877)
at ratpack.exec.internal.DefaultExecController$ExecControllerBindingThreadFactory.lambda$newThread$0(DefaultExecController.java:136)
at ratpack.exec.internal.DefaultExecController$ExecControllerBindingThreadFactory$$Lambda$129/1240843015.run(Unknown Source)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:745)