使用Jersey客户端的漂亮打印XML

时间:2016-04-26 13:01:52

标签: java xml pretty-print jersey-client

如何从Jersey客户端打印XML 响应

现在我在Jersey客户端上使用日志过滤器,并将XML_FORMAT_OUTPUT设置为true,但这只打印请求消息,而不是响应...是否需要以不同的方式处理响应?

我的代码:

ClientConfig config = new ClientConfig();
config.property(MessageProperties.XML_FORMAT_OUTPUT, true); //pretty print xml

Client client = ClientBuilder.newClient(config);
client.register(new LoggingFilter(logger, true)); //enable printing entity in log

我在日志中得到的是:

3 * Sending client request on thread Thread-2
3 > POST http://server:8080/
3 > Accept: application/xml
3 > Content-Type: application/xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<prov>
    <request type="get">
        <list>
            <subscriber id="170"/>
        </list>
    </request>
</prov>


3 * Client response received on thread Thread-2
3 < 200
3 < Access-Control-Allow-Credentials: true
3 < Access-Control-Allow-Headers: x-requested-with, X-Auth-Token, Content-Type
3 < Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
3 < Access-Control-Allow-Origin: *
3 < Access-Control-Max-Age: 3600
3 < Content-Type: application/xml;charset=UTF-8
3 < Date: Tue, 26 Apr 2016 12:40:25 GMT
3 < Server: Apache-Coyote/1.1
3 < Transfer-Encoding: chunked
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><prov><result type="get" failed="true"/></prov>

0 个答案:

没有答案