List of usage examples for org.apache.commons.httpclient URIException getMessage
public String getMessage()
From source file:mitm.common.util.URIUtils.java
/** * Tries to create a URI out of the string. It first tries to create a URI directly. If that fails * it tries to URI encode the string and then create the URI. * @param identifier// www. ja v a 2s. c o m * @return */ public static URI toURI(String identifier, boolean encode) throws URISyntaxException { identifier = StringUtils.trimToNull(identifier); if (identifier == null) { return null; } URI uri = null; try { uri = new URI(identifier); } catch (URISyntaxException e) { logger.debug("Not a valid URI. Trying encoded version. Identifier: " + identifier); if (!encode) { throw e; } /* * try to URI encode the string */ try { identifier = URIUtil.encodePathQuery(identifier); } catch (URIException urie) { throw new CausableURISyntaxException(identifier, urie.getMessage(), urie); } uri = new URI(identifier); } return uri; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorXML.java
public static long processXml(CrawlURI curi, CharSequence cs, CrawlController controller) { long foundLinks = 0; Matcher uris = null;/* w ww .java 2 s. co m*/ String xmlUri; uris = TextUtils.getMatcher(XML_URI_EXTRACTOR, cs); while (uris.find()) { xmlUri = uris.group(1); // TODO: Escape more HTML Entities. xmlUri = TextUtils.replaceAll(ESCAPED_AMP, xmlUri, "&"); foundLinks++; try { // treat as speculative, as whether context really // intends to create a followable/fetchable URI is // unknown curi.createAndAddLink(xmlUri, Link.SPECULATIVE_MISC, Link.SPECULATIVE_HOP); } catch (URIException e) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (controller != null) { controller.logUriError(e, curi.getUURI(), xmlUri); } else { logger.info(curi + ", " + xmlUri + ": " + e.getMessage()); } } } TextUtils.recycleMatcher(uris); return foundLinks; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorCSS.java
public static long processStyleCode(CrawlURI curi, CharSequence cs, CrawlController controller) { long foundLinks = 0; Matcher uris = null;/* w w w . java 2 s. c o m*/ String cssUri; try { uris = TextUtils.getMatcher(CSS_URI_EXTRACTOR, cs); while (uris.find()) { cssUri = uris.group(2); // TODO: Escape more HTML Entities. cssUri = TextUtils.replaceAll(ESCAPED_AMP, cssUri, "&"); // Remove backslashes when used as escape character in CSS URL cssUri = TextUtils.replaceAll(CSS_BACKSLASH_ESCAPE, cssUri, "$1"); foundLinks++; try { curi.createAndAddLinkRelativeToBase(cssUri, Link.EMBED_MISC, Link.EMBED_HOP); } catch (URIException e) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (controller != null) { controller.logUriError(e, curi.getUURI(), cssUri); } else { logger.info(curi + ", " + cssUri + ": " + e.getMessage()); } } } } catch (StackOverflowError e) { DevUtils.warnHandle(e, "ExtractorCSS StackOverflowError"); } finally { TextUtils.recycleMatcher(uris); } return foundLinks; }
From source file:dk.netarkivet.harvester.harvesting.extractor.ExtractorJS.java
public static long considerStrings(CrawlURI curi, CharSequence cs, CrawlController controller, boolean handlingJSFile) { long foundLinks = 0; Matcher strings = TextUtils.getMatcher(JAVASCRIPT_STRING_EXTRACTOR, cs); while (strings.find()) { CharSequence subsequence = cs.subSequence(strings.start(2), strings.end(2)); if (UriUtils.isLikelyUriJavascriptContextLegacy(subsequence)) { String string = subsequence.toString(); string = StringEscapeUtils.unescapeJavaScript(string); string = UriUtils.speculativeFixup(string, curi.getUURI()); foundLinks++;/* ww w .java2s . co m*/ try { if (handlingJSFile) { curi.createAndAddLinkRelativeToVia(string, Link.JS_MISC, Link.SPECULATIVE_HOP); } else { curi.createAndAddLinkRelativeToBase(string, Link.JS_MISC, Link.SPECULATIVE_HOP); } } catch (URIException e) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (controller != null) { controller.logUriError(e, curi.getUURI(), string); } else { LOGGER.info(curi + ", " + string + ": " + e.getMessage()); } } } else { foundLinks += considerStrings(curi, subsequence, controller, handlingJSFile); } } TextUtils.recycleMatcher(strings); return foundLinks; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorJS.java
public static long considerStrings(CrawlURI curi, CharSequence cs, CrawlController controller, boolean handlingJSFile) { long foundLinks = 0; Matcher strings = TextUtils.getMatcher(JAVASCRIPT_STRING_EXTRACTOR, cs); while (strings.find()) { CharSequence subsequence = cs.subSequence(strings.start(2), strings.end(2)); Matcher uri = TextUtils.getMatcher(STRING_URI_DETECTOR, subsequence); if (uri.matches()) { String string = uri.group(); string = speculativeFixup(string, curi); foundLinks++;/*from www . j a va 2 s .c om*/ try { if (handlingJSFile) { curi.createAndAddLinkRelativeToVia(string, Link.JS_MISC, Link.SPECULATIVE_HOP); } else { curi.createAndAddLinkRelativeToBase(string, Link.JS_MISC, Link.SPECULATIVE_HOP); } } catch (URIException e) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (controller != null) { controller.logUriError(e, curi.getUURI(), string); } else { LOGGER.info(curi + ", " + string + ": " + e.getMessage()); } } } else if (subsequence.toString().startsWith("/")) { try { curi.createAndAddLinkRelativeToBase(subsequence.toString(), Link.JS_MISC, Link.NAVLINK_HOP); } catch (URIException e) { if (controller != null) { controller.logUriError(e, curi.getUURI(), subsequence); } else { LOGGER.info(curi + ", " + subsequence + ": " + e.getMessage()); } } } else { foundLinks += considerStrings(curi, subsequence, controller, handlingJSFile); } TextUtils.recycleMatcher(uri); } TextUtils.recycleMatcher(strings); return foundLinks; }
From source file:com.sforce.cd.apexUnit.client.codeCoverage.WebServiceInvoker.java
public static JSONObject doGet(String relativeServiceURL, String accessToken) { LOG.debug("relativeServiceURL in doGet method:" + relativeServiceURL); HttpClient httpclient = new HttpClient(); GetMethod get = null;//from ww w . j a v a 2 s .c o m String authorizationServerURL = CommandLineArguments.getOrgUrl() + relativeServiceURL; get = new GetMethod(authorizationServerURL); get.addRequestHeader("Content-Type", "application/json"); get.setRequestHeader("Authorization", "Bearer " + accessToken); LOG.debug("Start GET operation for the url..." + authorizationServerURL); InputStream instream = null; try { instream = executeHTTPMethod(httpclient, get, authorizationServerURL); LOG.debug("done with get operation"); JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(instream)); LOG.debug("is json null? :" + json == null ? "true" : "false"); if (json != null) { if (LOG.isDebugEnabled()) { LOG.debug("ToolingApi.get response: " + json.toString()); Set<String> keys = castSet(String.class, json.keySet()); Iterator<String> jsonKeyIter = keys.iterator(); LOG.debug("Response for the GET method: "); while (jsonKeyIter.hasNext()) { String key = jsonKeyIter.next(); LOG.debug("key : " + key + ". Value : " + json.get(key) + "\n"); // TODO if query results are too large, only 1st batch // of results // are returned. Need to use the identifier in an // additional query // to retrieve rest of the next batch of results if (key.equals("nextRecordsUrl")) { // fire query to the value for this key // doGet((String) json.get(key), accessToken); try { authorizationServerURL = CommandLineArguments.getOrgUrl() + (String) json.get(key); get.setURI(new URI(authorizationServerURL, false)); instream = executeHTTPMethod(httpclient, get, authorizationServerURL); JSONObject newJson = (JSONObject) JSONValue.parse(new InputStreamReader(instream)); if (newJson != null) { Set<String> newKeys = castSet(String.class, json.keySet()); Iterator<String> newJsonKeyIter = newKeys.iterator(); while (newJsonKeyIter.hasNext()) { String newKey = newJsonKeyIter.next(); json.put(newKey, newJson.get(newKey)); LOG.debug("newkey : " + newKey + ". NewValue : " + newJson.get(newKey) + "\n"); } } } catch (URIException e) { ApexUnitUtils.shutDownWithDebugLog(e, "URI exception while fetching subsequent batch of result"); } } } } } return json; } finally { get.releaseConnection(); try { if (instream != null) { instream.close(); } } catch (IOException e) { ApexUnitUtils.shutDownWithDebugLog(e, "Encountered IO exception when closing the stream after reading response from the get method. The error says: " + e.getMessage()); } } }
From source file:jails.http.client.CommonsClientHttpRequest.java
public URI getURI() { try {/*from w w w . jav a 2s.c o m*/ return URI.create(this.httpMethod.getURI().getEscapedURI()); } catch (URIException ex) { throw new IllegalStateException("Could not get HttpMethod URI: " + ex.getMessage(), ex); } }
From source file:com.cyberway.issue.crawler.scope.SeedFileIterator.java
protected UURI transform(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; }/*from ww w.j a v a 2 s .com*/ try { // TODO: ignore lines beginning with non-word char return UURIFactory.getInstance(uri); } catch (URIException e) { logger.log(Level.INFO, "line in seed file ignored: " + e.getMessage(), e); if (ignored != null) { try { ignored.write(uri + "\n"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return null; } }
From source file:com.cyberway.issue.crawler.datamodel.ServerCache.java
/** * Get the {@link CrawlServer} associated with <code>curi</code>. * @param cauri CandidateURI we're to get server from. * @return CrawlServer instance that matches the passed CandidateURI. *//*from w w w. j av a2 s .c o m*/ public CrawlServer getServerFor(CandidateURI cauri) { CrawlServer cs = null; try { String key = CrawlServer.getServerKey(cauri); // TODOSOMEDAY: make this robust against those rare cases // where authority is not a hostname. if (key != null) { cs = getServerFor(key); } } catch (URIException e) { logger.severe(e.getMessage() + ": " + cauri); e.printStackTrace(); } catch (NullPointerException npe) { logger.severe(npe.getMessage() + ": " + cauri); npe.printStackTrace(); } return cs; }
From source file:com.cyberway.issue.crawler.scope.PathScope.java
/** * @param o// ww w.ja v a2 s. c o m * @return True if focus filter accepts passed object. */ protected boolean focusAccepts(Object o) { UURI u = UURI.from(o); if (u == null) { return false; } // Get the seeds to refresh Iterator iter = seedsIterator(); while (iter.hasNext()) { UURI s = (UURI) iter.next(); if (isSameHost(s, u)) { try { // Protect against non-parseable URIs. See // "[ 910120 ] java.net.URI#getHost fails when // leading digit" if (s.getPath() == null || u.getPath() == null) { continue; } } catch (URIException e) { logger.severe("Failed get path on " + u + " or " + s + ": " + e.getMessage()); } try { if (s.getPath().regionMatches(0, u.getPath(), 0, s.getPath().lastIndexOf('/'))) { // matches up to last '/' checkClose(iter); return true; } else { // no match; try next seed continue; } } catch (URIException e) { logger.severe("Failed get path on " + u + " or " + s + ": " + e.getMessage()); } } } // if none found, fail checkClose(iter); return false; }