Search in sources :

Example 1 with URI

use of org.apache.commons.httpclient.URI in project pinpoint by naver.

the class HttpMethodBaseExecuteMethodInterceptor method getHost.

private String getHost(HttpMethod httpMethod, Object[] args) {
    try {
        final URI url = httpMethod.getURI();
        if (url.isAbsoluteURI()) {
            return getEndpoint(url.getHost(), url.getPort());
        }
        if (isDebug) {
            logger.debug("URI is not absolute. {}", url.getURI());
        }
        // if not found schema, use httpConnection.
        final HttpConnection httpConnection = getHttpConnection(args);
        if (httpConnection != null) {
            final String host = httpConnection.getHost();
            int port = httpConnection.getPort();
            // if port is default port number.
            if (httpConnection.getProtocol() != null && port == httpConnection.getProtocol().getDefaultPort()) {
                port = -1;
            }
            return getEndpoint(host, port);
        }
    } catch (URIException e) {
        // unexpected error, perhaps of user fault.
        logger.error("[HttpClient3] Fail get URI", e);
    }
    return null;
}
Also used : URIException(org.apache.commons.httpclient.URIException) HttpConnection(org.apache.commons.httpclient.HttpConnection) URI(org.apache.commons.httpclient.URI)

Example 2 with URI

use of org.apache.commons.httpclient.URI in project zm-mailbox by Zimbra.

the class ProvUtil method sendSoapMessage.

@Override
public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState) {
    console.println("========== SOAP SEND ==========");
    if (debugLevel == SoapDebugLevel.high) {
        try {
            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) {
            // trim the ending crlf
            console.println(header.toString().trim());
        }
        console.println();
    }
    sendStart = System.currentTimeMillis();
    console.println(envelope.prettyPrint());
    console.println("===============================");
}
Also used : URIException(org.apache.commons.httpclient.URIException) Header(org.apache.commons.httpclient.Header) URI(org.apache.commons.httpclient.URI)

Example 3 with URI

use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.

the class StandardParameterParser method getTreePath.

@Override
public List<String> getTreePath(HttpMessage msg) throws URIException {
    URI uri = msg.getRequestHeader().getURI();
    List<String> list = getTreePath(uri);
    // Add any structural params (form params) in key order
    Map<String, String> formParams = this.parse(msg.getRequestBody().toString());
    List<String> keys = new ArrayList<String>(formParams.keySet());
    Collections.sort(keys);
    for (String key : keys) {
        if (this.structuralParameters.contains(key)) {
            list.add(formParams.get(key));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) URI(org.apache.commons.httpclient.URI)

Example 4 with URI

use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.

the class Spider method start.

/* SPIDER PROCESS maintenance - pause, resume, shutdown, etc. */
/**
	 * Starts the Spider crawling.
	 */
public void start() {
    log.info("Starting spider...");
    this.timeStarted = System.currentTimeMillis();
    fetchFilterSeeds();
    // seeds and will not stop.
    if (seedList == null || seedList.isEmpty()) {
        log.warn("No seeds available for the Spider. Cancelling scan...");
        notifyListenersSpiderComplete(false);
        notifyListenersSpiderProgress(100, 0, 0);
        return;
    }
    if (scanUser != null)
        log.info("Scan will be performed from the point of view of User: " + scanUser.getName());
    this.controller.init();
    this.stopped = false;
    this.paused = false;
    this.initialized = false;
    // Initialize the thread pool
    this.threadPool = Executors.newFixedThreadPool(spiderParam.getThreadCount(), new SpiderThreadFactory("ZAP-SpiderThreadPool-" + id + "-thread-"));
    // Initialize the HTTP sender
    httpSender = new HttpSender(connectionParam, true, HttpSender.SPIDER_INITIATOR);
    // Do not follow redirections because the request is not updated, the redirections will be
    // handled manually.
    httpSender.setFollowRedirect(false);
    // Add the seeds
    for (URI uri : seedList) {
        if (log.isDebugEnabled()) {
            log.debug("Adding seed for spider: " + uri);
        }
        controller.addSeed(uri, HttpRequestHeader.GET);
    }
    // Mark the process as completely initialized
    initialized = true;
}
Also used : HttpSender(org.parosproxy.paros.network.HttpSender) URI(org.apache.commons.httpclient.URI)

Example 5 with URI

use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.

the class SpiderController method resourceURIFound.

@Override
public void resourceURIFound(HttpMessage responseMessage, int depth, String uri, boolean shouldIgnore) {
    log.debug("New resource found: " + uri);
    if (uri == null) {
        return;
    }
    // Create the uri
    URI uriV = createURI(uri);
    if (uriV == null) {
        return;
    }
    // Check if the uri was processed already
    String visitedURI;
    try {
        visitedURI = URLCanonicalizer.buildCleanedParametersURIRepresentation(uriV, spider.getSpiderParam().getHandleParameters(), spider.getSpiderParam().isHandleODataParametersVisited());
    } catch (URIException e) {
        return;
    }
    synchronized (visitedGet) {
        if (visitedGet.contains(visitedURI)) {
            // log.debug("URI already visited: " + visitedURI);
            return;
        } else {
            visitedGet.add(visitedURI);
        }
    }
    // Check if any of the filters disallows this uri
    for (FetchFilter f : fetchFilters) {
        FetchStatus s = f.checkFilter(uriV);
        if (s != FetchStatus.VALID) {
            log.debug("URI: " + uriV + " was filtered by a filter with reason: " + s);
            spider.notifyListenersFoundURI(uri, HttpRequestHeader.GET, s);
            return;
        }
    }
    // Check if should be ignored and not fetched
    if (shouldIgnore) {
        log.debug("URI: " + uriV + " is valid, but will not be fetched, by parser reccommendation.");
        spider.notifyListenersFoundURI(uri, HttpRequestHeader.GET, FetchStatus.VALID);
        return;
    }
    spider.notifyListenersFoundURI(uri, HttpRequestHeader.GET, FetchStatus.VALID);
    // Submit the task
    SpiderTask task = new SpiderTask(spider, responseMessage.getRequestHeader().getURI(), uriV, depth, HttpRequestHeader.GET);
    spider.submitTask(task);
}
Also used : URIException(org.apache.commons.httpclient.URIException) FetchFilter(org.zaproxy.zap.spider.filters.FetchFilter) URI(org.apache.commons.httpclient.URI) FetchStatus(org.zaproxy.zap.spider.filters.FetchFilter.FetchStatus)

Aggregations

URI (org.apache.commons.httpclient.URI)135 Test (org.junit.Test)72 FetchStatus (org.zaproxy.zap.spider.filters.FetchFilter.FetchStatus)33 URIException (org.apache.commons.httpclient.URIException)32 HttpMessage (org.parosproxy.paros.network.HttpMessage)10 ArrayList (java.util.ArrayList)9 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)8 DatabaseException (org.parosproxy.paros.db.DatabaseException)7 IOException (java.io.IOException)6 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)6 HandleParametersOption (org.zaproxy.zap.spider.SpiderParam.HandleParametersOption)6 Header (org.apache.commons.httpclient.Header)5 InvalidParameterException (java.security.InvalidParameterException)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 Cookie (org.apache.commons.httpclient.Cookie)3 EntityEnclosingMethod (org.apache.commons.httpclient.methods.EntityEnclosingMethod)3 StructuralNode (org.zaproxy.zap.model.StructuralNode)3 File (java.io.File)2 HashMap (java.util.HashMap)2