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:com.discursive.jccook.httpclient.CustomSSLExample.java

public static void main(String[] args) throws HttpException, IOException {
    HttpClient client = new HttpClient();
    String url = "https://pericles.symbiont.net/jccook";

    ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
    Protocol https = new Protocol("https", socketFactory, 443);
    Protocol.registerProtocol("https", https);

    HttpMethod method = new GetMethod(url);
    client.executeMethod(method);/*from w ww.j av a2 s  .  c o  m*/
    String response = method.getResponseBodyAsString();
    System.out.println(response);
    method.releaseConnection();
    method.recycle();
}

From source file:edu.umd.cs.submit.CommandLineSubmit.java

public static void main(String[] args) {
    try {//from   w ww. ja v a  2s . c  o m
        Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        File home = args.length > 0 ? new File(args[0]) : new File(".");

        Protocol.registerProtocol("easyhttps", easyhttps);
        File submitFile = new File(home, ".submit");
        File submitUserFile = new File(home, ".submitUser");
        File submitIgnoreFile = new File(home, ".submitIgnore");
        File cvsIgnoreFile = new File(home, ".cvsignore");

        if (!submitFile.canRead()) {
            System.out.println("Must perform submit from a directory containing a \".submit\" file");
            System.out.println("No such file found at " + submitFile.getCanonicalPath());
            System.exit(1);
        }

        Properties p = new Properties();
        p.load(new FileInputStream(submitFile));
        String submitURL = p.getProperty("submitURL");
        if (submitURL == null) {
            System.out.println(".submit file does not contain a submitURL");
            System.exit(1);
        }
        String courseName = p.getProperty("courseName");
        String courseKey = p.getProperty("courseKey");
        String semester = p.getProperty("semester");
        String projectNumber = p.getProperty("projectNumber");
        String authenticationType = p.getProperty("authentication.type");
        String baseURL = p.getProperty("baseURL");

        System.out.println("Submitting contents of " + home.getCanonicalPath());
        System.out.println(" as project " + projectNumber + " for course " + courseName);
        FilesToIgnore ignorePatterns = new FilesToIgnore();
        addIgnoredPatternsFromFile(cvsIgnoreFile, ignorePatterns);
        addIgnoredPatternsFromFile(submitIgnoreFile, ignorePatterns);

        FindAllFiles find = new FindAllFiles(home, ignorePatterns.getPattern());
        Collection<File> files = find.getAllFiles();

        boolean createdSubmitUser = false;
        Properties userProps = new Properties();
        if (submitUserFile.canRead()) {
            userProps.load(new FileInputStream(submitUserFile));
        }
        if (userProps.getProperty("cvsAccount") == null && userProps.getProperty("classAccount") == null
                || userProps.getProperty("oneTimePassword") == null) {
            System.out.println();
            System.out.println(
                    "We need to authenticate you and create a .submitUser file so you can submit your project");

            createSubmitUser(submitUserFile, courseKey, projectNumber, authenticationType, baseURL);
            createdSubmitUser = true;
            userProps.load(new FileInputStream(submitUserFile));
        }

        MultipartPostMethod filePost = createFilePost(p, find, files, userProps);
        HttpClient client = new HttpClient();
        client.setConnectionTimeout(HTTP_TIMEOUT);
        int status = client.executeMethod(filePost);
        System.out.println(filePost.getResponseBodyAsString());
        if (status == 500 && !createdSubmitUser) {
            System.out.println("Let's try reauthenticating you");
            System.out.println();

            createSubmitUser(submitUserFile, courseKey, projectNumber, authenticationType, baseURL);
            userProps.load(new FileInputStream(submitUserFile));
            filePost = createFilePost(p, find, files, userProps);
            client = new HttpClient();
            client.setConnectionTimeout(HTTP_TIMEOUT);
            status = client.executeMethod(filePost);
            System.out.println(filePost.getResponseBodyAsString());
        }
        if (status != HttpStatus.SC_OK) {
            System.out.println("Status code: " + status);
            System.exit(1);
        }
        System.out.println("Submission accepted");
    } catch (Exception e) {
        System.out.println();
        System.out.println("An Error has occured during submission!");
        System.out.println();
        System.out.println("[DETAILS]");
        System.out.println(e.getMessage());
        e.printStackTrace(System.out);
        System.out.println();
    }
}

From source file:edu.isi.misd.tagfiler.security.TagFilerSecurity.java

/**
 * Loads any security settings into the current environment.
 *//*from   ww  w  . j  a va  2s  . c o  m*/
@SuppressWarnings("deprecation")
public static void loadSecuritySettings() {

    // Read whether or not to allow self-signed certificates to be
    // authenticated,
    // if so then load a custom socket factory that allows them to be
    // trusted
    if (Boolean.valueOf(TagFilerProperties.getProperty("tagfiler.security.AllowSelfSignedCerts"))) {
        Protocol https = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        Protocol.registerProtocol("https", https);
    }
}

From source file:de.knurt.heinzelmann.util.urlcontent.HttpsUnsecuredContent.java

@SuppressWarnings("deprecation")
@Override/*from w ww.jav a 2 s.c  om*/
public String getContent(String urlstring) throws IOException, HTTPException {
    Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", easyhttps);

    HttpClient client = new HttpClient();
    GetMethod httpget = new GetMethod(urlstring);
    client.executeMethod(httpget);
    return httpget.getResponseBodyAsString();
}

From source file:com.eviware.soapui.impl.wsdl.support.http.SoapUIEasySSLProtocolSocketFactory.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    String sslConfig = (String) params.getParameter(SoapUIHostConfiguration.SOAPUI_SSL_CONFIG);

    if (StringUtils.isNullOrEmpty(sslConfig)) {
        return enableSocket((SSLSocket) super.createSocket(host, port, localAddress, localPort, params));
    }//  w ww  .  j av a 2  s  . com

    EasySSLProtocolSocketFactory factory = factoryMap.get(sslConfig);
    if (factory != null) {
        return enableSocket((SSLSocket) factory.createSocket(host, port, localAddress, localPort, params));
    }
    try {
        // try to create new factory for specified config
        factory = new EasySSLProtocolSocketFactory();

        int ix = sslConfig.lastIndexOf(' ');
        String keyStore = sslConfig.substring(0, ix);
        String pwd = sslConfig.substring(ix + 1);

        factory.setKeyMaterial(new KeyMaterial(keyStore, pwd.toCharArray()));
        factoryMap.put(sslConfig, factory);

        return enableSocket((SSLSocket) factory.createSocket(host, port, localAddress, localPort, params));
    } catch (Exception gse) {
        SoapUI.logError(gse);
        return enableSocket((SSLSocket) super.createSocket(host, port, localAddress, localPort, params));
    }
}

From source file:de.knurt.fam.template.controller.letter.FamServicePDFResolver.java

/** {@inheritDoc} */
@Override//w ww .  jav  a  2s.com
@SuppressWarnings("deprecation")
// TODO #11 kill uses of deprecations
public PostMethod process(JSONObject datum) {

    // create connection
    Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", easyhttps);

    // request configured fam-service-pdf
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod(this.uri2Service);
    post.setQueryString(QueryStringFactory.get("json", datum.toString()).toString());

    // execute
    try {
        client.executeMethod(post);
    } catch (HttpException e) {
        FamLog.exception(e, 201106131407l);
    } catch (IOException e) {
        FamLog.exception(e, 201106131406l);
    }
    return post;
}

From source file:com.twistbyte.affiliate.HttpUtility.java

public HttpUtility() {

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.getParams().setDefaultMaxConnectionsPerHost(50);
    connectionManager.getParams().setMaxTotalConnections(50);

    httpclient = new HttpClient(connectionManager);

    // connect timeout in 8 seconds
    httpclient.getParams().setParameter("http.connection.timeout", new Integer(8000));
    httpclient.getParams().setParameter("http.socket.timeout", new Integer(300000));

    Protocol protocol = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", protocol);
}

From source file:com.urswolfer.intellij.plugin.gerrit.rest.SslSupport.java

@Nullable
private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host,
        @NotNull HttpClient client, @NotNull URI uri,
        @NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator) throws IOException {
    if (!isCertificateException(e)) {
        throw e;/*from  w w w. java  2 s.co  m*/
    }

    if (isTrusted(host)) {
        // creating a special configuration that allows connections to non-trusted HTTPS hosts
        // see the javadoc to EasySSLProtocolSocketFactory for details
        Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(),
                443);
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(host, 443, easyHttps);
        String relativeUri = new URI(uri.getPathQuery(), false).getURI();
        // it is important to use relative URI here, otherwise our custom protocol won't work.
        // we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
        // and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
        HttpMethod method = methodCreator.convert(relativeUri);
        client.executeMethod(hc, method);
        return method;
    }
    throw e;
}

From source file:ie.pars.nlp.sketchengine.interactions.SKEInteractionsBase.java

/**
 * Create a session id to communicate with the server
 *
 * @return/*from   www  . j a  v  a2 s .c  o  m*/
 */
protected HttpClient getSessionID() {
    String cookie_policy = CookiePolicy.DEFAULT; //use CookiePolicy.BROWSER_COMPATIBILITY in case cookie handling does not work
    HttpClient client = new HttpClient();
    try {
        Protocol.registerProtocol("https",
                new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443));
        client.getHostConfiguration().setHost(rootURL, 80, "http");
        client.getParams().setCookiePolicy(cookie_policy);
    } catch (java.security.GeneralSecurityException | IOException e) {
        e.printStackTrace();
    }
    client.getParams().setCookiePolicy(cookie_policy);
    // retrieve session id
    GetMethod authget = new GetMethod("/login/");
    try {
        int code = client.executeMethod(authget);
    } catch (IOException ex) {
        System.err.println("Error: couldn't retrieve session ID from Sketch Engine server.");
        System.exit(1);
    }
    authget.releaseConnection();
    return client;

}

From source file:fr.unix_experience.owncloud_sms.engine.OCHttpClient.java

public OCHttpClient(Context context, Uri serverURI, String accountName, String accountPassword) {
    super(new MultiThreadedHttpConnectionManager());
    Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", easyhttps);
    _serverURI = serverURI;/*from w ww  . j  av  a2 s.  co  m*/
    _username = accountName;
    _password = accountPassword;
    getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    getParams().setParameter(PARAM_PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    getParams().setParameter(HttpMethodParams.USER_AGENT,
            "nextcloud-phonesync (" + new AndroidVersionProvider(context).getVersionCode() + ")");
}