List of usage examples for org.apache.commons.httpclient URI getPort
public int getPort()
From source file:org.zaproxy.zap.spider.filters.HttpPrefixFetchFilter.java
/** * Filters any URI that does not start with the defined prefix. * /*from w ww . j a va 2s.co m*/ * @return {@code FetchStatus.VALID} if the {@code uri} starts with the {@code prefix}, {@code FetchStatus.OUT_OF_SCOPE} * otherwise */ @Override public FetchStatus checkFilter(URI uri) { if (uri == null) { return FetchStatus.OUT_OF_SCOPE; } String otherScheme = normalisedScheme(uri.getRawScheme()); if (port != normalisedPort(otherScheme, uri.getPort())) { return FetchStatus.OUT_OF_SCOPE; } if (!scheme.equals(otherScheme)) { return FetchStatus.OUT_OF_SCOPE; } if (!hasSameHost(uri)) { return FetchStatus.OUT_OF_SCOPE; } if (!startsWith(uri.getRawPath(), path)) { return FetchStatus.OUT_OF_SCOPE; } return FetchStatus.VALID; }
From source file:org.zaproxy.zap.spider.Spider.java
/** * Adds a new seed for the Spider.// ww w . j av a2s . co m * * @param uri the uri */ public void addSeed(URI uri) { // Update the scope of the spidering process String host = null; try { host = uri.getHost(); defaultFetchFilter.addScopeRegex(host); } catch (URIException e) { log.error("There was an error while adding seed value: " + uri, e); return; } // Add the seed to the list -- it will be added to the task list only when the spider is // started this.seedList.add(uri); // Add the appropriate 'robots.txt' as a seed if (getSpiderParam().isParseRobotsTxt()) { try { // Build the URI of the robots.txt file URI robotsUri; // If the port is not 80 or 443, add it to the URI if (uri.getPort() == 80 || uri.getPort() == 443) { robotsUri = new URI(uri.getScheme() + "://" + host + "/robots.txt", true); } else { robotsUri = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + "/robots.txt", true); } this.seedList.add(robotsUri); } catch (Exception e) { log.warn("Error while creating URI for robots.txt file for site " + uri, e); } } // Add the appropriate 'sitemap.xml' as a seed if (getSpiderParam().isParseSitemapXml()) { try { // Build the URI of the sitemap.xml file URI sitemapUri; // If the port is not 80 or 443, add it to the URI if (uri.getPort() == 80 || uri.getPort() == 443) { sitemapUri = new URI(uri.getScheme() + "://" + host + "/sitemap.xml", true); } else { sitemapUri = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + "/sitemap.xml", true); } this.seedList.add(sitemapUri); } catch (Exception e) { log.warn("Error while creating URI for sitemap.xml file for site " + uri, e); } } // And add '.svn/entries' as a seed, for SVN based spidering if (getSpiderParam().isParseSVNEntries()) { try { URI svnEntriesURI1, svnEntriesURI2; // If the port is not 80 or 443, add it to the URI // SVN entries can exist in multiple directories, so make sure to add in the full path. String fullpath = uri.getPath(); String name = uri.getName(); if (fullpath == null) fullpath = ""; if (name == null) name = ""; String pathminusfilename = fullpath.substring(0, fullpath.lastIndexOf(name)); if (pathminusfilename.equals("")) pathminusfilename = "/"; //if it's not an svn folder, add the seeds. Matcher matcherSvnUrl = svnUrlPattern.matcher(pathminusfilename); if (!matcherSvnUrl.find()) { if (uri.getPort() == 80 || uri.getPort() == 443) { svnEntriesURI1 = new URI( uri.getScheme() + "://" + host + pathminusfilename + ".svn/entries", true); svnEntriesURI2 = new URI(uri.getScheme() + "://" + host + pathminusfilename + ".svn/wc.db", true); } else { svnEntriesURI1 = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + pathminusfilename + ".svn/entries", true); svnEntriesURI2 = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + pathminusfilename + ".svn/wc.db", true); } this.seedList.add(svnEntriesURI1); this.seedList.add(svnEntriesURI2); } } catch (Exception e) { log.warn("Error while creating a seed URI for the SVN files for site " + uri, e); } } // And add '.git/index' as a seed, for Git based spidering if (getSpiderParam().isParseGit()) { try { URI gitEntriesURI; // If the port is not 80 or 443, add it to the URI // Make sure to add in the full path. String fullpath = uri.getPath(); String name = uri.getName(); if (fullpath == null) fullpath = ""; if (name == null) name = ""; String pathminusfilename = fullpath.substring(0, fullpath.lastIndexOf(name)); if (pathminusfilename.equals("")) pathminusfilename = "/"; //if it's not in a Git folder, add the seed. Matcher matcherGitUrl = gitUrlPattern.matcher(pathminusfilename); if (!matcherGitUrl.find()) { if (uri.getPort() == 80 || uri.getPort() == 443) { gitEntriesURI = new URI(uri.getScheme() + "://" + host + pathminusfilename + ".git/index", true); } else { gitEntriesURI = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + pathminusfilename + ".git/index", true); } this.seedList.add(gitEntriesURI); } } catch (Exception e) { log.warn("Error while creating a seed URI for the Git files for site " + uri, e); } } }
From source file:phex.download.swarming.SWDownloadFile.java
/** * *//*from www . j av a2 s.co m*/ public SWDownloadFile(URI downloadUri, SwarmingManager swMgr) throws URIException { this(swMgr); String protocol = downloadUri.getScheme(); if ("magnet".equals(protocol)) { MagnetData magnetData = MagnetData.parseFromURI(downloadUri); URN urn = MagnetData.lookupSHA1URN(magnetData); String magnetFileName = MagnetData.lookupFileName(magnetData); magnetFileName = FileUtils.convertToLocalSystemFilename(magnetFileName); String searchTerm; if (magnetData.getKeywordTopic() != null) { searchTerm = magnetData.getKeywordTopic(); } else { searchTerm = StringUtils.createNaturalSearchTerm(MagnetData.lookupSearchName(magnetData)); } initialize(magnetFileName, urn, UNKNOWN_FILE_SIZE, searchTerm, true); try { initIncompleteFile(); } catch (FileHandlingException | ManagedFileException exp) { logger.error(exp.toString(), exp); } List<URI> urlList = MagnetData.lookupHttpURIs(magnetData); for (URI uri : urlList) { String host = uri.getHost(); int port = uri.getPort(); if (port == -1) { port = 80; } DestAddress address = new DefaultDestAddress(host, port); SWDownloadCandidate candidate = new SWDownloadCandidate(address, uri, this, mgr.getCandidateLogBuffer()); addDownloadCandidate(candidate); } // fire off a search in case this is a magnet download to get sources. if (urn != null || getCandidatesCount() == 0) { startSearchForCandidates(); } } else { String uriFileName = URLUtil.getFileNameFromUri(downloadUri); uriFileName = FileUtils.convertToLocalSystemFilename(uriFileName); String searchTerm = StringUtils.createNaturalSearchTerm(uriFileName); initialize(uriFileName, null, UNKNOWN_FILE_SIZE, searchTerm, true); try { initIncompleteFile(); } catch (FileHandlingException | ManagedFileException exp) { logger.error(exp.toString(), exp); } String host = downloadUri.getHost(); if (host != null) { int port = downloadUri.getPort(); if (port == -1) { port = 80; } DestAddress address = new DefaultDestAddress(host, port); SWDownloadCandidate candidate = new SWDownloadCandidate(address, downloadUri, this, mgr.getCandidateLogBuffer()); addDownloadCandidate(candidate); } } }
From source file:ru.org.linux.spring.Configuration.java
public boolean compareWithMainURI(URI uri) { try {//from w w w. j a v a 2 s.co m return (mainHost.equals(uri.getHost()) && mainPort == uri.getPort()); } catch (Exception e) { return false; } }
From source file:ru.org.linux.util.formatter.ToHtmlFormatter.java
public String memberURL(User user, boolean secure) throws URIException { URI mainUri = configuration.getMainURI(); String scheme;/*from w ww . j a va2 s . co m*/ if (secure) { scheme = "https"; } else { scheme = "http"; } return (new URI(scheme, null, mainUri.getHost(), mainUri.getPort(), String.format("/people/%s/profile", user.getNick()))).getEscapedURIReference(); }
From source file:ru.org.linux.util.LorURI.java
/** * ? url ? ? mainUrl //from w w w . j a va 2 s . co m * url id ? * ? url ? * @param mainURI ? URI ? * @param url url * @throws URIException ? url */ public LorURI(URI mainURI, String url) throws URIException { this.mainURI = mainURI; URI uri; try { uri = new URI(url, true, "UTF-8"); } catch (URIException e) { uri = new URI(url, false, "UTF-8"); } lorURI = uri; if (lorURI.getHost() == null) { throw new URIException(); } /* ? uri lorsouce ? ? ? scheme http https */ trueLorUrl = (mainURI.getHost().equals(lorURI.getHost()) && mainURI.getPort() == lorURI.getPort() && ("http".equals(lorURI.getScheme()) || "https".equals(lorURI.getScheme()))); if (trueLorUrl) { // find message id in lor url int msgId = 0; int commId = 0; boolean isMsg = false; boolean isComm = false; if (lorURI.getPath() != null && lorURI.getQuery() != null) { Matcher oldJumpPathMatcher = requestOldJumpPathPattern.matcher(lorURI.getPath()); Matcher oldJumpQueryMatcher = requestOldJumpQueryPattern.matcher(lorURI.getQuery()); if (oldJumpPathMatcher.find() && oldJumpQueryMatcher.find()) { try { msgId = Integer.parseInt(oldJumpQueryMatcher.group(1)); commId = Integer.parseInt(oldJumpQueryMatcher.group(2)); isMsg = true; isComm = true; } catch (NumberFormatException e) { msgId = 0; commId = 0; isMsg = false; isComm = false; } } } String path = lorURI.getPath(); if (path != null && !isMsg) { Matcher messageMatcher = requestMessagePattern.matcher(path); if (messageMatcher.find()) { try { msgId = Integer.parseInt(messageMatcher.group(1)); isMsg = true; } catch (NumberFormatException e) { msgId = 0; isMsg = false; } } else { msgId = 0; isMsg = false; } if (path.endsWith("/history")) { isMsg = false; } } messageId = msgId; messageUrl = isMsg; // find comment id in lor url String fragment = lorURI.getFragment(); if (fragment != null) { Matcher commentMatcher = requestCommentPattern.matcher(fragment); if (commentMatcher.find()) { try { commId = Integer.parseInt(commentMatcher.group(1)); isComm = true; } catch (NumberFormatException e) { commId = 0; isComm = false; } } } if (lorURI.getQuery() != null) { Matcher commentMatcher = requestConmmentPatternNew.matcher(lorURI.getQuery()); if (commentMatcher.find()) { try { commId = Integer.parseInt(commentMatcher.group(1)); isComm = true; } catch (NumberFormatException e) { commId = 0; isComm = false; } } } commentId = commId; commentUrl = isComm; } else { messageId = 0; messageUrl = false; commentId = 0; commentUrl = false; } }
From source file:ru.org.linux.util.LorURL.java
public LorURL(URI mainURI, String url) throws URIException { parsed = new Impl(url); char[] _main_host = mainURI.getRawHost(); int _main_port = mainURI.getPort(); char[] _https_scheme = "https".toCharArray(); char[] _http_scheme = "http".toCharArray(); _true_lor_url = Arrays.equals(_main_host, parsed.getRawHost()) && _main_port == parsed.getPort() && (Arrays.equals(_http_scheme, parsed.getRawScheme()) || Arrays.equals(_https_scheme, parsed.getRawScheme())); findURLIds();/* ww w . ja va 2 s . c o m*/ }
From source file:ru.org.linux.util.LorURL.java
/** * ?? scheme url http https ?? secure * ? ? lor ??, ? , ?//from w w w.j a v a2 s . c o m * @param canonical ? URL ? * @return ? url * @throws URIException url */ public String canonize(URI canonical) throws URIException { if (!_true_lor_url) { return toString(); } String host = canonical.getHost(); int port = canonical.getPort(); String path = parsed.getPath(); String query = parsed.getQuery(); String fragment = parsed.getFragment(); if (canonical.getScheme().equals("http")) { return (new HttpURL(null, host, port, path, query, fragment)).getEscapedURIReference(); } else { return (new HttpsURL(null, host, port, path, query, fragment)).getEscapedURIReference(); } }
From source file:ru.org.linux.util.LorURL.java
/** * url ? ?\/*from www . j a v a 2 s . co m*/ * @param messageDao ? ? * @param canonical ? URL ? * @return url ? ?? ? * @throws MessageNotFoundException ? ?? * @throws URIException ? url */ public String formatJump(TopicDao messageDao, URI canonical) throws MessageNotFoundException, URIException { if (_topic_id != -1) { Topic message = messageDao.getById(_topic_id); Group group = messageDao.getGroup(message); String scheme = canonical.getScheme(); String host = canonical.getHost(); int port = canonical.getPort(); String path = group.getUrl() + _topic_id; String query = ""; if (_comment_id != -1) { query = "cid=" + _comment_id; } URI jumpUri = new URI(scheme, null, host, port, path, query); return jumpUri.getEscapedURI(); } return ""; }
From source file:slash.navigation.rest.HttpRequest.java
public void setAuthentication(String userName, String password) { try {//from w ww . j a v a2s . c o m URI uri = method.getURI(); setAuthentication(userName, password, new AuthScope(uri.getHost(), uri.getPort(), "Restricted Access")); // TODO required? } catch (URIException e) { log.severe("Cannot set authentication: " + e.getMessage()); } }