0

有谁知道为什么在调用/user URL 后会抛出列出的异常?这很奇怪,因为一切都按预期工作(上游服务处理来自下游的响应并将响应发送给客户端)。使用老鼠包1.4.1。完整代码可用:https ://github.com/peterjurkovic/ratpack-demo

编辑: 我刚刚尝试降级到版本1.3.3,但使用这个版本的 Ratpack 并没有发生。Github问题已创建

编辑 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)
4

0 回答 0