Example usage for org.apache.commons.httpclient.contrib.ssl EasySSLProtocolSocketFactory EasySSLProtocolSocketFactory

List of usage examples for org.apache.commons.httpclient.contrib.ssl EasySSLProtocolSocketFactory EasySSLProtocolSocketFactory

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.contrib.ssl EasySSLProtocolSocketFactory EasySSLProtocolSocketFactory.

Prototype

public EasySSLProtocolSocketFactory() 

Source Link

Document

Constructor for EasySSLProtocolSocketFactory.

Usage

From source file:org.switchyard.quickstarts.demo.policy.security.wss.username.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);//from w ww  . ja v a 2 s .c o  m
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            scheme = "https";
            port = 8443;
            Protocol.registerProtocol("https",
                    new Protocol("https", (ProtocolSocketFactory) (new EasySSLProtocolSocketFactory()), port));
        } else {
            scheme = "http";
            port = 8080;
        }
        String usernameToken = policies.contains(CLIENT_AUTHENTICATION)
                ? new StringPuller().pull("/xml/UsernameToken.xml")
                : null;
        invokeWorkService(scheme, port, usernameToken);
    }
}

From source file:org.wso2.carbon.andes.authentication.andes.oauth.OAuthTokenValidaterStubFactory.java

/**
 * This is required to create a trusted connection with the external entity.
 * Have to manually configure it since we use CommonHTTPTransport(axis2 transport) in axis2.
 * @return an EasySSLProtocolSocketFactory for SSL communication.
 *//*w w  w. ja va2 s.  c o m*/
private EasySSLProtocolSocketFactory createProtocolSocketFactory() throws OAuthTokenValidationException {
    try {
        EasySSLProtocolSocketFactory easySSLPSFactory = new EasySSLProtocolSocketFactory();
        JKSStore jksKeyStore = OAuthConfigurationManager.getInstance().getJksKeyStore();
        String keyStoreLocation = jksKeyStore.getStoreLocation();
        char[] password = jksKeyStore.getPassword().toCharArray();
        File keyStoreFile = new File(keyStoreLocation);
        if (keyStoreFile.exists()) {
            KeyMaterial km = new KeyMaterial(keyStoreLocation, password);
            easySSLPSFactory.setKeyMaterial(km);
            return easySSLPSFactory;
        } else {
            String errorMsg = "Unable to load Keystore from the following location: " + keyStoreLocation;
            throw new OAuthTokenValidationException(errorMsg);
        }
    } catch (IOException e) {
        String errorMsg = "Failed to initiate EasySSLProtocolSocketFactory.";
        throw new OAuthTokenValidationException(errorMsg, e);
    } catch (GeneralSecurityException e) {
        String errorMsg = "Failed to set the key material in easy ssl factory.";
        throw new OAuthTokenValidationException(errorMsg, e);
    }
}

From source file:org.wso2.carbon.device.mgt.extensions.remote.session.authentication.oauth.OAuthTokenValidatorStubFactory.java

/**
 * This is required to create a trusted connection with the external entity.
 * Have to manually configure it since we use CommonHTTPTransport(axis2 notification) in axis2.
 *
 * @return an EasySSLProtocolSocketFactory for SSL communication.
 *//*w w  w  .j av  a2 s.  c  om*/
private EasySSLProtocolSocketFactory createProtocolSocketFactory() throws OAuthTokenValidationException {
    try {
        return new EasySSLProtocolSocketFactory();
    } catch (IOException e) {
        String errorMsg = "Failed to initiate EasySSLProtocolSocketFactory.";
        throw new OAuthTokenValidationException(errorMsg, e);
    } catch (GeneralSecurityException e) {
        String errorMsg = "Failed to set the key material in easy ssl factory.";
        throw new OAuthTokenValidationException(errorMsg, e);
    }
}

From source file:org.wso2.iot.integration.common.IOTHttpClient.java

public IOTResponse post(String endpoint, String body) {
    HttpClient client = new HttpClient();
    try {//from  w  w w .j  a  va2  s.  c o  m
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
        Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
        Protocol.registerProtocol(Constants.HTTPS, https);
        String url = backEndUrl + endpoint;
        PostMethod method = new PostMethod(url);
        method.setRequestHeader(AUTHORIZATION, authorizationString);
        StringRequestEntity requestEntity = new StringRequestEntity(body,
                requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8);
        method.setRequestEntity(requestEntity);
        IOTResponse iotResponse = new IOTResponse();
        iotResponse.setStatus(client.executeMethod(method));
        iotResponse.setBody(method.getResponseBodyAsString());
        return iotResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at IOTResponse post for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at IOTResponse post for IOException", e);
    }
    return null;
}

From source file:org.wso2.iot.integration.common.IOTHttpClient.java

public IOTResponse put(String endpoint, String body) {
    HttpClient client = new HttpClient();
    try {/*  w w  w.  j  a va 2 s .  co  m*/
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
        Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
        Protocol.registerProtocol(Constants.HTTPS, https);
        String url = backEndUrl + endpoint;
        PutMethod method = new PutMethod(url);
        method.setRequestHeader(AUTHORIZATION, authorizationString);
        StringRequestEntity requestEntity = new StringRequestEntity(body,
                requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8);
        method.setRequestEntity(requestEntity);
        IOTResponse iotResponse = new IOTResponse();
        iotResponse.setStatus(client.executeMethod(method));
        iotResponse.setBody(method.getResponseBodyAsString());
        return iotResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at IOTResponse put for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at IOTResponse put for IO Exception", e);
    }
    return null;
}

From source file:org.wso2.iot.integration.common.IOTHttpClient.java

public IOTResponse get(String endpoint) {
    HttpClient client = new HttpClient();
    try {/*from  w ww. ja  va 2  s.c  o  m*/
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();

        Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
        Protocol.registerProtocol(Constants.HTTPS, https);
        String url = backEndUrl + endpoint;
        GetMethod method = new GetMethod(url);
        method.setRequestHeader(AUTHORIZATION, authorizationString);
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));
        IOTResponse iotResponse = new IOTResponse();
        iotResponse.setStatus(client.executeMethod(method));
        iotResponse.setBody(new String(method.getResponseBody()));
        return iotResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at IOTResponse get for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at IOTResponse get for IOException", e);
    }

    return null;
}

From source file:org.wso2.iot.integration.common.IOTHttpClient.java

public IOTResponse delete(String endpoint) {

    HttpClient client = new HttpClient();

    try {/*from  w  w w.ja  v  a  2s  .  c  om*/
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();

        Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
        Protocol.registerProtocol(Constants.HTTPS, https);

        String url = backEndUrl + endpoint;

        DeleteMethod method = new DeleteMethod(url);
        method.setRequestHeader(AUTHORIZATION, authorizationString);
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));

        IOTResponse iotResponse = new IOTResponse();
        iotResponse.setStatus(client.executeMethod(method));
        iotResponse.setBody(method.getResponseBodyAsString());
        return iotResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at IOTResponse delete for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at IOTResponse delete for IOException", e);
    }
    return null;
}

From source file:org.wso2.mdm.integration.common.MDMHttpClient.java

public MDMResponse post(String endpoint, String body) {
    HttpClient client = new HttpClient();
    try {//from   w w w  . ja va2s . co  m
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
        Protocol https = new Protocol("https", socketFactory, 9443);
        Protocol.registerProtocol("https", https);
        String url = backEndUrl + endpoint;
        PostMethod method = new PostMethod(url);
        method.setRequestHeader(AUTHORIZATION, authrizationString);
        StringRequestEntity requestEntity = new StringRequestEntity(body,
                requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8);
        method.setRequestEntity(requestEntity);
        MDMResponse mdmResponse = new MDMResponse();
        mdmResponse.setStatus(client.executeMethod(method));
        mdmResponse.setBody(method.getResponseBodyAsString());
        return mdmResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at MDMResponse post for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occured at MDMResponse post for IOException", e);
    }
    return null;
}

From source file:org.wso2.mdm.integration.common.MDMHttpClient.java

public MDMResponse put(String endpoint, String body) {
    HttpClient client = new HttpClient();
    try {/*from w w w  .j  av  a 2  s .com*/
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
        Protocol https = new Protocol("https", socketFactory, 9443);
        Protocol.registerProtocol("https", https);
        String url = backEndUrl + endpoint;
        PutMethod method = new PutMethod(url);
        method.setRequestHeader(AUTHORIZATION, authrizationString);
        StringRequestEntity requestEntity = new StringRequestEntity(body,
                requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8);
        method.setRequestEntity(requestEntity);
        MDMResponse mdmResponse = new MDMResponse();
        mdmResponse.setStatus(client.executeMethod(method));
        mdmResponse.setBody(method.getResponseBodyAsString());
        return mdmResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at MDMResponse put for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at MDMResponse put for IO Exception", e);
    }
    return null;
}

From source file:org.wso2.mdm.integration.common.MDMHttpClient.java

public MDMResponse get(String endpoint) {
    HttpClient client = new HttpClient();
    try {/*from   ww  w .  j av  a  2 s . co  m*/
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();

        Protocol https = new Protocol("https", socketFactory, 9443);
        Protocol.registerProtocol("https", https);
        String url = backEndUrl + endpoint;
        GetMethod method = new GetMethod(url);
        method.setRequestHeader(AUTHORIZATION, authrizationString);
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));
        MDMResponse mdmResponse = new MDMResponse();
        mdmResponse.setStatus(client.executeMethod(method));
        mdmResponse.setBody(new String(method.getResponseBody()));
        return mdmResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at MDMResponse get for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at MDMResponse get for IOException", e);
    }

    return null;
}