Example usage for org.apache.commons.httpclient HttpMethod getURI

List of usage examples for org.apache.commons.httpclient HttpMethod getURI

Introduction

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

Prototype

public abstract URI getURI() throws URIException;

Source Link

Usage

From source file:org.xwiki.xwoot.manager.internal.DefaultXWootManager.java

private Map<String, Object> getStatusMap(String type) {
    String uri = String.format("%s/status?type=%s", getXWootAppAddress(), type);
    HttpMethod method = new GetMethod(uri);
    try {//www  . j  a  v  a 2 s  .co  m
        getLogger().debug("Requesting: " + method.getURI());
        if (client.executeMethod(method) < 400) {
            XStream xstream = new XStream(new DomDriver());
            Map<String, Object> result = (Map<String, Object>) xstream
                    .fromXML(method.getResponseBodyAsStream());
            getLogger().debug("Result: " + result);
            return result;
        }
        getLogger().info("Failed call: " + method.getStatusLine());
    } catch (Exception ex) {
        getLogger().warn("Exception occured while calling [" + uri + "]", ex);
    } finally {
        // Release the connection, since HTTPClient reuses connections for improved performance
        method.releaseConnection();
    }

    return new HashMap<String, Object>();
}

From source file:ws.antonov.config.provider.HttpConfigProvider.java

@Override
public Message.Builder retrieveConfigData(Class<? extends Message> configClass,
        ConfigParamsBuilder.ConfigParamsMap configParams) throws IOException {
    try {/*  ww  w  .ja v a  2s  .  co  m*/
        HttpMethod get = createHttpMethod(computeUrlDestinationFromParams(configParams));
        int result = httpClient.executeMethod(get);
        if (result == 200) {
            ContentType contentType = determineContentType(get);
            return convertMessage(configClass, contentType, get.getResponseBodyAsStream());
        }
        throw new RuntimeException("Did not receive 200-OK response from config provider at " + get.getURI()
                + ", but got " + result + " instead!");
    } catch (Exception e) {
        throw new IOException("Unable to load requested config", e);
    }
}