如何在 Jersey Invocation Builder 中使用 PATCH 方法? [英] how to use PATCH method with Jersey Invocation Builder?

查看:72
本文介绍了如何在 Jersey Invocation Builder 中使用 PATCH 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebTarget webTarget = httpClient.target(url);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON)
                .header(HttpUtils.AUTHORISATION_HEADER_NAME, "Bearer " + theAccessToken);
response = invocationBuilder.put(Entity.json(objectMapper.writeValueAsString(payload)));

httpClient 属于 javax.ws.rs.client.Client 类型并被注入.

httpClient is of type javax.ws.rs.client.Client and gets injected.

invocatioBuilder 实现了 javax.ws.rs.client.Invocation.Builder,但在包 org.glassfish.jersey.client

invocatioBuilder implements javax.ws.rs.client.Invocation.Builder, but is defined in package org.glassfish.jersey.client

invocationBuilder.put、invocationBuilder.post、invocationBuilder.get 都存在并且可以工作,但是这里没有 invocationBuilder.patch - 它丢失了.

invocationBuilder.put, invocationBuilder.post, invocationBuilder.get all exist and work, but here is no invocationBuilder.patch - it's missing.

关于如何打补丁有什么建议吗?

Any suggestions on how to patch?

==== 更新 ====

==== UPDATE ====

经过一番谷歌搜索,球衣客户端似乎不支持补丁.由于我们所有的应用程序 API 调用都是使用 jersey 客户端进行的,因此这有点问题.我想我需要找到一个替代的库、方法和代码来调用补丁,但它也需要支持 OATH 2.0.如果存在这样的库,并且理想情况下有一些示例,您有什么想法吗?

After some googling, it seems that jersey client has no support for patch. As all our apps API calls are made using jersey client, this is a bit of a problem. I assume Ill need to find an alternative library, method and code to call patch, but it needs to support OATH 2.0 also. Any ideas if such a library exists, and, ideally has some examples?

仅供参考,使用 Java 1.8.0_131-b11

FYI, using Java 1.8.0_131-b11

推荐答案

感谢@Paul Samsotha,解决方案如下:

Thanks to @Paul Samsotha, the working solution is this:

WebTarget webTarget = httpClient.target(url);
webTarget.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);

Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON)
                .header(HttpUtils.AUTHORISATION_HEADER_NAME, "Bearer " + theAccessToken);
response = invocationBuilder.method("PATCH", Entity.json(objectMapper.writeValueAsString(payload)));

这篇关于如何在 Jersey Invocation Builder 中使用 PATCH 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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