Java 如何在CXF客户端中使用补丁方法

Java 如何在CXF客户端中使用补丁方法,java,web-services,jax-rs,cxf,http-patch,Java,Web Services,Jax Rs,Cxf,Http Patch,我试图使用CXF(3.1.3版)客户端通过补丁方法调用API 尝试按照以下线程中指定的步骤进行操作,但无法解析。 仅获取URLConnectionHttpConductor而不是AsynchttpConductor 以下是代码片段: Bus bus = BusFactory.getDefaultBus(); // insist on the async connector to use PATCH. bus.setProperty(AsyncHTTPConduit.

我试图使用CXF(3.1.3版)客户端通过补丁方法调用API

尝试按照以下线程中指定的步骤进行操作,但无法解析。 仅获取URLConnectionHttpConductor而不是AsynchttpConductor

以下是代码片段:

    Bus bus = BusFactory.getDefaultBus();
    // insist on the async connector to use PATCH.
    bus.setProperty(AsyncHTTPConduit.USE_ASYNC,  
AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
    WebClient webClient = WebClient.create(request.getRestURL());
   WebClient.getConfig(webClient).getBus().setProperty
     (AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
   WebClient.getConfig(webClient).getRequestContext()
       .put(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.
       UseAsyncPolicy.ALWAYS);
    HTTPConduit conduit = (HTTPConduit)WebClient.getConfig(webClient)
                           .getConduit();
    System.out.println(conduit.getClass().getName());

    Response response = webClient.invoke(request.getMethod(), null);
    System.out.println("service response = "+ response); 
我甚至尝试过在POST请求中使用X-HTTP-Method-Override=PATCH header

另一方服务是使用RestEasy实现的,看起来像不遵守X-HTTP-Method-Override头


你能帮我找到问题吗

当我们遇到类似问题时,我们使用了
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;
IOReactorConfig IOReactorConfig=IOReactorConfig.custom().setIoThreadCount(10.build();
ConnectionReactor ioReactor=新的默认ConnectionReactor(ioReactorConfig);
PoolingHttpClientConnectionManager cm=新的PoolingHttpClientConnectionManager(ioReactor);
cm.setMaxTotal(100);
cm.setDefaultMaxPerRoute(10);
RequestConfig RequestConfig=RequestConfig.custom()
.setConnectTimeout(30000)
.setSocketTimeout(30000).build();
CloseableHttpAsyncClient httpclient=HttpAsyncClient.custom()
.setConnectionManager(cm)
.SetConnectionManager共享(false)
.setDefaultRequestConfig(requestConfig)
.build();
httpclient.start();
HttpPatch HttpEq=新的HttpPatch(url);
StringEntity=新的StringEntity(json);
httpReq.setEntity(实体);
Future-Future=httpclient.execute(httpReq,context,null);
HttpResponse HttpResponse=future.get();
HttpEntity responseEntity=httpResponse.getEntity();
字符串responseText=responseEntity!=无效的EntityUtils.toString(responseEntity):null;

有关更多详细信息,请参阅。

您使用的jar版本正确吗?发布jar版本并检查类的源代码(如果有的话)。您是否按照您在文章中引用的问题设置了属性use.async.http.conductor并正确添加了依赖项?是的,正如我已经提到的,我正在设置属性asynchttpconductor.use\u async(use.async.http.conductor)CXF jar版本3.1.3,还添加了hc jar依赖项。我还尝试将属性值设置为不同的值,如TRUE和ALWAYS bus.setProperty(AsynchttpConductor.USE\u ASYNC,AsynchttpConductFactory.UseAynchPolicy.ALWAYS);或bus.setProperty(AsynchttpConductor.USE\u ASYNC,Boolean.TRUE);