Search in sources :

Example 1 with URIException

use of org.apache.commons.httpclient.URIException 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 URIException

use of org.apache.commons.httpclient.URIException 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 URIException

use of org.apache.commons.httpclient.URIException in project Asqatasun by Asqatasun.

the class AsqatasunTextSeedModule method seedLine.

/**
     * Handle a read line that is probably a seed.
     *
     * @param uri String seed-containing line
     */
protected void seedLine(String uri) {
    if (!uri.matches("[a-zA-Z][\\w+\\-]+:.*")) {
        // Rfc2396 s3.1 scheme,
        // minus '.'
        // Does not begin with scheme, so try http://
        uri = "http://" + uri;
    }
    try {
        UURI uuri = UURIFactory.getInstance(uri);
        CrawlURI curi = new CrawlURI(uuri);
        curi.setSeed(true);
        curi.setSchedulingDirective(SchedulingConstants.MEDIUM);
        if (getSourceTagSeeds()) {
            curi.setSourceTag(curi.toString());
        }
        publishAddedSeed(curi);
    } catch (URIException e) {
        // try as nonseed line as fallback
        nonseedLine(uri);
    }
}
Also used : UURI(org.archive.net.UURI) URIException(org.apache.commons.httpclient.URIException) CrawlURI(org.archive.modules.CrawlURI)

Example 4 with URIException

use of org.apache.commons.httpclient.URIException 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)

Example 5 with URIException

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

the class DefaultParseFilter method isFiltered.

@Override
public boolean isFiltered(HttpMessage responseMessage) {
    //if it's a file ending in "/.svn/entries", or "/.svn/wc.db", the SVN Entries or Git parsers will process it 
    //regardless of type, and regardless of whether it exceeds the file size restriction below.
    Matcher svnXMLFilenameMatcher, svnSQLiteFilenameMatcher, gitFilenameMatcher;
    try {
        String fullfilename = responseMessage.getRequestHeader().getURI().getPath();
        //handle null paths
        if (fullfilename == null)
            fullfilename = "";
        svnSQLiteFilenameMatcher = svnSQLiteFilenamePattern.matcher(fullfilename);
        svnXMLFilenameMatcher = svnXMLFilenamePattern.matcher(fullfilename);
        gitFilenameMatcher = gitFilenamePattern.matcher(fullfilename);
        if (svnSQLiteFilenameMatcher.find() || svnXMLFilenameMatcher.find() || gitFilenameMatcher.find())
            return false;
    } catch (URIException e) {
        //give other parsers a chance to parse it.
        log.error(e);
    }
    // Check response body size
    if (responseMessage.getResponseBody().length() > MAX_RESPONSE_BODY_SIZE) {
        if (log.isDebugEnabled()) {
            log.debug("Resource too large: " + responseMessage.getRequestHeader().getURI());
        }
        return true;
    }
    // If it's a redirection, accept it, as the SpiderRedirectParser will process it
    if (HttpStatusCode.isRedirection(responseMessage.getResponseHeader().getStatusCode()))
        return false;
    // Check response type.
    if (!responseMessage.getResponseHeader().isText()) {
        if (log.isDebugEnabled()) {
            log.debug("Resource is not text: " + responseMessage.getRequestHeader().getURI());
        }
        return true;
    }
    return false;
}
Also used : URIException(org.apache.commons.httpclient.URIException) Matcher(java.util.regex.Matcher)

Aggregations

URIException (org.apache.commons.httpclient.URIException)52 URI (org.apache.commons.httpclient.URI)31 IOException (java.io.IOException)9 HttpMethod (org.apache.commons.httpclient.HttpMethod)8 Header (org.apache.commons.httpclient.Header)7 HttpClient (org.apache.commons.httpclient.HttpClient)6 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 EntityEnclosingMethod (org.apache.commons.httpclient.methods.EntityEnclosingMethod)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 DatabaseException (org.parosproxy.paros.db.DatabaseException)5 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 InputStreamReader (java.io.InputStreamReader)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 HttpException (org.apache.commons.httpclient.HttpException)3 HttpMessage (org.parosproxy.paros.network.HttpMessage)3 InvalidParameterException (java.security.InvalidParameterException)2 HashMap (java.util.HashMap)2