1

我正在使用JAXRSClientFactory实例化 REST 客户端以进行集成测试。

在两次测试之间,我重新启动了我的 Jetty 服务器,并将新的 REST 客户端实例化到相同的 URL。但是,CXF 似乎在使用某种连接池或连接保持活动系统,因为我在重新启动服务器后的第一次测试中遇到连接错误。

我没有在文档中找到任何说明使用连接池的内容:是这样吗?如果是这样,我该如何防止它,或者在测试结束时刷新给定客户端的连接?

4

1 回答 1

3

Dammit,

I finally found how to do it.

here is the code :

import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.transport.http.HTTPConduit;
import static org.apache.cxf.transports.http.configuration.ConnectionType.CLOSE;

...

MyService proxy = JAXRSClientFactory.create("url", MyService.class);

// Disable keep-alive connection
ClientConfiguration config = WebClient.getConfig(proxy);
HTTPConduit conduit = config.getHttpConduit();
conduit.getClient().setConnection(CLOSE);
于 2013-02-11T14:51:46.363 回答