Apache http组件服务器连线日志

问题描述 投票:0回答:1

我正在Apache httpcomponents httpcore-4.4.1.jar中的HTTP服务器之上构建一个小型应用程序。我想拥有类似于http客户端连线日志-Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire的日志。到目前为止,检查代码我找不到这种东西,所以我认为我可以自己实现类似的东西。我可以覆盖org.apache.http.impl.BHttpConnectionBase.getSocketInputStream(Socket)getSocketOutputStream,但是不确定如何将新类“插入”服务器。也欢迎您提出其他想法,但是请不要建议使用Wireshark或Fiddler等捕获间歇性的流量。

java logging apache-httpcomponents
1个回答
1
投票

这2个方法可以在扩展org.apache.http.impl.DefaultBHttpServerConnection的类中重写。这个新类需要由覆盖org.apache.http.impl.DefaultBHttpServerConnectionFactory.createConnection(Socket)的类返回,然后可以使用setConnectionFactory方法将其设置为HTTP Server:

final HttpServer server = ServerBootstrap.bootstrap()
            .setConnectionFactory(connectionFactory)
            .setListenerPort(9090)
            .setHttpProcessor(httpProcessor)
            .setSocketConfig(socketConfig)
            .setExceptionLogger(new StdErrorExceptionLogger ())
            .setHandlerMapper(handle_map)
            .create();
    server.start();
© www.soinside.com 2019 - 2024. All rights reserved.