The following code results in JSON server responses being printed in Dropwizard 0.9.2 and 1.0.2:
return ClientBuilder
.newBuilder()
.build()
.register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true))
For example:
Oct 21, 2016 7:57:42 AM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Client response received on thread main
1 < 401
1 < Connection: keep-alive
1 < Content-Length: 49
1 < Content-Type: text/plain
1 < Date: Fri, 21 Oct 2016 07:57:42 GMT
1 < Server: […]
1 < WWW-Authenticate: Basic realm="[…]"
Credentials are required to access this resource.
javax.ws.rs.NotAuthorizedException: HTTP 401 Unauthorized
However, LoggingFilter
is deprecated in 1.0.2, and it's recommended to use LoggingFeature
instead. In the documentation of LoggingFeature it says that the default verbosity is LoggingFeature.Verbosity.PAYLOAD_TEXT
, so I was expecting the following code to still print JSON server responses in Dropwizard 1.0.2:
return ClientBuilder
.newBuilder()
.build()
.register(new LoggingFeature(Logger.getLogger(getClass().getName())))
Instead the log contains just this:
javax.ws.rs.NotAuthorizedException: HTTP 401 Unauthorized
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…