Search in sources :

Example 36 with HttpClient

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;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Test(org.junit.Test)

Example 37 with HttpClient

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;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Test(org.junit.Test)

Example 38 with HttpClient

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;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpURL(org.apache.commons.httpclient.HttpURL)

Example 39 with HttpClient

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");
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) URL(java.net.URL)

Example 40 with HttpClient

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

Aggregations

HttpClient (org.apache.commons.httpclient.HttpClient)399 GetMethod (org.apache.commons.httpclient.methods.GetMethod)221 PostMethod (org.apache.commons.httpclient.methods.PostMethod)120 HttpMethod (org.apache.commons.httpclient.HttpMethod)98 Test (org.junit.Test)87 IOException (java.io.IOException)82 InputStream (java.io.InputStream)70 HttpException (org.apache.commons.httpclient.HttpException)44 JSONParser (org.json.simple.parser.JSONParser)44 JSONObject (org.json.simple.JSONObject)40 Map (java.util.Map)35 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)25 HttpState (org.apache.commons.httpclient.HttpState)25 ZMailbox (com.zimbra.client.ZMailbox)23 Account (com.zimbra.cs.account.Account)22 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)22 ServiceException (com.zimbra.common.service.ServiceException)21 JSONArray (org.json.simple.JSONArray)21 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)20