我试图使用CXF(版本3.1.3)客户端使用PATCH方法调用API。
尝试按照以下线程中指定的步骤但无法解决。 只获取URLConnectionHttpConduit而不是AsyncHttpConduit
http://cxf.apache.org/docs/asynchronous-client-http-transport.html
How to use PATCH method in CXF
Verifying CXF HttpAsyncClient use of use.async.http.conduit contextual property
以下是代码段:
Runpath Search Paths
我甚至尝试使用带有POST请求的X-HTTP-Method-Override = PATCH标头
使用RestEasy实现其他辅助服务,并且看起来不尊重X-HTTP-Method-Override标头。
你能帮我找到问题吗?
答案 0 :(得分:2)
当我们遇到类似的问题时,我们使用了CloseableHttpAsyncClient
,它运行正常。以下是供您参考的示例代码:
IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setIoThreadCount(10).build();
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(ioReactor);
cm.setMaxTotal(100);
cm.setDefaultMaxPerRoute(10);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(30000)
.setSocketTimeout(30000).build();
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setConnectionManager(cm)
.setConnectionManagerShared(false)
.setDefaultRequestConfig(requestConfig)
.build();
httpclient.start();
HttpPatch httpReq = new HttpPatch(url);
StringEntity entity = new StringEntity(json);
httpReq.setEntity(entity);
Future<HttpResponse> future = httpclient.execute(httpReq, context, null);
HttpResponse httpResponse = future.get();
HttpEntity responseEntity = httpResponse.getEntity();
String responseText = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
您可以参考link了解更多详情。