Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ApacheConnectorProvider:Jersey Client 2.5.1_Java_Apache_Rest_Jersey_Jersey Client - Fatal编程技术网

Java ApacheConnectorProvider:Jersey Client 2.5.1

Java ApacheConnectorProvider:Jersey Client 2.5.1,java,apache,rest,jersey,jersey-client,Java,Apache,Rest,Jersey,Jersey Client,参考号:。 我正在尝试使用ApacheConnector作为jersey客户端的连接器。在jersey client和apache connector的2.4.1版本中,客户端似乎工作正常 上述网站上的使用文档有一个注释: Jersey 2.5中更改了此API,其中引入了ConnectorProviderSPI,以便将客户端初始化与连接器实例化分离。因此,从Jersey 2.5开始,无法在Jersey ClientConfig中直接注册连接器实例。必须使用新的ConnectorProvider

参考号:。 我正在尝试使用
ApacheConnector
作为jersey客户端的连接器。在jersey client和apache connector的2.4.1版本中,客户端似乎工作正常

上述网站上的使用文档有一个注释:

Jersey 2.5中更改了此API,其中引入了
ConnectorProvider
SPI,以便将客户端初始化与连接器实例化分离。因此,从Jersey 2.5开始,无法在Jersey ClientConfig中直接注册连接器实例。必须使用新的ConnectorProvider SPI来配置自定义客户端传输连接器


但客户端似乎总是使用默认的
HttpUrlConnection
作为连接器。如何使用为客户端配置的连接器?

将连接器设置为
ClientConfig
而不是其他方式(
ConnectorProvider\getConnector
不应由用户调用,而是由Jersey客户端调用,它是SPI的一部分):


《泽西岛用户指南》-.

对此进行了说明,谢谢。。。我能够让它工作:)。我无法找到默认构造函数是如何被调用的,这就是我试图调用provider.getConnector(client,clientConfig)。我调试了代码,并在运行时调用了相应的连接器。如何在提供程序中设置代理服务器?如果要通过ApacheConnectorProvider使用连接池,请小心。对于<2.29的Jersey版本,它已断开,因为连接没有释放回池。我花了3天时间试图调试一个连接泄漏,结果证明是连接器中的一个bug。
public  Client configureDefaultJerseyClient(String host) throws Exception
{
    String certFilePath = InstallCert.doInstall(host,SSL_PORT,TRUST_STORE_PASSWORD);
    if(EMPTY_STRING.equals(certFilePath))
    {
        throw new Exception("Error while installing certificate for host " + host);
    }
    ClientConfig clientConfig = new ClientConfig();

    /* As the PoolingClientConnectionManager is a deprecated class, the client will
    not support the multithreaded requests. Commenting the code below to avoid using
    deprecated class. In order to test we would be instantiating multiple clients to
    serve the multithreaded requests.*/

    clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager());

    SslConfigurator sslConfig = defaultSslConfigurator(certFilePath);
    clientConfig.property(ApacheClientProperties.SSL_CONFIG, sslConfig);    

    SSLContext sslContext = sslConfig.createSSLContext();
    clientConfig.property(ApacheClientProperties.SSL_CONFIG, sslConfig);

    Client client = ClientBuilder.newBuilder().sslContext(sslContext).build();
    client.register(new MyFilter());
    client.register(new org.glassfish.jersey.filter.LoggingFilter());

    ApacheConnectorProvider provider = new ApacheConnectorProvider();
    provider.getConnector(client, clientConfig);

    return client;
}
ClientConfig clientConfig = new ClientConfig();
clientConfig.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(clientConfig);