如何在运动衫客户端中覆盖响应标头 [英] How to override response header in jersey client

查看:79
本文介绍了如何在运动衫客户端中覆盖响应标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个球衣客户,我正试图与该客户解组.问题在于远程Web服务将应用程序/八位字节流作为内容类型发送回去,因此Jersey不知道如何解组(我对XML等返回text/html时也遇到类似的错误).我无法更改Web服务.

I have a jersey client that I am trying to unmarshall a response entity with. The problem is the remote web service sends back application/octet-stream as the content type so Jersey does not know how to unmarshall it (I have similar errors with text/html coming back for XML and such). I cannot change the web service.

我想做的是覆盖内容类型,并将其更改为application/json,以便jersey知道要使用哪个编组器.

What I want to do is override the content-type and change it to application/json so jersey will know which marshaller to use.

我无法向json marshaller注册应用程序/八位字节流,因为对于给定的内容类型,我实际上可能会找回各种奇怪的地方.

I cannot register application/octet-stream with the json marshaller as for a given content type I actually might be getting back all kinds of oddities.

推荐答案

正如laz所指出的,ClientFilter是必经之路:

As laz pointed out, ClientFilter is the way to go:

client.addFilter(new ClientFilter() {
    @Override
    public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
        request.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, "application/json");
        return getNext().handle(request);
    }
});

这篇关于如何在运动衫客户端中覆盖响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆