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;
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations