use of org.apache.commons.httpclient.HttpClient in project zeppelin by apache.
the class DirAccessTest method testDirAccessOk.
@Test
public void testDirAccessOk() throws Exception {
synchronized (this) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "true");
AbstractTestRestApi.startUp();
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
httpClient.executeMethod(getMethod);
AbstractTestRestApi.shutDown();
assert getMethod.getStatusCode() == HttpStatus.SC_OK;
}
}
use of org.apache.commons.httpclient.HttpClient in project zeppelin by apache.
the class DirAccessTest method testDirAccessForbidden.
@Test
public void testDirAccessForbidden() throws Exception {
synchronized (this) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "false");
AbstractTestRestApi.startUp();
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
httpClient.executeMethod(getMethod);
AbstractTestRestApi.shutDown();
assert getMethod.getStatusCode() == HttpStatus.SC_FORBIDDEN;
}
}
use of org.apache.commons.httpclient.HttpClient in project pinot by linkedin.
the class ChangeTableState method execute.
@Override
public boolean execute() throws Exception {
if (_controllerHost == null) {
_controllerHost = NetUtil.getHostAddress();
}
String stateValue = _state.toLowerCase();
if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) {
throw new IllegalArgumentException("Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop");
}
HttpClient httpClient = new HttpClient();
HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName);
url.setQuery("state", stateValue);
GetMethod httpGet = new GetMethod(url.getEscapedURI());
int status = httpClient.executeMethod(httpGet);
if (status != 200) {
throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString());
}
return true;
}
use of org.apache.commons.httpclient.HttpClient in project Openfire by igniterealtime.
the class FaviconServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Create a pool of HTTP connections to use to get the favicons
client = new HttpClient(new MultiThreadedHttpConnectionManager());
HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setConnectionTimeout(2000);
params.setSoTimeout(2000);
// Load the default favicon to use when no favicon was found of a remote host
try {
URL resource = config.getServletContext().getResource("/images/server_16x16.gif");
defaultBytes = getImage(resource.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
// Initialize caches.
missesCache = CacheFactory.createCache("Favicon Misses");
hitsCache = CacheFactory.createCache("Favicon Hits");
}
use of org.apache.commons.httpclient.HttpClient 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;
}
Aggregations