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

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

Introduction

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

Prototype

public String getCurrentHierPath() throws URIException 

Source Link

Document

Get the current hierarchy level.

Usage

From source file:com.twinsoft.convertigo.beans.connectors.HttpConnector.java

private String getAbsoluteUrl(HttpMethod method, String givenUrl)
        throws URIException, MalformedURLException, EngineException {
    String absoluteUrl = givenUrl;
    if (method != null) {
        if (givenUrl != null) {
            // givenUrl is already absolute
            if (givenUrl.startsWith("http")) {
                absoluteUrl = givenUrl;/*from www .j  a v  a2s .  co  m*/

                URL url = null;
                String host = "";
                int port = -1;
                if (absoluteUrl.toLowerCase().startsWith("https:")) {
                    if (!https) {
                        Engine.logBeans.debug("(HttpConnector) Setting up SSL properties");
                        certificateManager.collectStoreInformation(context);
                    }

                    url = new URL(absoluteUrl);
                    host = url.getHost();
                    port = url.getPort();
                    if (port == -1)
                        port = 443;

                    Engine.logBeans.debug("(HttpConnector) Host: " + host + ":" + port);

                    Engine.logBeans.debug(
                            "(HttpConnector) CertificateManager has changed: " + certificateManager.hasChanged);
                    if (certificateManager.hasChanged || (!host.equalsIgnoreCase(hostConfiguration.getHost()))
                            || (hostConfiguration.getPort() != port)) {
                        Engine.logBeans
                                .debug("(HttpConnector) Using MySSLSocketFactory for creating the SSL socket");
                        Protocol myhttps = new Protocol("https",
                                MySSLSocketFactory.getSSLSocketFactory(certificateManager.keyStore,
                                        certificateManager.keyStorePassword, certificateManager.trustStore,
                                        certificateManager.trustStorePassword, this.trustAllServerCertificates),
                                port);

                        hostConfiguration.setHost(host, port, myhttps);
                    }

                    // absoluteUrl = url.getFile();
                    Engine.logBeans.debug("(HttpConnector) Updated URL for SSL purposes: " + absoluteUrl);
                } else {
                    url = new URL(absoluteUrl);
                    host = url.getHost();
                    port = url.getPort();

                    Engine.logBeans.debug("(HttpConnector) Host: " + host + ":" + port);
                    hostConfiguration.setHost(host, port);
                }
            }
            // givenUrl is relative to method uri ones
            else {
                URI uri = method.getURI();
                String methodProtocol = uri.getScheme();
                String methodHost = uri.getHost();

                if (hostConfiguration.getProtocol().isSecure()) {
                    return givenUrl.startsWith("/") ? givenUrl : ('/' + givenUrl);
                }

                int methodPort = uri.getPort();
                String path = uri.getCurrentHierPath();
                path = ((path.equals("/") ? "" : path));

                absoluteUrl = methodProtocol + "://" + methodHost;
                if (methodPort != -1) {
                    absoluteUrl += ":" + methodPort;
                }

                if (!givenUrl.startsWith("/") && (path.length() == 0 || !givenUrl.contains(path + "/"))) {
                    absoluteUrl += path + "/" + givenUrl;
                } else {
                    absoluteUrl += givenUrl;
                }
            }
        }
    }
    return absoluteUrl;
}

From source file:phex.util.URLUtil.java

public static String getPathQueryFromUri(URI uri) throws URIException {
    String path;//  w  ww. jav a  2s . c o  m
    String query;
    path = uri.getPath();
    query = uri.getQuery();

    uri.getCurrentHierPath();

    if (query != null && query.length() > 0) {
        return path + '?' + query;
    }

    if (path == null) {
        return "/";
    } else {
        return path;
    }
}

From source file:phex.utils.URLUtil.java

public static String getPathQueryFromUri(URI uri) throws URIException {
    String path;/*  ww w.ja  va 2s  .  c om*/
    String query;
    path = uri.getPath();
    query = uri.getQuery();

    uri.getCurrentHierPath();

    if (query != null && query.length() > 0) {
        return path + "?" + query;
    }

    if (path == null) {
        return "/";
    } else {
        return path;
    }
}