Search in sources :

Example 1 with CswsSession

use of org.apache.manifoldcf.csws.CswsSession 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)

Aggregations

NTCredentials (org.apache.http.auth.NTCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)1 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 LaxRedirectStrategy (org.apache.http.impl.client.LaxRedirectStrategy)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1 HttpRequestExecutor (org.apache.http.protocol.HttpRequestExecutor)1 InterruptibleSocketFactory (org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory)1 CswsSession (org.apache.manifoldcf.csws.CswsSession)1