Example usage for org.apache.commons.httpclient URI toString

List of usage examples for org.apache.commons.httpclient URI toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Get the escaped URI string.

Usage

From source file:com.exalead.io.failover.MonitoredHttpConnectionManager.java

public synchronized void addHost(URI uri, int power) {
    HostState hs = new HostState();
    hs.configuration = new HostConfiguration();
    hs.configuration.setHost(uri);//  w  ww  .  j  av a 2  s. co m

    hs.power = power;

    if (hostsMap.containsKey(hs.configuration)) {
        throw new IllegalArgumentException("Host: " + uri.toString() + " already exists");
    }

    hosts.add(hs);

    for (int i = 0; i < power; i++)
        hostsForSelection.add(hs);

    hostsMap.put(hs.configuration, hs);
    nextToMonitorList.add(hs);
}

From source file:com.zimbra.cs.account.ProvUtil.java

@Override
public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState) {
    console.println("========== SOAP SEND ==========");

    if (debugLevel == SoapDebugLevel.high) {
        try {/*from   www. ja va  2  s  .  c  o  m*/
            URI uri = postMethod.getURI();
            console.println(uri.toString());
        } catch (URIException e) {
            if (verboseMode) {
                e.printStackTrace(errConsole);
            } else {
                console.println("Unable to get request URL, error=" + e.getMessage());
            }
        }

        Header[] headers = postMethod.getRequestHeaders();
        for (Header header : headers) {
            console.println(header.toString().trim()); // trim the ending crlf
        }
        console.println();
    }

    sendStart = System.currentTimeMillis();

    console.println(envelope.prettyPrint());
    console.println("===============================");
}

From source file:org.apache.any23.source.HTTPDocumentSource.java

private String normalize(String uri) throws URISyntaxException {
    try {//from   w w  w. j av a  2  s .  c  o  m
        URI normalized = new URI(uri, DefaultHTTPClient.isUrlEncoded(uri));
        normalized.normalize();
        return normalized.toString();
    } catch (URIException e) {
        LOG.warn("Invalid uri: {}", uri);
        LOG.error("Can not convert URL", e);
        throw new URISyntaxException(uri, e.getMessage());
    }
}

From source file:org.apache.hadoop.hbase.rest.client.Client.java

/**
 * Execute a transaction method given only the path. Will select at random
 * one of the members of the supplied cluster definition and iterate through
 * the list until a transaction can be successfully completed. The
 * definition of success here is a complete HTTP transaction, irrespective
 * of result code.  //from  w w w  .ja  va2s.c  om
 * @param cluster the cluster definition
 * @param method the transaction method
 * @param headers HTTP header values to send
 * @param path the properly urlencoded path
 * @return the HTTP response code
 * @throws IOException
 */
public int executePathOnly(Cluster cluster, HttpMethod method, Header[] headers, String path)
        throws IOException {
    IOException lastException;
    if (cluster.nodes.size() < 1) {
        throw new IOException("Cluster is empty");
    }
    int start = (int) Math.round((cluster.nodes.size() - 1) * Math.random());
    int i = start;
    do {
        cluster.lastHost = cluster.nodes.get(i);
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("http://");
            sb.append(cluster.lastHost);
            sb.append(path);
            URI uri = new URI(sb.toString(), true);
            return executeURI(method, headers, uri.toString());
        } catch (IOException e) {
            lastException = e;
        }
    } while (++i != start && i < cluster.nodes.size());
    throw lastException;
}

From source file:org.apache.hadoop.hbase.stargate.client.Client.java

/**
 * Execute a transaction method given only the path. Will select at random
 * one of the members of the supplied cluster definition and iterate through
 * the list until a transaction can be successfully completed. The
 * definition of success here is a complete HTTP transaction, irrespective
 * of result code.  /*  ww  w.  j  a v a 2 s. c  om*/
 * @param cluster the cluster definition
 * @param method the transaction method
 * @param headers HTTP header values to send
 * @param path the path
 * @return the HTTP response code
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public int executePathOnly(Cluster cluster, HttpMethod method, Header[] headers, String path)
        throws IOException {
    IOException lastException;
    if (cluster.nodes.size() < 1) {
        throw new IOException("Cluster is empty");
    }
    int start = (int) Math.round((cluster.nodes.size() - 1) * Math.random());
    int i = start;
    do {
        cluster.lastHost = cluster.nodes.get(i);
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("http://");
            sb.append(cluster.lastHost);
            sb.append(path);
            URI uri = new URI(sb.toString());
            return executeURI(method, headers, uri.toString());
        } catch (IOException e) {
            lastException = e;
        }
    } while (++i != start && i < cluster.nodes.size());
    throw lastException;
}

From source file:org.apache.jackrabbit.spi2davex.RepositoryServiceImpl.java

/**
 * Creates a new instance of this repository service.
 *
 * @param jcrServerURI The server uri.//ww w.  j a v a  2 s . co  m
 * @param defaultWorkspaceName The default workspace name.
 * @param batchReadConfig The batch read configuration.
 * @param itemInfoCacheSize The size of the item info cache.
 * @param maximumHttpConnections maximumHttpConnections A int &gt;0 defining
 * the maximum number of connections per host to be configured on
 * {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setDefaultMaxConnectionsPerHost(int)}.
 * @throws RepositoryException If an exception occurs.
 */
public RepositoryServiceImpl(String jcrServerURI, String defaultWorkspaceName, BatchReadConfig batchReadConfig,
        int itemInfoCacheSize, int maximumHttpConnections) throws RepositoryException {

    super(jcrServerURI, IdFactoryImpl.getInstance(), NameFactoryImpl.getInstance(),
            PathFactoryImpl.getInstance(), new QValueFactoryImpl(), itemInfoCacheSize, maximumHttpConnections);

    try {
        URI repositoryUri = computeRepositoryUri(jcrServerURI);
        this.jcrServerURI = repositoryUri.toString();
    } catch (URIException e) {
        throw new RepositoryException(e);
    }

    this.defaultWorkspaceName = defaultWorkspaceName;
    if (batchReadConfig == null) {
        this.batchReadConfig = new BatchReadConfig() {
            public int getDepth(Path path, PathResolver resolver) {
                return 0;
            }
        };
    } else {
        this.batchReadConfig = batchReadConfig;
    }
}

From source file:org.apache.webdav.ant.ResourceProperties.java

public void storeProperties(PropFindMethod propFind) throws URIException {
    // for each content element, check resource type and classify
    for (Enumeration e = propFind.getAllResponseURLs(); e.hasMoreElements();) {
        String href = (String) e.nextElement();
        URI uri = new URI(propFind.getURI(), href);

        String key = uri.toString();
        List properties = (List) this.resourceMap.get(key);
        if (properties == null) {
            properties = new ArrayList();
            this.resourceMap.put(key, properties);
        }/* w  w w. j av a2 s . com*/
        for (Enumeration f = propFind.getResponseProperties(href); f.hasMoreElements();) {
            properties.add(f.nextElement());
        }
    }
}

From source file:org.eclipse.smarthome.binding.yahooweather.discovery.YahooWeatherDiscoveryService.java

/**
 * Retrieves the woeid (Where On Earth IDentifier) used for determining the location
 * used in the Yahoo Weather interface/* w w w  .j  a v  a 2  s .  c o m*/
 * @param Coordinate in form latitude,longitude as String
 * @return Json text from woeid service as String 
 */
private String getWoeidData(String coordinate) {
    String query = "SELECT * FROM geo.placefinder WHERE text='" + coordinate + "' and gflags='R'";
    String url = null;
    try {
        URI uri = new URI("https://query.yahooapis.com/v1/public/yql", false);
        uri.setQuery("q=" + query + "&format=json");
        url = uri.toString();
    } catch (Exception e) {
        logger.debug("Error while getting location ID: {}", e.getMessage());
    }
    return downloadData(url);
}

From source file:org.eclipsetrader.yahoo.internal.core.Util.java

public static URL getRSSNewsFeedForSecurity(ISecurity security)
        throws MalformedURLException, URIException, NullPointerException {
    IFeedIdentifier identifier = (IFeedIdentifier) security.getAdapter(IFeedIdentifier.class);
    if (identifier == null) {
        return null;
    }//ww  w  .  j  av a2  s.  co m

    String symbol = getSymbol(identifier);

    URI feedUrl = new URI("http://finance.yahoo.com/rss/headline?s=" + symbol, false);

    return new URL(feedUrl.toString());
}

From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java

/**
 * Attempts a login using the given PostMethod by adding the needed form
 * parameters./*from  w ww  .  java 2  s .c  o m*/
 * 
 * @param postMethod
 *            - the PostMethod with all other needed params already
 *            inserted.
 * @return the response as a String.
 */
public htmlProperty LogIntoWebForm(PostMethod postMethod, String sessionId) {

    String url = null;
    String redirectLocation = null;
    String userId = null;
    String itemPage = null;
    String html = null;
    Status iStatus = new Status();
    htmlProperty loginStatus = new htmlProperty();

    // set the login params

    postMethod.addRequestHeader("Cookie", "III_SESSION_ID=" + sessionId);

    //postMethod.addParameter("submit.x", "0");
    //postMethod.addParameter("submit.y", "0");
    postMethod.addParameter("pat_submit", "xxx");

    // Since login returns a 302, we have to make another GET request after the POST.
    GetMethod getMethod = null;

    try {
        int statusCode = client.executeMethod(postMethod);
        URI uri = postMethod.getURI();
        url = uri.toString();

        // We're redirecting on the first request
        LOG.debug("lenght of postMethod.getResponseBodyAsString(): "
                + postMethod.getResponseBodyAsString().length());

        if (statusCode == 302) {

            LOG.debug("LoginWebForm - Success submited Page (StatusCode = 302)");

            redirectLocation = postMethod.getResponseHeader("Location").getValue();
            //LOG.debug("LoginWebForm - redirectLocation: " + redirectLocation);
            itemPage = strFunction.Rightstr(url, "/");
            //LOG.debug("LoginWebForm - itemPage 1: " + itemPage);
            url = url.substring(0, url.indexOf("/" + itemPage)) + redirectLocation;
            //LOG.debug("LoginWebForm - url: " + url);
            itemPage = strFunction.Rightstr(url, "/");
            //LOG.debug("LoginWebForm - itemPage: " + itemPage);
            int start = url.indexOf(SNo);
            int end = url.indexOf("/" + itemPage);
            userId = url.substring(start, end).replace(SNo, "").replace("/", "");
            //LOG.debug("LoginWebForm - userId: " + userId);               

            getMethod = new GetMethod(url);
            getMethod.addRequestHeader("Cookie", "III_SESSION_ID=" + sessionId);

            statusCode = client.executeMethod(getMethod);
            //LOG.debug("LoginWebForm - Received contents statusCode: " + statusCode);
            if (statusCode == 200) {
                LOG.debug("LoginWebForm - statusCode(" + statusCode + ") - Success received Login page");
                html = getMethod.getResponseBodyAsString();
                //LOG.debug("LoginWebForm - html.length: " + html.length());
                iStatus.returnStatus = true;
                iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - Success";
                loginStatus.recordStatus = iStatus;
                loginStatus.sessionId = sessionId;
                loginStatus.url = url;
                loginStatus.pageItem = itemPage.trim();
                loginStatus.userid = userId;
                loginStatus.html = html;
            } else {
                LOG.debug("LoginWebForm - statusCode(" + statusCode + ") - false received Login page");
                iStatus.returnStatus = false;
                iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - statusCode(" + statusCode
                        + "). " + errorCodeMsg.ErrorMessage(470);
                loginStatus.recordStatus = iStatus;
                loginStatus.sessionId = sessionId;
                loginStatus.url = url;
                loginStatus.pageItem = itemPage;
                loginStatus.userid = userId;
                loginStatus.html = html;
            }
        }
        /*
        else if (statusCode == 200) {
         LOG.debug("LoginWebForm - statusCode(" + statusCode + ") - Success received Login page");
                 
        redirectLocation = postMethod.getResponseHeader("Location").getValue(); 
        //LOG.debug("LoginWebForm - redirectLocation: " + redirectLocation);
        itemPage = strFunction.Rightstr(url, "/");
        //LOG.debug ("LoginWebForm - itemPage 1: " + itemPage);
        url = url.substring(0, url.indexOf("/" + itemPage)) + redirectLocation;
        //LOG.debug("LoginWebForm - url: " + url);
        itemPage = strFunction.Rightstr(url, "/");
        //LOG.debug ("LoginWebForm - itemPage: " + itemPage);
        int start = url.indexOf(SNo);
        int end = url.indexOf("/" + itemPage);
        userId = url.substring(start, end).replace(SNo, "").replace("/", "");
        //LOG.debug("LoginWebForm - userId: " + userId);   
                 
         html = postMethod.getResponseBodyAsString();
         //LOG.debug("LoginWebForm - html.length: " + html.length());
         iStatus.returnStatus = true;
         iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - Success";
         loginStatus.recordStatus = iStatus;
         loginStatus.sessionId = sessionId;
         loginStatus.url = url;
         loginStatus.pageItem = itemPage.trim();
         loginStatus.userid = userId;
         loginStatus.html = html;   
        }
        */
        else {
            LOG.error("LoginWebForm - LDAP False to Login or others false to Login - statusCode(" + statusCode
                    + "). ");
            iStatus.returnStatus = false;
            iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - statusCode(" + statusCode
                    + "). " + errorCodeMsg.ErrorMessage(470);
            loginStatus.recordStatus = iStatus;
            loginStatus.sessionId = sessionId;
            loginStatus.url = url;
            loginStatus.pageItem = itemPage;
            loginStatus.userid = userId;
            loginStatus.html = html;
        }

    } catch (HttpException e1) {
        LOG.error("LoginWebForm - Error! HttpException.");
        //e1.printStackTrace();

        iStatus.returnStatus = false;
        iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - " + errorCodeMsg.ErrorMessage(490);
        loginStatus.recordStatus = iStatus;
        loginStatus.sessionId = sessionId;
        loginStatus.url = url;
        loginStatus.pageItem = itemPage;
        loginStatus.userid = userId;
        loginStatus.html = html;

    } catch (IOException e1) {
        LOG.error("LoginWebForm - Error! IOException.");
        //e1.printStackTrace();

        iStatus.returnStatus = false;
        iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - " + errorCodeMsg.ErrorMessage(480);
        ;
        loginStatus.recordStatus = iStatus;
        loginStatus.sessionId = sessionId;
        loginStatus.url = url;
        loginStatus.pageItem = itemPage;
        loginStatus.userid = userId;
        loginStatus.html = html;

    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
        if (getMethod != null) {
            getMethod.releaseConnection();
        }
    }
    return loginStatus;
}