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:com.cyberway.issue.crawler.datamodel.credential.HtmlFormCredential.java

public boolean isPrerequisite(final CrawlURI curi) {
    boolean result = false;
    String curiStr = curi.getUURI().toString();
    String loginUri = getPrerequisite(curi);
    if (loginUri != null) {
        try {/* www  .j a  v a  2  s. co  m*/
            UURI uuri = UURIFactory.getInstance(curi.getUURI(), loginUri);
            if (uuri != null && curiStr != null && uuri.toString().equals(curiStr)) {
                result = true;
                if (!curi.isPrerequisite()) {
                    curi.setPrerequisite(true);
                    logger.fine(curi + " is prereq.");
                }
            }
        } catch (URIException e) {
            logger.severe("Failed to uuri: " + curi + ", " + e.getMessage());
        }
    }
    return result;
}

From source file:com.cyberway.issue.crawler.datamodel.credential.Rfc2617Credential.java

public boolean populate(CrawlURI curi, HttpClient http, HttpMethod method, String payload) {
    boolean result = false;
    String authRealm = payload;//  w  w w  .  j  a  va2 s.  c  o m
    if (authRealm == null) {
        logger.severe("No authscheme though creds: " + curi);
        return result;
    }

    // Always add the credential to HttpState. Doing this because no way of
    // removing the credential once added AND there is a bug in the
    // credentials management system in that it always sets URI root to
    // null: it means the key used to find a credential is NOT realm + root
    // URI but just the realm. Unless I set it everytime, there is
    // possibility that as this thread progresses, it might come across a
    // realm already loaded but the login and password are from another
    // server. We'll get a failed authentication that'd be difficult to
    // explain.
    //
    // Have to make a UsernamePasswordCredentials. The httpclient auth code
    // does an instanceof down in its guts.
    UsernamePasswordCredentials upc = null;
    try {
        upc = new UsernamePasswordCredentials(getLogin(curi), getPassword(curi));
        http.getState().setCredentials(
                new AuthScope(curi.getUURI().getHost(), curi.getUURI().getPort(), authRealm), upc);
        logger.fine("Credentials for realm " + authRealm + " for CrawlURI " + curi.toString()
                + " added to request: " + result);
        result = true;
    } catch (AttributeNotFoundException e1) {
        logger.severe("Failed to get login and password for " + curi + " and " + authRealm);
    } catch (URIException e) {
        logger.severe("Failed to parse host from " + curi + ": " + e.getMessage());
    }

    return result;
}

From source file:edu.ucsd.xmlrpc.xmlrpc.client.XmlRpcCommonsTransport.java

protected void resetClientForRedirect() throws XmlRpcException {
    //get the location header to find out where to redirect to
    Header locationHeader = method.getResponseHeader("location");
    if (locationHeader == null) {
        throw new XmlRpcException("Invalid redirect: Missing location header");
    }// w ww  .j  a  va  2  s .  c  om
    String location = locationHeader.getValue();

    URI redirectUri = null;
    URI currentUri = null;
    try {
        currentUri = method.getURI();
        String charset = currentUri.getProtocolCharset();
        redirectUri = new URI(location, true, charset);
        method.setURI(redirectUri);
    } catch (URIException ex) {
        throw new XmlRpcException(ex.getMessage(), ex);
    }

    //And finally invalidate the actual authentication scheme
    method.getHostAuthState().invalidate();
}

From source file:com.cyberway.issue.crawler.datamodel.credential.HtmlFormCredential.java

public boolean populate(CrawlURI curi, HttpClient http, HttpMethod method, String payload) {
    // http is not used.
    // payload is not used.
    boolean result = false;
    Map formItems = null;/*  ww  w .j av a2  s .  c  o  m*/
    try {
        formItems = getFormItems(curi);
    } catch (AttributeNotFoundException e1) {
        logger.severe("Failed get of form items for " + curi);
    }
    if (formItems == null || formItems.size() <= 0) {
        try {
            logger.severe("No form items for " + method.getURI());
        } catch (URIException e) {
            logger.severe("No form items and exception getting uri: " + e.getMessage());
        }
        return result;
    }

    NameValuePair[] data = new NameValuePair[formItems.size()];
    int index = 0;
    String key = null;
    for (Iterator i = formItems.keySet().iterator(); i.hasNext();) {
        key = (String) i.next();
        data[index++] = new NameValuePair(key, (String) formItems.get(key));
    }
    if (method instanceof PostMethod) {
        ((PostMethod) method).setRequestBody(data);
        result = true;
    } else if (method instanceof GetMethod) {
        // Append these values to the query string.
        // Get current query string, then add data, then get it again
        // only this time its our data only... then append.
        HttpMethodBase hmb = (HttpMethodBase) method;
        String currentQuery = hmb.getQueryString();
        hmb.setQueryString(data);
        String newQuery = hmb.getQueryString();
        hmb.setQueryString(((StringUtils.isNotEmpty(currentQuery)) ? currentQuery + "&" : "") + newQuery);
        result = true;
    } else {
        logger.severe("Unknown method type: " + method);
    }
    return result;
}

From source file:ch.cyberduck.core.dav.DAVResource.java

@Override
protected void setWebdavProperties(final Enumeration responses) throws HttpException, IOException {

    super.setWebdavProperties(new Enumeration() {
        public boolean hasMoreElements() {
            return responses.hasMoreElements();
        }/* www  .j a  v  a2s .  c  om*/

        public Object nextElement() {
            final ResponseEntity response = (ResponseEntity) responses.nextElement();
            return new ResponseEntity() {

                public int getStatusCode() {
                    return response.getStatusCode();
                }

                public Enumeration getProperties() {
                    return response.getProperties();
                }

                public Enumeration getHistories() {
                    return response.getHistories();
                }

                public Enumeration getWorkspaces() {
                    return response.getWorkspaces();
                }

                public String getHref() {
                    if (StringUtils.isNotBlank(response.getHref())) {
                        // http://trac.cyberduck.ch/ticket/2223
                        final String escaped = StringUtils.replace(response.getHref(), " ", "%20");
                        try {
                            new java.net.URI(escaped);
                        } catch (URISyntaxException e) {
                            log.warn("Href not escaped in respose:" + response.getHref());
                            try {
                                return URIUtil.encodePath(response.getHref());
                            } catch (URIException failure) {
                                log.error("Encoding path failed:" + failure.getMessage());
                            }
                        }
                        return escaped;
                    }
                    return response.getHref();
                }
            };
        }
    });
}

From source file:dk.netarkivet.harvester.tools.TwitterDecidingScope.java

/**
 * Adds a url as a seed if possible. Otherwise just prints an error description and returns.
 *
 * @param tweetUrl The url to be added./*  www.j a  va2 s  . c o m*/
 */
private void addSeedIfLegal(String tweetUrl) {
    try {
        CandidateURI curi = CandidateURI.createSeedCandidateURI(UURIFactory.getInstance(tweetUrl));
        System.out.println("Adding seed: '" + curi.toString() + "'");
        addSeed(curi);
    } catch (URIException e1) {
        log.error(e1.getMessage());
        e1.printStackTrace();
    }
}

From source file:com.cyberway.issue.crawler.framework.CrawlScope.java

/**
 * @param a First UURI of compare.//  w w  w . j ava  2s  .  c  o  m
 * @param b Second UURI of compare.
 * @return True if UURIs are of same host.
 */
protected boolean isSameHost(UURI a, UURI b) {
    boolean isSameHost = false;
    if (a != null && b != null) {
        // getHost can come back null.  See
        // "[ 910120 ] java.net.URI#getHost fails when leading digit"
        try {
            if (a.getReferencedHost() != null && b.getReferencedHost() != null) {
                if (a.getReferencedHost().equals(b.getReferencedHost())) {
                    isSameHost = true;
                }
            }
        } catch (URIException e) {
            logger.severe("Failed compare of " + a + " " + b + ": " + e.getMessage());
        }
    }
    return isSameHost;
}

From source file:com.cyberway.issue.crawler.postprocessor.LinksScoper.java

/**
 * The CrawlURI has a prerequisite; apply scoping and update
 * Link to CandidateURI in manner analogous to outlink handling. 
 * @param curi CrawlURI with prereq to consider
 *//*from w w w.  j a v a 2s . co m*/
protected void handlePrerequisite(CrawlURI curi) {
    try {
        // Create prerequisite CandidateURI
        CandidateURI caUri = curi.createCandidateURI(curi.getBaseURI(), (Link) curi.getPrerequisiteUri());
        int prereqPriority = curi.getSchedulingDirective() - 1;
        if (prereqPriority < 0) {
            prereqPriority = 0;
            LOGGER.severe("Unable to promote prerequisite " + caUri + " above " + curi);
        }
        caUri.setSchedulingDirective(prereqPriority);
        caUri.setForceFetch(true);
        if (isInScope(caUri)) {
            // replace link with CandidateURI
            curi.setPrerequisiteUri(caUri);
        } else {
            // prerequisite is out-of-scope; mark CrawlURI as error,
            // preventinting normal S_DEFERRED handling
            curi.setFetchStatus(S_PREREQUISITE_UNSCHEDULABLE_FAILURE);
        }
    } catch (URIException ex) {
        Object[] array = { curi, curi.getPrerequisiteUri() };
        getController().uriErrors.log(Level.INFO, ex.getMessage(), array);
    } catch (NumberFormatException e) {
        // UURI.createUURI will occasionally throw this error.
        Object[] array = { curi, curi.getPrerequisiteUri() };
        getController().uriErrors.log(Level.INFO, e.getMessage(), array);
    }
}

From source file:com.store.rau.storefront.controllers.pages.AbstractPageController.java

/**
 * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not.
 *
 * @param request/*from  ww w .  ja  v  a  2s .  c  o m*/
 *           - request that contains current URL
 * @param response
 *           - response to write "301 Moved Permanently" status to if redirected
 * @param resolvedUrlPath
 *           - properly resolved URL
 * @return null if url is properly resolved or redirection string if not
 * @throws UnsupportedEncodingException
 */
protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response,
        final String resolvedUrlPath) throws UnsupportedEncodingException {
    try {
        final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath);
        final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8");
        final String decoded = URIUtil.decode(resolvedUrl, "utf-8");
        if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) {
            return null;
        } else {
            //  org.springframework.web.servlet.View.RESPONSE_STATUS_ATTRIBUTE = "org.springframework.web.servlet.View.responseStatus"
            request.setAttribute("org.springframework.web.servlet.View.responseStatus",
                    HttpStatus.MOVED_PERMANENTLY);
            final String queryString = request.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
                return "redirect:" + resolvedUrlPath + "?" + queryString;
            }
            return "redirect:" + resolvedUrlPath;
        }
    } catch (final URIException e) {
        LOGGER.error("URIException:" + e.getMessage(), e);
        throw new UnsupportedEncodingException(e.getMessage());
    }
}

From source file:com.cyberway.issue.crawler.extractor.ExtractorHTTP.java

protected void addHeaderLink(CrawlURI curi, Header loc) {
    if (loc == null) {
        // If null, return without adding anything.
        return;/*from w w w .j  av a 2s . c om*/
    }
    // TODO: consider possibility of multiple headers
    try {
        curi.createAndAddLink(loc.getValue(), loc.getName() + ":", Link.REFER_HOP);
        numberOfLinksExtracted++;
    } catch (URIException e) {
        // There may not be a controller (e.g. If we're being run
        // by the extractor tool).
        if (getController() != null) {
            getController().logUriError(e, curi.getUURI(), loc.getValue());
        } else {
            LOGGER.info(curi + ", " + loc.getValue() + ": " + e.getMessage());
        }
    }

}