List of usage examples for org.apache.commons.httpclient URIException getMessage
public String getMessage()
From source file:au.org.ala.biocache.dto.SearchRequestParams.java
/** * URI encode the param value if isEncoded is true * * @param input/*from ww w. ja v a 2s . c o m*/ * @param isEncoded * @return query string */ protected String conditionalEncode(String input, Boolean isEncoded) { String output; if (isEncoded) { try { output = URIUtil.encodeWithinQuery(input); } catch (URIException e) { logger.warn("URIUtil encoding error: " + e.getMessage(), e); output = input; } } else { output = input; } return output; }
From source file:com.jivesoftware.authHelper.customescheme.negotiate.CustomNegotiateScheme.java
/** * Produces Negotiate authorization string based on token created by * processChallenge.// w w w. j a va2s. c om * * @param credentials Never used be the Negotiate scheme but must be provided to * satisfy common-httpclient API. Credentials from JAAS will be used insted. * @param method The method being authenticated * * @throws org.apache.commons.httpclient.auth.AuthenticationException if authorization string cannot * be generated due to an authentication failure * * @return an Negotiate authorization string * * @since 3.0 */ public synchronized String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { LOG.info("enter CustomNegotiateScheme.authenticate(Credentials, HttpMethod)"); if (state == UNINITIATED) { throw new IllegalStateException("Negotiation authentication process has not been initiated"); } try { try { if (context == null) { LOG.info("host: " + method.getURI().getHost()); init(method.getURI().getHost(), (UsernamePasswordCredentials) credentials); } } catch (org.apache.commons.httpclient.URIException urie) { LOG.severe(urie.getMessage()); state = FAILED; throw new AuthenticationException(urie.getMessage()); } // HTTP 1.1 issue: // Mutual auth will never complete do to 200 insted of 401 in // return from server. "state" will never reach ESTABLISHED // but it works anyway // token = context.initSecContext(token, 0, token.length); LOG.info("got token, sending " + token.length + " to server"); } catch (GSSException gsse) { LOG.severe(gsse.getMessage()); state = FAILED; if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED) { throw new InvalidCredentialsException(gsse.getMessage(), gsse); } if (gsse.getMajor() == GSSException.NO_CRED) { throw new CredentialsNotAvailableException(gsse.getMessage(), gsse); } if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN || gsse.getMajor() == GSSException.DUPLICATE_TOKEN || gsse.getMajor() == GSSException.OLD_TOKEN) { throw new AuthChallengeException(gsse.getMessage(), gsse); } // other error throw new AuthenticationException(gsse.getMessage()); } return "Negotiate " + new String(new Base64(-1).encode(token)); }
From source file:com.cyberway.issue.crawler.extractor.ExtractorDOC.java
private void addLink(CrawlURI curi, String hyperlink) { try {/*from w w w . jav a2s.c o m*/ curi.createAndAddLink(hyperlink, Link.NAVLINK_MISC, Link.NAVLINK_HOP); } catch (URIException e1) { getController().logUriError(e1, curi.getUURI(), hyperlink); if (getController() != null) { // Controller can be null: e.g. when running // ExtractorTool. getController().logUriError(e1, curi.getUURI(), hyperlink); } else { logger.info(curi + ", " + hyperlink + ": " + e1.getMessage()); } } numberOfLinksExtracted++; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorPDF.java
protected void extract(CrawlURI curi) { if (!isHttpTransactionContentToProcess(curi) || !isExpectedMimeType(curi.getContentType(), "application/pdf")) { return;/* ww w .ja v a 2 s. c o m*/ } numberOfCURIsHandled++; File tempFile; if (curi.getHttpRecorder().getRecordedInput().getSize() > maxSizeToParse) { return; } int sn = ((ToeThread) Thread.currentThread()).getSerialNumber(); tempFile = new File(getController().getScratchDisk(), "tt" + sn + "tmp.pdf"); PDFParser parser; ArrayList uris; try { curi.getHttpRecorder().getRecordedInput().copyContentBodyTo(tempFile); parser = new PDFParser(tempFile.getAbsolutePath()); uris = parser.extractURIs(); } catch (IOException e) { curi.addLocalizedError(getName(), e, "ExtractorPDF IOException"); return; } catch (RuntimeException e) { // Truncated/corrupt PDFs may generate ClassCast exceptions, or // other problems curi.addLocalizedError(getName(), e, "ExtractorPDF RuntimeException"); return; } finally { tempFile.delete(); } if (uris != null && uris.size() > 0) { Iterator iter = uris.iterator(); while (iter.hasNext()) { String uri = (String) iter.next(); try { curi.createAndAddLink(uri, Link.NAVLINK_MISC, Link.NAVLINK_HOP); } catch (URIException e1) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (getController() != null) { getController().logUriError(e1, curi.getUURI(), uri); } else { LOGGER.info(curi + ", " + uri + ": " + e1.getMessage()); } } } numberOfLinksExtracted += uris.size(); } LOGGER.fine(curi + " has " + uris.size() + " links."); // Set flag to indicate that link extraction is completed. curi.linkExtractorFinished(); }
From source file:com.armorize.hackalert.extractor.msword.ExtractorDOC2.java
public void extractOutlinks(CrawlURI curi, final String plainText) throws MalformedPatternException { long start = System.currentTimeMillis(); final PatternCompiler cp = new Perl5Compiler(); final Pattern pattern = cp.compile(URL_PATTERN, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.MULTILINE_MASK); final PatternMatcher matcher = new Perl5Matcher(); final PatternMatcherInput input = new PatternMatcherInput(plainText); MatchResult result;/*from w w w. j av a 2 s . co m*/ String url; // loop the matches while (matcher.contains(input, pattern)) { // if this is taking too long, stop matching // (SHOULD really check cpu time used so that heavily loaded // systems // do not unnecessarily hit this limit.) if (System.currentTimeMillis() - start >= 60000L) { if (logger.isLoggable(Level.WARNING)) { logger.warning("Time limit exceeded for getOutLinks"); } break; } result = matcher.getMatch(); url = result.group(0); try { curi.createAndAddLink(url, Link.NAVLINK_MISC, Link.NAVLINK_HOP); } catch (URIException e) { getController().logUriError(e, curi.getUURI(), url); if (getController() != null) { // Controller can be null: e.g. when running // ExtractorTool. getController().logUriError(e, curi.getUURI(), url); } else { logger.info(curi + ", " + url + ": " + e.getMessage()); } } } }
From source file:dk.netarkivet.harvester.harvesting.extractor.ExtractorOAI.java
/** * Perform the link extraction on the current crawl uri. This method * does not set linkExtractorFinished() on the current crawlURI, so * subsequent extractors in the chain can find more links. * @param curi the CrawlUI from which to extract the link. *//*from w ww . j a v a2 s . c o m*/ @Override protected boolean innerExtract(CrawlURI curi) { try { String query = curi.getUURI().getQuery(); if (query == null) { // Test for null query - strange that we need to do that return false; } if (!query.contains("verb=ListRecords")) { //Not an OAI-PMH document return false; } } catch (URIException e) { log.error("Cannot get query part from '" + curi + "'", e); } this.numberOfCURIsHandled++; ReplayCharSequence cs = null; try { cs = curi.getRecorder().getContentReplayCharSequence(); } catch (IOException e) { log.error("Failed getting ReplayCharSequence: " + e.getMessage()); } if (cs == null) { log.error("Failed getting ReplayCharSequence: " + curi.toString()); return false; } try { boolean foundResumptionToken = processXml(curi, cs); if (foundResumptionToken) { numberOfLinksExtracted += 1; } } finally { if (cs != null) { try { cs.close(); } catch (IOException ioe) { log.warn(TextUtils.exceptionToString("Failed close of ReplayCharSequence.", ioe)); } } } return false; }
From source file:com.blackducksoftware.soleng.bdsplugin.dao.CodeCenterDAO.java
/** * Constructs a Code Center url using their redirect knowledge The pattern * must follow the protocol: Note: Version is optional http:// * <servername>/codecenter /CCRedirectPage?isAtTop=true&CCRedirectPageName * =Component&CCComponentName=<compName >&CCComponentVersion=<version> * * @param pojo// w w w .j ava2 s. com * @param settings * @return */ public CompPOJO populateUrlForComponent(final CompPOJO pojo, final Settings settings) { String server = settings.getString(BDSPluginConstants.PROPERTY_CC_URL); if (server != null) { String compName = pojo.getComponentName(); String compVersion = pojo.getVersion(); try { if (!server.endsWith("/")) { server += "/"; } String urlString = URIUtil.encodeQuery(server + "codecenter/CCRedirectPage?isAtTop=true&CCRedirectPageName=Component&CCComponentName=" + compName.trim() + "&CCComponentVersion=" + compVersion); pojo.setUrl(urlString); } catch (URIException e) { log.error("Unable to create a proper url for component: " + compName + " error: " + e.getMessage()); } } else { log.warn("Unable to construct URLs for components, CC server not specified"); } return pojo; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorHTML.java
public void extract(CrawlURI curi) { if (!isHttpTransactionContentToProcess(curi) || !(isExpectedMimeType(curi.getContentType(), "text/html") || isExpectedMimeType(curi.getContentType(), "application/xhtml"))) { return;// ww w .j a v a2s. c o m } final boolean ignoreUnexpectedHTML = ((Boolean) getUncheckedAttribute(curi, ATTR_IGNORE_UNEXPECTED_HTML)) .booleanValue(); if (ignoreUnexpectedHTML) { try { if (!isHtmlExpectedHere(curi)) { // HTML was not expected (eg a GIF was expected) so ignore // (as if a soft 404) return; } } catch (URIException e) { logger.severe("Failed expectedHTML test: " + e.getMessage()); } } this.numberOfCURIsHandled++; ReplayCharSequence cs = null; try { HttpRecorder hr = curi.getHttpRecorder(); if (hr == null) { throw new IOException("Why is recorder null here?"); } cs = hr.getReplayCharSequence(); } catch (IOException e) { curi.addLocalizedError(this.getName(), e, "Failed get of replay char sequence " + curi.toString() + " " + e.getMessage()); logger.log(Level.SEVERE, "Failed get of replay char sequence in " + Thread.currentThread().getName(), e); } if (cs == null) { return; } // We have a ReplayCharSequence open. Wrap all in finally so we // for sure close it before we leave. try { // Extract all links from the charsequence extract(curi, cs); // Set flag to indicate that link extraction is completed. curi.linkExtractorFinished(); } finally { if (cs != null) { try { cs.close(); } catch (IOException ioe) { logger.warning(TextUtils.exceptionToString("Failed close of ReplayCharSequence.", ioe)); } } } }
From source file:de.juwimm.cms.http.HttpClientWrapper.java
/** * tries first with no auth toherwise first with non-ntlm proxy if still * http-error-code 407 with ntlm-proxy/*from w w w . j a v a 2 s. c o m*/ * * @param testURL * @param userName * for testURL authentication NOT for proxy * @param password * for testURL authentication NOT for proxy * @throws HttpException */ private void testAndConfigureConnectionTryInvoke(URL testURL, String userName, String password) throws HttpException { HttpMethodBase method = null; try { /* * At first Im trying here with default settings, so no proxy auth, * proxy if given and or proxy auth with username and password auth. */ method = invoke(testURL, userName, password); } catch (URIException exe) { if (exe.getReasonCode() == 407) { log.info("Proxy needs authorization to be configured"); if (this.getHttpProxyUser() != null) { try { /* * Now I want to try the proxy with NTLM * authentification. I can not figure out if I can use * NTLM, so we're trying it. */ this.setUseNTproxy(true); method = invoke(testURL, null, null); } catch (URIException exe2) { if (exe2.getReasonCode() == 407) { /* * Something went wrong - in general username / * password pair does not match - in this case this * could also be a wrong NT-DOMAIN. */ this.setUseNTproxy(false); throw exe2; } throw new HttpException(HttpMessages.getString("HttpClientWrapper.testConnectionFailed", testURL.getHost(), exe2.getMessage())); } } else { log.info("...but first you have to enter one"); this.setUseNTproxy(false); throw exe; } } else { throw new HttpException(HttpMessages.getString("HttpClientWrapper.testConnectionFailed", testURL.getHost(), exe.getMessage())); } } finally { if (method != null) { method.releaseConnection(); } } }
From source file:com.cyberway.issue.crawler.filter.PathDepthFilter.java
protected boolean innerAccepts(Object o) { String path = null;//from ww w . j a v a2 s. co m if (o == null) { return false; } if (o instanceof CandidateURI) { try { if (((CandidateURI) o).getUURI() != null) { path = ((CandidateURI) o).getUURI().getPath(); } } catch (URIException e) { logger.severe("Failed getpath for " + ((CandidateURI) o).getUURI()); } } else if (o instanceof UURI) { try { path = ((UURI) o).getPath(); } catch (URIException e) { logger.severe("Failed getpath for " + o); } } if (path == null) { return true; } int count = 0; for (int i = path.indexOf(slash); i != -1; i = path.indexOf(slash, i + 1)) { count++; } if (o instanceof CrawlURI) { try { this.maxPathDepth = (Integer) getAttribute(ATTR_MAX_PATH_DEPTH, (CrawlURI) o); } catch (AttributeNotFoundException e) { logger.severe(e.getMessage()); } } return (this.maxPathDepth != null) ? count <= this.maxPathDepth.intValue() : false; }