【问题标题】:Camel jetty component logging骆驼码头组件测井
【发布时间】:2016-12-01 10:38:42
【问题描述】:

如何在骆驼中启用 http 日志?我正在使用rest-dsl。我想查看每个请求和响应的 http 标头和正文我的代码:

restConfiguration()
                .component("jetty")
                .host("0.0.0.0")
                .port(port)
                .scheme("https")
                .bindingMode(RestBindingMode.json)
                .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES")
                .dataFormatProperty("json.in.enableFeatures", "FAIL_ON_NULL_FOR_PRIMITIVES")
                .componentProperty("sslKeyPassword", KEYSTORE_PASSWORD)
                .componentProperty("sslKeystore", KEYSTORE)
                .componentProperty("sslPassword", KEYSTORE_PASSWORD)
                .enableCORS(true)
                .componentProperty("traceEnabled", "true")
                // swagger
                .apiContextPath("api-doc")
            .apiProperty("api.title", "Mobile Api").apiProperty("api.version", "v1.0")
            .apiProperty("schemes", "https")
           ;

rest(MOBILE_API_PATH).produces("application/json").consumes("application/json")

            .post("/transaction").type(MobileTransactionRequest.class).outType(MobileTransactionResponse.class)
            .to("direct:mobileTransaction")

【问题讨论】:

    标签: json rest logging apache-camel


    【解决方案1】:

    要启用组件日志记录,您需要创建此 bean:

    <bean id="log" class="org.eclipse.jetty.server.handler.RequestLogHandler">
        <property name="requestLog" ref="jettyLog"/>
    </bean>
    <bean id="jettyLog" class="org.eclipse.jetty.server.Slf4jRequestLog"/>
    

    并像这样配置enpoint:

    jetty:http://0.0.0.0:8040/test?handlers=#log
    

    但默认情况下记录器不会写入正文和所有标题。您应该使用自己的日志逻辑创建扩展 AbstractLifeCycle 并实现 RequestLog 的类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多