Example usage for org.apache.commons.httpclient.protocol Protocol unregisterProtocol

List of usage examples for org.apache.commons.httpclient.protocol Protocol unregisterProtocol

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.protocol Protocol unregisterProtocol.

Prototype

public static void unregisterProtocol(String paramString) 

Source Link

Usage

From source file:com.thoughtworks.go.agent.service.SslInfrastructureServiceTest.java

@After
public void teardown() throws Exception {
    GuidService.deleteGuid();//www.j av  a  2  s  .co m
    Protocol.unregisterProtocol("https");
    SslInfrastructureService.AGENT_CERTIFICATE_FILE.delete();
    SslInfrastructureService.AGENT_TRUST_FILE.delete();
}

From source file:com.twinsoft.convertigo.engine.util.RemoteAdmin.java

public void login(String username, String password) throws RemoteAdminException, EngineException {
    PostMethod loginMethod = null;/*w ww .j a va  2 s .co  m*/

    try {
        String loginServiceURL = (bHttps ? "https" : "http") + "://" + serverBaseUrl
                + "/admin/services/engine.Authenticate";

        Protocol myhttps = null;

        hostConfiguration = httpClient.getHostConfiguration();

        if (bHttps) {
            if (bTrustAllCertificates) {
                ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
                myhttps = new Protocol("https", socketFactory, serverPort);
                Protocol.registerProtocol("https", myhttps);

                hostConfiguration.setHost(host, serverPort, myhttps);
            }
        }

        if (("").equals(username) || username == null) {
            throw new RemoteAdminException(
                    "Unable to connect to the Convertigo server: \"Server administrator\" field is empty.");
        }
        if (("").equals(password) || password == null) {
            throw new RemoteAdminException(
                    "Unable to connect to the Convertigo server: \"Password\" field is empty.");
        }

        URL url = new URL(loginServiceURL);

        HttpState httpState = new HttpState();
        httpClient.setState(httpState);
        // Proxy configuration
        Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url);

        loginMethod = new PostMethod(loginServiceURL);
        loginMethod.addParameter("authType", "login");
        loginMethod.addParameter("authUserName", username);
        loginMethod.addParameter("authPassword", password);

        int returnCode = httpClient.executeMethod(loginMethod);
        String httpResponse = loginMethod.getResponseBodyAsString();

        if (returnCode == HttpStatus.SC_OK) {
            Document domResponse;
            try {
                DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                domResponse = parser.parse(new InputSource(new StringReader(httpResponse)));
                domResponse.normalize();

                NodeList nodeList = domResponse.getElementsByTagName("error");

                if (nodeList.getLength() != 0) {
                    throw new RemoteAdminException(
                            "Unable to connect to the Convertigo server: wrong username or password.");
                }
            } catch (ParserConfigurationException e) {
                throw new RemoteAdminException("Unable to parse the Convertigo server response: \n"
                        + e.getMessage() + ".\n" + "Received response: " + httpResponse);
            } catch (IOException e) {
                throw new RemoteAdminException(
                        "An unexpected error has occured during the Convertigo server login.\n"
                                + "(IOException) " + e.getMessage() + "\n" + "Received response: "
                                + httpResponse,
                        e);
            } catch (SAXException e) {
                throw new RemoteAdminException("Unable to parse the Convertigo server response: "
                        + e.getMessage() + ".\n" + "Received response: " + httpResponse);
            }
        } else {
            decodeResponseError(httpResponse);
        }
    } catch (HttpException e) {
        throw new RemoteAdminException("An unexpected error has occured during the Convertigo server login.\n"
                + "Cause: " + e.getMessage(), e);
    } catch (UnknownHostException e) {
        throw new RemoteAdminException(
                "Unable to find the Convertigo server (unknown host): " + e.getMessage());
    } catch (IOException e) {
        String message = e.getMessage();

        if (message.indexOf("unable to find valid certification path") != -1) {
            throw new RemoteAdminException(
                    "The SSL certificate of the Convertigo server is not trusted.\nPlease check the 'Trust all certificates' checkbox.");
        } else
            throw new RemoteAdminException(
                    "Unable to reach the Convertigo server: \n" + "(IOException) " + e.getMessage(), e);
    } catch (GeneralSecurityException e) {
        throw new RemoteAdminException(
                "Unable to reach the Convertigo server: \n" + "(GeneralSecurityException) " + e.getMessage(),
                e);
    } finally {
        Protocol.unregisterProtocol("https");
        if (loginMethod != null)
            loginMethod.releaseConnection();
    }
}

From source file:com.twinsoft.convertigo.engine.util.RemoteAdmin.java

public void deployArchive(File archiveFile, boolean bAssembleXsl) throws RemoteAdminException {

    String deployServiceURL = (bHttps ? "https" : "http") + "://" + serverBaseUrl
            + "/admin/services/projects.Deploy?bAssembleXsl=" + bAssembleXsl;

    PostMethod deployMethod = null;/*from   ww  w.  j av  a2  s. c o m*/
    Protocol myhttps = null;

    try {
        if (bHttps && bTrustAllCertificates) {
            ProtocolSocketFactory socketFactory = MySSLSocketFactory.getSSLSocketFactory(null, null, null, null,
                    true);
            myhttps = new Protocol("https", socketFactory, serverPort);
            Protocol.registerProtocol("https", myhttps);

            hostConfiguration = httpClient.getHostConfiguration();
            hostConfiguration.setHost(host, serverPort, myhttps);
            httpClient.setHostConfiguration(hostConfiguration);
        }

        deployMethod = new PostMethod(deployServiceURL);

        Part[] parts = { new FilePart(archiveFile.getName(), archiveFile) };
        deployMethod.setRequestEntity(new MultipartRequestEntity(parts, deployMethod.getParams()));

        int returnCode = httpClient.executeMethod(deployMethod);
        String httpResponse = deployMethod.getResponseBodyAsString();

        if (returnCode == HttpStatus.SC_OK) {
            Document domResponse;
            try {
                DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                domResponse = parser.parse(new InputSource(new StringReader(httpResponse)));
                domResponse.normalize();

                NodeList nodeList = domResponse.getElementsByTagName("error");

                if (nodeList.getLength() != 0) {
                    Element errorNode = (Element) nodeList.item(0);

                    Element errorMessage = (Element) errorNode.getElementsByTagName("message").item(0);

                    Element exceptionName = (Element) errorNode.getElementsByTagName("exception").item(0);

                    Element stackTrace = (Element) errorNode.getElementsByTagName("stacktrace").item(0);

                    if (errorMessage != null) {
                        throw new RemoteAdminException(errorMessage.getTextContent(),
                                exceptionName.getTextContent(), stackTrace.getTextContent());
                    } else {
                        throw new RemoteAdminException(
                                "An unexpected error has occured during the Convertigo project deployment: \n"
                                        + "Body content: \n\n"
                                        + XMLUtils.prettyPrintDOMWithEncoding(domResponse, "UTF-8"));
                    }
                }
            } catch (ParserConfigurationException e) {
                throw new RemoteAdminException("Unable to parse the Convertigo server response: \n"
                        + e.getMessage() + ".\n" + "Received response: " + httpResponse);
            } catch (IOException e) {
                throw new RemoteAdminException(
                        "An unexpected error has occured during the Convertigo project deployment.\n"
                                + "(IOException) " + e.getMessage() + "\n" + "Received response: "
                                + httpResponse,
                        e);
            } catch (SAXException e) {
                throw new RemoteAdminException("Unable to parse the Convertigo server response: "
                        + e.getMessage() + ".\n" + "Received response: " + httpResponse);
            }
        } else {
            decodeResponseError(httpResponse);
        }
    } catch (HttpException e) {
        throw new RemoteAdminException(
                "An unexpected error has occured during the Convertigo project deployment.\n" + "Cause: "
                        + e.getMessage(),
                e);
    } catch (IOException e) {
        throw new RemoteAdminException(
                "Unable to reach the Convertigo server: \n" + "(IOException) " + e.getMessage(), e);
    } catch (Exception e) {
        throw new RemoteAdminException(
                "Unable to reach the Convertigo server: \n" + "(Exception) " + e.getMessage(), e);
    } finally {
        Protocol.unregisterProtocol("https");
        if (deployMethod != null)
            deployMethod.releaseConnection();
    }
}

From source file:org.helios.collector.url.URLCollector.java

/**
 * Unregisters any custom Protocol set for this instance
 *///  ww  w. ja va 2s  .c  o m
public void stopCollector() {
    if (myProtocolPrefix != null) {
        Protocol.unregisterProtocol(myProtocolPrefix);
    }
    if (getMethod != null) {
        getMethod.releaseConnection();
    } else if (postMethod != null) {
        postMethod.releaseConnection();
    }
}