例外情况是:已经使用Pooling Http Client manager

时间:2015-09-24 13:31:31

标签: java connection client-server

我的下面是创建与服务器的连接池,但我的下面的代码工作正常一段时间,有时会给出以下错误

异常是:已经在java中连接

错误跟踪:

Exception in thread "main" javax.ws.rs.ProcessingException: Already connected
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:233)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:655)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:652)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:652)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:412)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:321)

我的java代码:

SslConfigurator sslConfig = SslConfigurator.newInstance()
            .securityProtocol("TLS")
            .keyStoreFile("/path")
            .keyStorePassword("passw")
            .keyStoreType("JKS")
            .trustStoreFile("/path");

    SSLContext sslCtx = sslConfig.createSSLContext();
HostnameVerifier defaultHostnameVerifier = new DefaultHostnameVerifier();
        LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslConfig.createSSLContext(),
        defaultHostnameVerifier);
        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory> create()
        .register("http", PlainConnectionSocketFactory.getSocketFactory())
        .register("https", sslSocketFactory)
        .build();

        connectionManager = new PoolingHttpClientConnectionManager(registry);
        connectionManager.setMaxTotal(100);
        connectionManager.setDefaultMaxPerRoute(10);
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER,
                connectionManager);
        client = ClientBuilder.newBuilder().withConfig(clientConfig).build();

        Response response = client.target(target).path(path).request(media).post(media);

0 个答案:

没有答案