Search in sources :

Example 1 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project Openfire by igniterealtime.

the class UpdateManager method downloadPlugin.

/**
     * Download and install latest version of plugin.
     *
     * @param url the URL of the latest version of the plugin.
     * @return true if the plugin was successfully downloaded and installed.
     */
public boolean downloadPlugin(String url) {
    boolean installed = false;
    // Download and install new version of plugin
    HttpClient httpClient = new HttpClient();
    // Check if a proxy should be used
    if (isUsingProxy()) {
        HostConfiguration hc = new HostConfiguration();
        hc.setProxy(getProxyHost(), getProxyPort());
        httpClient.setHostConfiguration(hc);
    }
    GetMethod getMethod = new GetMethod(url);
    //execute the method
    try {
        int statusCode = httpClient.executeMethod(getMethod);
        if (statusCode == 200) {
            //get the resonse as an InputStream
            try (InputStream in = getMethod.getResponseBodyAsStream()) {
                String pluginFilename = url.substring(url.lastIndexOf("/") + 1);
                installed = XMPPServer.getInstance().getPluginManager().installPlugin(in, pluginFilename);
            }
            if (installed) {
                // Remove the plugin from the list of plugins to update
                for (Update update : pluginUpdates) {
                    if (update.getURL().equals(url)) {
                        update.setDownloaded(true);
                    }
                }
                // Save response in a file for later retrieval
                saveLatestServerInfo();
            }
        }
    } catch (IOException e) {
        Log.warn("Error downloading new plugin version", e);
    }
    return installed;
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) IOException(java.io.IOException)

Example 2 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project tdi-studio-se by Talend.

the class ExchangeUtils method sendGetRequest.

public static String sendGetRequest(String urlAddress) throws Exception {
    HttpClient httpclient = new HttpClient();
    GetMethod getMethod = new GetMethod(urlAddress);
    TransportClientProperties tcp = TransportClientPropertiesFactory.create("http");
    if (tcp.getProxyHost().length() != 0) {
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(tcp.getProxyUser() != null ? tcp.getProxyUser() : "", tcp.getProxyPassword() != null ? tcp.getProxyUser() : "");
        httpclient.getState().setProxyCredentials(AuthScope.ANY, creds);
        HostConfiguration hcf = new HostConfiguration();
        hcf.setProxy(tcp.getProxyHost(), Integer.parseInt(tcp.getProxyPort()));
        httpclient.executeMethod(hcf, getMethod);
    } else {
        httpclient.executeMethod(getMethod);
    }
    String response = getMethod.getResponseBodyAsString();
    getMethod.releaseConnection();
    return response;
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) TransportClientProperties(org.apache.axis.components.net.TransportClientProperties) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 3 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project tdi-studio-se by Talend.

the class WSDLLocatorImpl method createHttpClient.

private HttpClient createHttpClient() {
    HttpClient httpClient = new HttpClient();
    if (configuration.getProxyServer() != null) {
        HostConfiguration hostConfiguration = new HostConfiguration();
        hostConfiguration.setProxy(configuration.getProxyServer(), configuration.getProxyPort());
        httpClient.setHostConfiguration(hostConfiguration);
    }
    if (configuration.getUsername() != null) {
        Credentials credentials = new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword());
        httpClient.getState().setCredentials(AuthScope.ANY, credentials);
    }
    if (configuration.getProxyUsername() != null) {
        Credentials credentials = new UsernamePasswordCredentials(configuration.getProxyUsername(), configuration.getProxyPassword());
        httpClient.getState().setProxyCredentials(AuthScope.ANY, credentials);
        httpClient.getHostConfiguration().setProxy(configuration.getProxyServer(), configuration.getProxyPort());
    }
    return httpClient;
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 4 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project Openfire by igniterealtime.

the class UpdateManager method checkForServerUpdate.

/**
     * Queries the igniterealtime.org server for new server and plugin updates.
     *
     * @param notificationsEnabled true if admins will be notified when new updates are found.
     * @throws Exception if some error happens during the query.
     */
public synchronized void checkForServerUpdate(boolean notificationsEnabled) throws Exception {
    // Get the XML request to include in the HTTP request
    String requestXML = getServerUpdateRequest();
    // Send the request to the server
    HttpClient httpClient = new HttpClient();
    // Check if a proxy should be used
    if (isUsingProxy()) {
        HostConfiguration hc = new HostConfiguration();
        hc.setProxy(getProxyHost(), getProxyPort());
        httpClient.setHostConfiguration(hc);
    }
    PostMethod postMethod = new PostMethod(updateServiceURL);
    NameValuePair[] data = { new NameValuePair("type", "update"), new NameValuePair("query", requestXML) };
    postMethod.setRequestBody(data);
    if (httpClient.executeMethod(postMethod) == 200) {
        // Process answer from the server
        String responseBody = postMethod.getResponseBodyAsString();
        processServerUpdateResponse(responseBody, notificationsEnabled);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 5 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project Openfire by igniterealtime.

the class UpdateManager method checkForPluginsUpdates.

public synchronized void checkForPluginsUpdates(boolean notificationsEnabled) throws Exception {
    // Get the XML request to include in the HTTP request
    String requestXML = getAvailablePluginsUpdateRequest();
    // Send the request to the server
    HttpClient httpClient = new HttpClient();
    // Check if a proxy should be used
    if (isUsingProxy()) {
        HostConfiguration hc = new HostConfiguration();
        hc.setProxy(getProxyHost(), getProxyPort());
        httpClient.setHostConfiguration(hc);
    }
    PostMethod postMethod = new PostMethod(updateServiceURL);
    NameValuePair[] data = { new NameValuePair("type", "available"), new NameValuePair("query", requestXML) };
    postMethod.setRequestBody(data);
    if (httpClient.executeMethod(postMethod) == 200) {
        // Process answer from the server
        String responseBody = postMethod.getResponseBodyAsString();
        processAvailablePluginsResponse(responseBody, notificationsEnabled);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient)

Aggregations

HostConfiguration (org.apache.commons.httpclient.HostConfiguration)8 HttpClient (org.apache.commons.httpclient.HttpClient)8 NameValuePair (org.apache.commons.httpclient.NameValuePair)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 IOException (java.io.IOException)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)1 InputStream (java.io.InputStream)1 TransportClientProperties (org.apache.axis.components.net.TransportClientProperties)1 Credentials (org.apache.commons.httpclient.Credentials)1 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)1 HttpException (org.apache.commons.httpclient.HttpException)1 HttpHost (org.apache.commons.httpclient.HttpHost)1 HttpState (org.apache.commons.httpclient.HttpState)1 ProxyHost (org.apache.commons.httpclient.ProxyHost)1 URI (org.apache.commons.httpclient.URI)1 URIException (org.apache.commons.httpclient.URIException)1 HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1