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

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

Introduction

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

Prototype

public boolean isAbsoluteURI() 

Source Link

Document

Tell whether or not this URI is absolute.

Usage

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java

@Override
public String getHost() {
    try {//from  w  w w.  j a v a 2s  . co m
        final URI uri = this.httpMethod.getURI();
        // if uri have schema
        if (uri.isAbsoluteURI()) {
            return getEndpoint(uri.getHost(), uri.getPort());
        }
        if (this.httpConnection != null) {
            final String host = this.httpConnection.getHost();
            final int port = getPort(this.httpConnection);
            return getEndpoint(host, port);
        }
    } catch (Exception e) {
        if (isDebug) {
            logger.debug("Failed to get host. httpMethod={}", this.httpMethod, e);
        }
    }
    return null;
}

From source file:com.navercorp.pinpoint.plugin.httpclient3.interceptor.HttpMethodBaseExecuteMethodInterceptor.java

private String getHost(HttpMethod httpMethod, HttpConnection httpConnection) {
    try {/*from  w ww. ja  v a 2 s .  co m*/
        final URI uri = httpMethod.getURI();
        // if uri have schema
        if (uri.isAbsoluteURI()) {
            return HttpClient3RequestWrapper.getEndpoint(uri.getHost(), uri.getPort());
        }
        if (httpConnection != null) {
            final String host = httpConnection.getHost();
            final int port = HttpClient3RequestWrapper.getPort(httpConnection);
            return HttpClient3RequestWrapper.getEndpoint(host, port);
        }
    } catch (Exception e) {
        if (isDebug) {
            logger.debug("Failed to get host. httpMethod={}", httpMethod, e);
        }
    }
    return null;
}

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java

@Override
public String getDestinationId() {
    try {//from  w w w.j a va 2  s. com
        final URI uri = this.httpMethod.getURI();
        // if uri have schema or not found HttpConnection argument.
        if (uri.isAbsoluteURI() || this.httpConnection == null) {
            return getEndpoint(uri.getHost(), uri.getPort());
        }
        final String host = this.httpConnection.getHost();
        final int port = getPort(this.httpConnection);
        return getEndpoint(host, port);
    } catch (Exception e) {
        if (isDebug) {
            logger.debug("Failed to get destinationId. httpMethod={}", this.httpMethod, e);
        }
    }
    return "unknown";
}

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java

@Override
public String getUrl() {
    try {/*from  w w  w  .j av a 2 s  .c  om*/
        final URI uri = this.httpMethod.getURI();
        // if uri have schema or not found HttpConnection argument.
        if (uri.isAbsoluteURI() || this.httpConnection == null) {
            return uri.getURI();
        }
        final String host = this.httpConnection.getHost();
        final int port = getPort(this.httpConnection);
        return getHttpUrl(host, port, uri, this.httpConnection);
    } catch (Exception e) {
        if (isDebug) {
            logger.debug("Failed to get url. httpMethod={}", this.httpMethod, e);
        }
    }
    return null;
}

From source file:com.dragonflow.StandardMonitor.URLMonitor.java

public static String resolveURL(String s, URLInfo urlinfo, String s1) {
    s = TextUtils.removeChars(s, "\n\r");
    s = s.trim();// w w w .ja  va2  s  .c om
    String s2 = urlinfo.getPort();
    if (s2.length() > 0) {
        s2 = ":" + s2;
    }
    boolean flag = true;
    int i = s.indexOf(':');
    if (i != -1) {
        String s3 = s.substring(0, i);
        String s4 = s3.toLowerCase();
        if (TextUtils.onlyChars(s4, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
            flag = false;
        }
        if ((s4.equals("http") || s4.equals("https")) && !s.startsWith(s3 + "://")) {
            flag = true;
        }
    } else if (s.startsWith("//")) {
        flag = false;
        s = urlinfo.getProtocol() + ":" + s;
    }
    if (flag) {
        if (TextUtils.startsWithIgnoreCase(s, "http:") || TextUtils.startsWithIgnoreCase(s, "https:")) {
            int j = s.indexOf(":");
            s = s.substring(j + 1);
        }
        if (s.startsWith("/")) {
            if (s1.length() > 0) {
                if (!s1.endsWith("/")) {
                    s1 = s1 + "/";
                }
                URLInfo urlinfo1 = new URLInfo(s1);
                String s5 = urlinfo1.getPort();
                if (s5.length() > 0) {
                    s5 = ":" + s5;
                }
                s = urlinfo1.getProtocol() + "://" + urlinfo1.getHost() + s5 + s;
            } else {
                s = urlinfo.getProtocol() + "://" + urlinfo.getHost() + s2 + s;
            }
        } else if (s1.length() == 0) {
            s1 = urlinfo.getFile();
            int k = s1.lastIndexOf("/");
            int l = s1.indexOf("?");
            if (l >= 0 && k > l) {
                k = s1.lastIndexOf("/", l);
            }
            if (k >= 0 && k < s1.length() - 1) {
                s1 = s1.substring(0, k + 1);
            }
            if (!s1.endsWith("/")) {
                s1 = s1 + "/";
            }
            s = urlinfo.getProtocol() + "://" + urlinfo.getHost() + s2 + s1 + s;
        } else {
            if (!s1.endsWith("/")) {
                s1 = s1 + "/";
            }
            s = s1 + s;
        }
    }
    s = stripDotDot(s);
    s = stripDotSlash(s);
    s = TextUtils.removeChars(s, "\n\r");
    s = s.trim();
    try {
        URI uri = new URI(s.toCharArray());
        if (!$assertionsDisabled && !uri.isAbsoluteURI()) {
            throw new AssertionError("The url is not complete for the redirect: " + s);
        }
        int i1 = uri.getPort();
        if (uri.getHost().equalsIgnoreCase(urlinfo.getHost()) && urlinfo.getPort().length() > 0 && i1 == -1) {
            int j1 = s.indexOf(uri.getHost()) + uri.getHost().length();
            String s6 = s.substring(0, j1);
            String s7 = s.substring(j1);
            if (!$assertionsDisabled && s7.startsWith(":")) {
                throw new AssertionError("This url already has port: " + s);
            }
            s = s6 + ":" + urlinfo.getPort() + s7;
        }
    } catch (URIException uriexception) {
    } catch (Exception exception) {
        LogManager.log("Error", "URLMonitor.resolveURL: URL: " + s + " Had exception: " + exception.toString());
    }
    return s;
}

From source file:org.parosproxy.paros.core.spider.Base.java

protected void buildAttrs(String attrs) {
    super.buildAttrs(attrs);

    String tmp = parserAttrHref.getValue(attrs);
    try {/*from  w  w w. ja va  2  s.c  o m*/
        URI uri = new URI(tmp, false);
        if (uri.isAbsoluteURI()) {
            href = tmp;
        }
    } catch (Exception e) {
    }

}

From source file:smartrics.rest.fitnesse.fixture.support.http.URIBuilder.java

@SuppressWarnings("deprecation")
public void setURI(org.apache.commons.httpclient.HttpMethodBase m, URI uri) throws URIException {
    HostConfiguration conf = m.getHostConfiguration();
    if (uri.isAbsoluteURI()) {
        conf.setHost(new HttpHost(uri));
        m.setHostConfiguration(conf);//w w w  .  ja v a2  s  . c  o m
    }
    m.setPath(uri.getPath() != null ? uri.getEscapedPath() : "/");
    m.setQueryString(uri.getQuery());
}