Search in sources :

Example 1 with InterruptibleSocketFactory

use of org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory in project manifoldcf by apache.

the class ElasticSearchConnector method getSession.

protected HttpClient getSession() throws ManifoldCFException {
    if (client == null) {
        int socketTimeout = 900000;
        int connectionTimeout = 60000;
        // Load configuration from parameters
        final ElasticSearchConfig config = new ElasticSearchConfig(params);
        final IKeystoreManager keystoreManager = config.getSSLKeystore();
        final String userName = config.getUserName();
        final String password = config.getPassword();
        final Credentials credentials;
        if (userName != null && userName.length() > 0)
            credentials = new UsernamePasswordCredentials(userName, password);
        else
            credentials = null;
        // Set up ingest ssl if indicated
        SSLConnectionSocketFactory myFactory = null;
        if (keystoreManager != null) {
            myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(keystoreManager.getSecureSocketFactory(), connectionTimeout), NoopHostnameVerifier.INSTANCE);
        } else {
            myFactory = SSLConnectionSocketFactory.getSocketFactory();
        }
        // Set up connection manager
        PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
        poolingConnectionManager.setDefaultMaxPerRoute(1);
        poolingConnectionManager.setValidateAfterInactivity(2000);
        poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
        connectionManager = poolingConnectionManager;
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        if (credentials != null) {
            credentialsProvider.setCredentials(AuthScope.ANY, credentials);
        }
        RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout);
        client = HttpClients.custom().setConnectionManager(connectionManager).setMaxConnTotal(1).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()).setDefaultCredentialsProvider(credentialsProvider).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).build();
    }
    expirationTime = System.currentTimeMillis() + EXPIRATION_INTERVAL;
    return client;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) IKeystoreManager(org.apache.manifoldcf.connectorcommon.interfaces.IKeystoreManager) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with InterruptibleSocketFactory

use of org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory in project manifoldcf by apache.

the class CswsConnector method getSession.

protected void getSession() throws ManifoldCFException, ServiceInterruption {
    getSessionParameters();
    if (hasConnected == false) {
        int socketTimeout = 900000;
        int connectionTimeout = 300000;
        // Set up ingest ssl if indicated
        final SSLConnectionSocketFactory myFactory;
        final javax.net.ssl.SSLSocketFactory mySslFactory;
        if (serverHTTPSKeystore != null) {
            mySslFactory = new InterruptibleSocketFactory(serverHTTPSKeystore.getSecureSocketFactory(), connectionTimeout);
            myFactory = new SSLConnectionSocketFactory(mySslFactory, NoopHostnameVerifier.INSTANCE);
        } else {
            mySslFactory = null;
            myFactory = SSLConnectionSocketFactory.getSocketFactory();
        }
        // Set up connection manager
        PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
        poolingConnectionManager.setDefaultMaxPerRoute(1);
        poolingConnectionManager.setValidateAfterInactivity(2000);
        poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
        connectionManager = poolingConnectionManager;
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        // Set up authentication to use
        if (serverHTTPNTLMDomain != null) {
            credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(serverHTTPNTLMUsername, serverHTTPNTLMPassword, currentHost, serverHTTPNTLMDomain));
        }
        HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager).disableAutomaticRetries().setDefaultRequestConfig(RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout).build()).setDefaultCredentialsProvider(credentialsProvider).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy());
        httpClient = builder.build();
        // Construct the various URLs we need
        final String baseURL = serverProtocol + "://" + serverName + ":" + serverPort;
        final String authenticationServiceURL = baseURL + authenticationServicePath;
        final String documentManagementServiceURL = baseURL + documentManagementServicePath;
        final String contentServiceServiceURL = baseURL + contentServiceServicePath;
        final String memberServiceServiceURL = baseURL + memberServiceServicePath;
        final String searchServiceServiceURL = baseURL + searchServiceServicePath;
        // Build web services connection management object
        if (Logging.connectors.isDebugEnabled()) {
            String passwordExists = (serverPassword != null && serverPassword.length() > 0) ? "password exists" : "";
            Logging.connectors.debug("Csws: Csws Session: Server='" + serverName + "'; port='" + serverPort + "'; user name='" + serverUsername + "'; " + passwordExists);
        }
        // Construct a new csws session object for setting up this session
        cswsSession = new CswsSession(serverUsername, serverPassword, serverHTTPSKeystore, 1000L * 60L * 15L, authenticationServiceURL, documentManagementServiceURL, contentServiceServiceURL, memberServiceServiceURL, searchServiceServiceURL);
        final GetSessionThread t = new GetSessionThread();
        try {
            t.start();
            t.finishUp();
            hasConnected = true;
        } catch (InterruptedException e) {
            t.interrupt();
            throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
        }
    }
    expirationTime = System.currentTimeMillis() + expirationInterval;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) NTCredentials(org.apache.http.auth.NTCredentials) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) CswsSession(org.apache.manifoldcf.csws.CswsSession) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy)

Example 3 with InterruptibleSocketFactory

use of org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory in project manifoldcf by apache.

the class ConfluenceClient method connect.

/**
 * <p>Connect methods used to initialize the underlying client</p>
 * @throws ManifoldCFException
 */
private void connect() throws ManifoldCFException {
    int socketTimeout = 900000;
    int connectionTimeout = 60000;
    javax.net.ssl.SSLSocketFactory httpsSocketFactory = KeystoreManagerFactory.getTrustingSecureSocketFactory();
    SSLConnectionSocketFactory myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(httpsSocketFactory, connectionTimeout), NoopHostnameVerifier.INSTANCE);
    PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
    poolingConnectionManager.setDefaultMaxPerRoute(1);
    poolingConnectionManager.setValidateAfterInactivity(2000);
    poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
    RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout);
    httpClient = HttpClients.custom().setConnectionManager(poolingConnectionManager).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy()).build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 4 with InterruptibleSocketFactory

use of org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory in project manifoldcf by apache.

the class LivelinkConnector method getSession.

protected void getSession() throws ManifoldCFException, ServiceInterruption {
    getSessionParameters();
    if (hasConnected == false) {
        int socketTimeout = 900000;
        int connectionTimeout = 300000;
        // Set up ingest ssl if indicated
        SSLConnectionSocketFactory myFactory = null;
        if (ingestKeystoreManager != null) {
            myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(ingestKeystoreManager.getSecureSocketFactory(), connectionTimeout), NoopHostnameVerifier.INSTANCE);
        } else {
            myFactory = SSLConnectionSocketFactory.getSocketFactory();
        }
        // Set up connection manager
        PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
        poolingConnectionManager.setDefaultMaxPerRoute(1);
        poolingConnectionManager.setValidateAfterInactivity(2000);
        poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
        connectionManager = poolingConnectionManager;
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        // Set up authentication to use
        if (ingestNtlmDomain != null) {
            credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(ingestNtlmUsername, ingestNtlmPassword, currentHost, ingestNtlmDomain));
        }
        HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager).disableAutomaticRetries().setDefaultRequestConfig(RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout).build()).setDefaultCredentialsProvider(credentialsProvider).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy());
        httpClient = builder.build();
        // System.out.println("Connection server object = "+llServer.toString());
        // Establish the actual connection
        int sanityRetryCount = FAILURE_RETRY_COUNT;
        while (true) {
            GetSessionThread t = new GetSessionThread();
            try {
                t.start();
                t.finishUp();
                hasConnected = true;
                break;
            } catch (InterruptedException e) {
                t.interrupt();
                throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
            } catch (RuntimeException e2) {
                sanityRetryCount = handleLivelinkRuntimeException(e2, sanityRetryCount, true);
            }
        }
    }
    expirationTime = System.currentTimeMillis() + expirationInterval;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) NTCredentials(org.apache.http.auth.NTCredentials) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy)

Example 5 with InterruptibleSocketFactory

use of org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory in project manifoldcf by apache.

the class ConfluenceClient method connect.

/**
 * <p>
 * Connect methods used to initialize the underlying client
 * </p>
 *
 * @throws ManifoldCFException
 */
private void connect() throws ManifoldCFException {
    final javax.net.ssl.SSLSocketFactory httpsSocketFactory = KeystoreManagerFactory.getTrustingSecureSocketFactory();
    final SSLConnectionSocketFactory myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(httpsSocketFactory, connectionTimeout), NoopHostnameVerifier.INSTANCE);
    final PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
    poolingConnectionManager.setDefaultMaxPerRoute(1);
    poolingConnectionManager.setValidateAfterInactivity(2000);
    poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
    final RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout);
    httpClient = HttpClients.custom().setConnectionManager(poolingConnectionManager).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy()).build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)5 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)5 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)5 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)5 HttpRequestExecutor (org.apache.http.protocol.HttpRequestExecutor)5 InterruptibleSocketFactory (org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory)5 LaxRedirectStrategy (org.apache.http.impl.client.LaxRedirectStrategy)4 CredentialsProvider (org.apache.http.client.CredentialsProvider)3 RequestConfig (org.apache.http.client.config.RequestConfig)3 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)3 NTCredentials (org.apache.http.auth.NTCredentials)2 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)2 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 IKeystoreManager (org.apache.manifoldcf.connectorcommon.interfaces.IKeystoreManager)1 CswsSession (org.apache.manifoldcf.csws.CswsSession)1