Example usage for org.apache.commons.httpclient HttpURL HttpURL

List of usage examples for org.apache.commons.httpclient HttpURL HttpURL

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpURL HttpURL.

Prototype

public HttpURL(String paramString1, String paramString2, String paramString3) throws URIException 

Source Link

Usage

From source file:ch.cyberduck.core.dav.DAVResource.java

public DAVResource(Host host) throws IOException {
    super(host.getProtocol().isSecure() ? new HttpsURL(host.getHostname(), host.getPort(), null)
            : new HttpURL(host.getHostname(), host.getPort(), null));
}

From source file:com.linkedin.pinot.tools.admin.command.ChangeTableState.java

@Override
public boolean execute() throws Exception {
    if (_controllerHost == null) {
        _controllerHost = NetUtil.getHostAddress();
    }/* ww w.j av  a2 s . c o m*/

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

From source file:com.idega.slide.business.IWSlideServiceBean.java

/**
 * Gets the root url for the webdav server with authentication
 *
 * @return//from   w w  w  . ja  va  2  s  .  co m
 */
private HttpURL getWebdavServerURL(UsernamePasswordCredentials credential, String path, String servletPath,
        boolean addSessionId) {
    try {
        String server = getIWApplicationContext().getDomain().getURL();
        if (server == null) {
            return null;
        }

        int port = 80;
        boolean https = false;
        if (server.endsWith(CoreConstants.SLASH)) {
            server = server.substring(0, server.lastIndexOf(CoreConstants.SLASH));
        }
        if (server.startsWith("http://")) {
            server = server.substring(7, server.length());
        }
        if (server.startsWith("https://")) {
            if (getIWMainApplication().getSettings().getBoolean("slide.allow.local.https")) {
                // https protocol when to slide is only enabled when this property is set
                https = true;
            }
            server = server.substring(8, server.length());
        }
        if (server.indexOf(CoreConstants.COLON) != -1) {
            String sPort = server.substring(server.indexOf(CoreConstants.COLON) + 1, server.length());
            port = Integer.parseInt(sPort);
            server = server.substring(0, server.indexOf(CoreConstants.COLON));
        }

        String rootPath = servletPath;
        String realPath = rootPath;
        if (path != null) {
            realPath = rootPath + path;
        }

        HttpURL hrl = https ? new HttpsURL(server, port, realPath) : new HttpURL(server, port, realPath);
        if (credential != null) {
            hrl.setUserinfo(credential.getUserName(), credential.getPassword());
        }

        return hrl;
    } catch (URIException e) {
        throw new IBORuntimeException(e);
    }
}

From source file:org.jahia.modules.jahiademo.filter.StockWidgetFilter.java

/**
 *
 * @param path/*  w ww. ja  v  a2  s. com*/
 * @param params
 * @return
 * @throws RepositoryException
 */
private JSONObject queryGoogleFinanceAPI(final String path, final String... params) throws RepositoryException {
    try {
        final HttpClient httpClient = new HttpClient();
        final HttpURL url = new HttpURL(API_URL, -1, path);

        final Map<String, String> m = new LinkedHashMap<String, String>();
        for (int i = 0; i < params.length; i += 2) {
            m.put(params[i], params[i + 1]);
        }

        url.setQuery(m.keySet().toArray(new String[m.size()]), m.values().toArray(new String[m.size()]));
        final long l = System.currentTimeMillis();
        LOGGER.debug("Start request : " + url);
        final GetMethod httpMethod = new GetMethod(url.toString());
        try {
            httpClient.getParams().setSoTimeout(1000);
            httpClient.executeMethod(httpMethod);
            return new JSONObject(httpMethod.getResponseBodyAsString());
        } finally {
            httpMethod.releaseConnection();
            LOGGER.debug("Request " + url + " done in " + (System.currentTimeMillis() - l) + "ms");
        }
    } catch (java.net.SocketTimeoutException te) {
        LOGGER.warn("Timeout Exception on request to Google Finance API");
        return null;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
}