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

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

Introduction

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

Prototype

public void setQuery(String query) throws URIException 

Source Link

Document

Set the query.

Usage

From source file:org.parosproxy.paros.extension.filter.FilterLogCookie.java

@Override
public void onHttpRequestSend(HttpMessage msg) {
    HttpRequestHeader header = msg.getRequestHeader();

    if (header != null) {
        String cookie = header.getHeader("Cookie");
        synchronized (cookieList) {
            if (cookie != null && cookieList.indexOf(cookie) == -1) {
                try {
                    // ZAP: catch CloneNotSupportedException as introduced with version 3.1 of HttpClient
                    URI uri;
                    try {
                        uri = (URI) header.getURI().clone();
                    } catch (CloneNotSupportedException e) {
                        throw new URIException(e.getMessage());
                    }//from w w  w . j a  va  2s  .  c  o m
                    uri.setQuery(null);
                    String sUri = uri.toString();
                    cookieList.add(cookie);
                    getView().getOutputPanel().append(sUri + DELIM + cookie + "\n");

                } catch (URIException e) {
                    // ZAP: Print stack trace to Output tab
                    getView().getOutputPanel().append(e);
                }
            }
        }
    }
}

From source file:org.parosproxy.paros.extension.filter.FilterLogGetQuery.java

@Override
public void onHttpRequestSend(HttpMessage httpMessage) {

    HttpRequestHeader reqHeader = httpMessage.getRequestHeader();

    if (reqHeader != null && reqHeader.isText() && !reqHeader.isImage()) {
        if (reqHeader.getMethod().equalsIgnoreCase(HttpRequestHeader.GET)) {
            try {

                URI uri = reqHeader.getURI();

                // ZAP: Removed unused variable (int pos).

                String firstline;

                URI newURI = (URI) uri.clone();
                String query = newURI.getQuery();
                if (query != null) {
                    newURI.setQuery(null);
                    firstline = newURI.toString();
                    // ZAP: Added type arguments.
                    Hashtable<String, String> param = parseParameter(query);
                    writeLogFile(firstline, param);
                } else {
                    firstline = uri.toString();
                    writeLogFile(firstline, null);
                }/*from   www.  jav  a  2s  . c  o m*/

            } catch (Exception aa) {
                logger.error(aa.getMessage(), aa);
            }
        }
    }

}

From source file:org.parosproxy.paros.extension.filter.FilterLogPostQuery.java

@Override
public void onHttpRequestSend(HttpMessage httpMessage) {

    HttpRequestHeader reqHeader = httpMessage.getRequestHeader();

    if (reqHeader != null && reqHeader.isText() && !reqHeader.isImage()) {
        if (reqHeader.getMethod().equalsIgnoreCase(HttpRequestHeader.POST)) {
            try {

                URI uri = reqHeader.getURI();

                // ZAP: Removed unused variable (int pos).

                String firstline;

                URI newURI = (URI) uri.clone();
                String query = httpMessage.getRequestBody().toString();
                if (query != null) {
                    newURI.setQuery(null);
                    firstline = newURI.toString();
                    // ZAP: Added type arguments.
                    Hashtable<String, String> param = parseParameter(query);
                    writeLogFile(firstline, param);
                } else {
                    firstline = uri.toString();
                    writeLogFile(firstline, null);
                }//from w w  w .  j a v  a2  s.c o  m

            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }

    }
}

From source file:org.parosproxy.paros.extension.trap.ProxyListenerTrap.java

private boolean isSkipFilter(HttpMessage msg) {

    try {/* w  ww .j  a v  a  2  s. c o  m*/
        URI uri = (URI) msg.getRequestHeader().getURI().clone();
        uri.setQuery(null);
        String sUri = uri.toString();
        if (trapParam.isExclude(sUri)) {
            return true;
        }

        if (!trapParam.isInclude(sUri)) {
            return true;
        }

    } catch (URIException e) {
    }

    return false;
}

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

public void mutateHttpMethod(String method) {
    // String header = reqPanel.getTxtHeader().getText();
    String header = getRequestHeader().toString();
    try {//  w w  w. j  av a 2  s .co  m
        HttpRequestHeader hrh = new HttpRequestHeader(header);

        URI uri = hrh.getURI();
        // String body = reqPanel.getTxtBody().getText();
        String body = getRequestBody().toString();
        String prevMethod = hrh.getMethod();
        if (prevMethod.equalsIgnoreCase(method)) {
            return;
        }
        if (prevMethod.equals(HttpRequestHeader.POST)) {
            // Was POST, move all params onto the URL
            if (body != null && body.length() > 0) {
                StringBuilder sb = new StringBuilder();
                if (uri.getQuery() != null) {
                    sb.append(uri.getQuery());
                }

                String[] params = body.split("&");
                for (String param : params) {
                    if (sb.length() > 0) {
                        sb.append('&');
                    }
                    String[] nv = param.split("=");
                    if (nv.length == 1) {
                        // This effectively strips out the equals if theres
                        // no value
                        sb.append(nv[0]);
                    } else {
                        sb.append(param);
                    }
                }
                uri.setQuery(sb.toString());

            }
            hrh.setURI(uri);
            // Clear the body
            body = "";

        } else if (method.equals(HttpRequestHeader.POST)) {
            // To be a port, move all URL query params into the body
            String query = uri.getQuery();
            if (query != null) {
                StringBuilder sb = new StringBuilder();
                String[] params = query.split("&");
                for (String param : params) {
                    if (sb.length() > 0) {
                        sb.append('&');
                    }
                    sb.append(param);
                    String[] nv = param.split("=");
                    if (nv.length == 1) {
                        // Cope with URL params with no values e.g.
                        // http://www.example.com/test?key
                        sb.append('=');
                    }
                }
                body = sb.toString();
                uri.setQuery(null);
                hrh.setURI(uri);
            }
        }
        hrh.setMethod(method);

        getRequestHeader().setMessage(hrh.toString());
        getRequestBody().setBody(body);
    } catch (HttpMalformedHeaderException e) {
        // Ignore?
        log.error(e.getMessage(), e);
    } catch (URIException e) {
        log.error(e.getMessage(), e);
    }

}

From source file:org.zaproxy.zap.extension.ascanrules.TestDirectoryBrowsing.java

private void checkIfDirectory(HttpMessage msg) throws URIException {

    URI uri = msg.getRequestHeader().getURI();
    uri.setQuery(null);
    String sUri = uri.toString();
    if (!sUri.endsWith("/")) {
        sUri = sUri + "/";
    }// w  ww  .j  ava  2s . com
    msg.getRequestHeader().setURI(new URI(sUri, true));
}

From source file:org.zaproxy.zap.extension.brk.ProxyListenerBreak.java

private boolean isBreakPoint(HttpMessage msg, boolean request) {
    if (request && getBreakPanel().isBreakRequest()) {
        // Break on all requests
        return true;
    } else if (!request && getBreakPanel().isBreakResponse()) {
        // Break on all responses
        return true;
    } else if (getBreakPanel().isStepping()) {
        // Stopping through all requests and responses
        return true;
    }/*www  .  j av a2 s.  c  om*/

    try {
        List<BreakPoint> breakPoints = extension.getBreakPointsList();

        if (breakPoints.isEmpty()) {
            // No break points
            return false;
        }

        URI uri = (URI) msg.getRequestHeader().getURI().clone();
        uri.setQuery(null);
        String sUri = uri.getURI();

        // match against the break points

        synchronized (breakPoints) {
            Iterator<BreakPoint> it = breakPoints.iterator();

            while (it.hasNext()) {
                BreakPoint breakPoint = it.next();

                if (breakPoint.isEnabled() && breakPoint.match(sUri)) {
                    return true;
                }
            }
        }
    } catch (URIException e) {
        log.warn(e.getMessage(), e);
    }

    return false;
}