Example usage for org.apache.commons.httpclient URIException getMessage

List of usage examples for org.apache.commons.httpclient URIException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.parosproxy.paros.core.scanner.VariantURLQuery.java

@Override
protected void buildMessage(HttpMessage msg, String query) {
    try {/*from   w  w  w. j  a v a 2s  .  c  om*/
        // ZAP: encoding has been decided before inside the VariantAbstractQuery
        // implementation so now we have only to set a raw query string
        msg.getRequestHeader().getURI().setEscapedQuery(query);

    } catch (URIException e) {
        log.error(e.getMessage() + query, e);
    }
}

From source file:org.parosproxy.paros.model.SiteMap.java

/**
 * Return the a HttpMessage of the same type under the tree path.
 * @param msg/*  w w w . ja va  2s .  c  o m*/
 * @return   null = not found
 */
public synchronized HttpMessage pollPath(HttpMessage msg) {
    SiteNode resultNode = null;
    URI uri = msg.getRequestHeader().getURI();

    SiteNode parent = (SiteNode) getRoot();
    String folder;

    try {
        String host = getHostName(uri);

        // no host yet
        parent = findChild(parent, host);
        if (parent == null) {
            return null;
        }
        List<String> path = model.getSession().getTreePath(uri);
        if (path.size() == 0) {
            // Its a top level node
            resultNode = parent;
        }
        for (int i = 0; i < path.size(); i++) {
            folder = path.get(i);
            if (folder != null && !folder.equals("")) {
                if (i == path.size() - 1) {
                    String leafName = getLeafName(folder, msg);
                    resultNode = findChild(parent, leafName);
                } else {
                    parent = findChild(parent, folder);
                    if (parent == null) {
                        return null;
                    }
                }
            }
        }
    } catch (URIException e) {
        // ZAP: Added error
        log.error(e.getMessage(), e);
    }

    if (resultNode == null || resultNode.getHistoryReference() == null) {
        return null;
    }

    HttpMessage nodeMsg = null;
    try {
        nodeMsg = resultNode.getHistoryReference().getHttpMessage();
    } catch (Exception e) {
        // ZAP: Added error
        log.error(e.getMessage(), e);
    }
    return nodeMsg;
}

From source file:org.parosproxy.paros.model.SiteMap.java

public synchronized SiteNode findNode(HttpMessage msg, boolean matchStructural) {
    if (Constant.isLowMemoryOptionSet()) {
        throw new InvalidParameterException("SiteMap should not be accessed when the low memory option is set");
    }//ww  w.j a  va  2s .com
    if (msg == null || msg.getRequestHeader() == null) {
        return null;
    }
    SiteNode resultNode = null;
    URI uri = msg.getRequestHeader().getURI();

    SiteNode parent = (SiteNode) getRoot();
    String folder = "";

    try {

        String host = getHostName(uri);

        // no host yet
        parent = findChild(parent, host);
        if (parent == null) {
            return null;
        }

        List<String> path = model.getSession().getTreePath(msg);
        if (path.size() == 0) {
            // Its a top level node
            resultNode = parent;
        }
        for (int i = 0; i < path.size(); i++) {
            folder = path.get(i);
            if (folder != null && !folder.equals("")) {
                if (i == path.size() - 1) {
                    if (matchStructural) {
                        resultNode = findChild(parent, folder);
                    } else {
                        String leafName = getLeafName(folder, msg);
                        resultNode = findChild(parent, leafName);
                    }
                } else {
                    parent = findChild(parent, folder);
                    if (parent == null) {
                        return null;
                    }
                }
            }
        }
    } catch (URIException e) {
        log.error(e.getMessage(), e);
    }

    return resultNode;
}

From source file:org.parosproxy.paros.model.SiteMap.java

public synchronized SiteNode findNode(URI uri, String method, String postData) {
    if (Constant.isLowMemoryOptionSet()) {
        throw new InvalidParameterException("SiteMap should not be accessed when the low memory option is set");
    }/* www. j  ava 2 s  .  c om*/
    SiteNode resultNode = null;
    String folder = "";

    try {
        String host = getHostName(uri);

        // no host yet
        resultNode = findChild((SiteNode) getRoot(), host);
        if (resultNode == null) {
            return null;
        }

        List<String> path = model.getSession().getTreePath(uri);
        for (int i = 0; i < path.size(); i++) {
            folder = path.get(i);

            if (folder != null && !folder.equals("")) {
                if (i == path.size() - 1) {
                    String leafName = getLeafName(folder, uri, method, postData);
                    resultNode = findChild(resultNode, leafName);
                } else {
                    resultNode = findChild(resultNode, folder);
                    if (resultNode == null) {
                        return null;
                    }
                }
            }
        }
    } catch (URIException e) {
        log.error(e.getMessage(), e);
    }

    return resultNode;
}

From source file:org.parosproxy.paros.model.SiteMap.java

public synchronized SiteNode findClosestParent(URI uri) {
    if (uri == null) {
        return null;
    }/*from   www  .  jav a  2  s . com*/
    SiteNode lastParent = null;
    SiteNode parent = (SiteNode) getRoot();
    String folder = "";

    try {
        String host = getHostName(uri);

        // no host yet
        parent = findChild(parent, host);
        if (parent == null) {
            return null;
        }
        lastParent = parent;

        List<String> path = model.getSession().getTreePath(uri);
        for (int i = 0; i < path.size(); i++) {
            folder = path.get(i);
            if (folder != null && !folder.equals("")) {
                if (i == path.size() - 1) {
                    lastParent = parent;
                } else {
                    parent = findChild(parent, folder);
                    if (parent == null) {
                        break;
                    }
                    lastParent = parent;
                }
            }
        }
    } catch (URIException e) {
        log.error(e.getMessage(), e);
    }

    return lastParent;
}

From source file:org.parosproxy.paros.model.SiteMap.java

private String getLeafName(String nodeName, URI uri, String method, String postData) {
    String leafName;//from  w  ww.  j ava2  s. c  o m

    if (method != null) {
        leafName = method + ":" + nodeName;
    } else {
        leafName = nodeName;
    }

    try {
        leafName = leafName + getQueryParamString(model.getSession().getUrlParams(uri));

        // also handle POST method query in body
        if (method != null && method.equalsIgnoreCase(HttpRequestHeader.POST)) {
            leafName = leafName + getQueryParamString(model.getSession().getFormParams(uri, postData));
        }
    } catch (URIException e) {
        // ZAP: Added error
        log.error(e.getMessage(), e);
    }
    return leafName;

}

From source file:org.parosproxy.paros.network.HttpMessage.java

/**
 * Compare if 2 message is the same.  2 messages are the same if:
 * Host, port, path and query param and VALUEs are the same.  For POST request, the body must be the same.
 * @param object/*from  w  w  w.ja  v  a 2  s.co m*/
 * @return
 */
@Override
public boolean equals(Object object) {

    if (!(object instanceof HttpMessage)) {
        return false;
    }

    HttpMessage msg = (HttpMessage) object;
    boolean result = false;

    // compare method
    if (!this.getRequestHeader().getMethod().equalsIgnoreCase(msg.getRequestHeader().getMethod())) {
        return false;
    }

    // compare host, port and URI
    URI uri1 = this.getRequestHeader().getURI();
    URI uri2 = msg.getRequestHeader().getURI();

    if (uri1 == null) {
        if (uri2 != null) {
            return false;
        }
        return true;
    } else if (uri2 == null) {
        return false;
    }

    try {
        if (uri1.getHost() == null || uri2.getHost() == null
                || !uri1.getHost().equalsIgnoreCase(uri2.getHost())) {
            return false;
        }

        if (uri1.getPort() != uri2.getPort()) {
            return false;
        }

        String pathQuery1 = uri1.getPathQuery();
        String pathQuery2 = uri2.getPathQuery();

        if (pathQuery1 == null && pathQuery2 == null) {
            return true;
        } else if (pathQuery1 != null && pathQuery2 != null) {
            return pathQuery1.equalsIgnoreCase(pathQuery2);
        } else if (pathQuery1 == null || pathQuery2 == null) {
            return false;
        }

        if (this.getRequestHeader().getMethod().equalsIgnoreCase(HttpRequestHeader.POST)) {
            return this.getRequestBody().equals(msg.getRequestBody());
        }

        result = true;

    } catch (URIException e) {
        try {
            result = this.getRequestHeader().getURI().toString()
                    .equalsIgnoreCase(msg.getRequestHeader().getURI().toString());
        } catch (Exception e1) {
            // ZAP: log error
            log.error(e.getMessage(), e);
        }
    }

    return result;
}

From source file:org.parosproxy.paros.network.HttpMessage.java

/**
 * 2 messages are equal type if the host, port, path and query names are equal.
 * Even though the query value may differ.
 * @param msg//from w  ww  .  jav a2s .  c  o  m
 * @return
 */
public boolean equalType(HttpMessage msg) {
    boolean result = false;

    // compare method
    if (!this.getRequestHeader().getMethod().equalsIgnoreCase(msg.getRequestHeader().getMethod())) {
        return false;
    }

    // compare host, port and URI
    URI uri1 = this.getRequestHeader().getURI();
    URI uri2 = msg.getRequestHeader().getURI();

    try {
        if (uri1.getHost() == null || uri2.getHost() == null
                || !uri1.getHost().equalsIgnoreCase(uri2.getHost())) {
            return false;
        }

        if (uri1.getPort() != uri2.getPort()) {
            return false;
        }

        String path1 = uri1.getPath();
        String path2 = uri2.getPath();

        if (path1 == null && path2 == null) {
            return true;
        }

        if (path1 != null && path2 != null && !path1.equalsIgnoreCase(path2)) {
            return false;
        } else {
            if (path1 == null || path2 == null) {
                return false;
            }
        }

        if (!queryEquals(msg)) {
            return false;
        }

        result = true;

    } catch (URIException e) {
        // ZAP: log error
        log.error(e.getMessage(), e);
    }

    return result;
}

From source file:org.parosproxy.paros.network.HttpRequestHeader.java

public HttpRequestHeader(String method, URI uri, String version, ConnectionParam params)
        throws HttpMalformedHeaderException {
    this(method + " " + uri.toString() + " " + version.toUpperCase() + CRLF + CRLF);

    try {//  w ww .  ja  v  a 2 s .  c o m
        setHeader(HOST, uri.getHost() + (uri.getPort() > 0 ? ":" + Integer.toString(uri.getPort()) : ""));

    } catch (URIException e) {
        log.error(e.getMessage(), e);
    }

    String userAgent = params != null ? params.getDefaultUserAgent()
            : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;)";
    setHeader(USER_AGENT, userAgent);
    setHeader(PRAGMA, "no-cache");

    // ZAP: added the Cache-Control header field to comply with HTTP/1.1
    if (version.equalsIgnoreCase(HTTP11)) {
        setHeader(CACHE_CONTROL, "no-cache");
    }

    // ZAP: set content type x-www-urlencoded only if it's a POST or a PUT
    if (method.equalsIgnoreCase(POST) || method.equalsIgnoreCase(PUT)) {
        setHeader(CONTENT_TYPE, "application/x-www-form-urlencoded");
    }

    setHeader(ACCEPT_ENCODING, null);

    // ZAP: changed from method to version
    if (version.equalsIgnoreCase(HTTP11)) {
        setContentLength(0);
    }

}

From source file:org.parosproxy.paros.network.HttpRequestHeader.java

/**
 * Return if this request header is a image request basing on the path
 * suffix.//from w  ww  . ja  va  2  s  .  c o  m
 */
@Override
public boolean isImage() {
    try {
        // ZAP: prevents a NullPointerException when no path exists
        final String path = getURI().getPath();
        if (path != null) {
            return (patternImage.matcher(path).find());
        }

    } catch (URIException e) {
        log.error(e.getMessage(), e);
    }

    return false;
}