List of usage examples for org.apache.commons.httpclient URI getHost
public String getHost() throws URIException
From source file:phex.download.swarming.SWDownloadFile.java
/** * *//* ww w.j a v a2 s .c om*/ 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:phex.util.URLUtil.java
public static String getFileNameFromUri(URI uri) throws URIException { String path;/*from ww w . ja v a 2s . c o m*/ path = uri.getPath(); if (path == null) { return uri.getHost(); } int at = path.lastIndexOf('/'); int to = path.length(); return (at >= 0) ? path.substring(at + 1, to) : path; }
From source file:phex.utils.URLUtil.java
public static String getFileNameFromUri(URI uri) throws URIException { String path;/*from ww w .j a v a2 s . c om*/ path = uri.getPath(); if (path == null) { return uri.getHost(); } int at = path.lastIndexOf("/"); int to = path.length(); return (at >= 0) ? path.substring(at + 1, to) : path; }
From source file:ru.org.linux.spring.Configuration.java
public boolean compareWithMainURI(URI uri) { try {/*w ww .ja 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 w w .ja va 2s . c o 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 //w w w . j a va 2s. 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
/** * ?? scheme url http https ?? secure * ? ? lor ??, ? , ?// ww w .java2 s .c om * @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 w w w . ja v a2 s. c o 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 www . j a v a2 s .c om*/ 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()); } }
From source file:uk.bl.wa.hadoop.regex.WARCRegexMapper.java
/** * /*from w w w . j av a 2 s. c o m*/ * @param url * @return */ private static String extractHost(String url) { String host = "unknown.host"; URI uri = null; // Attempt to parse: try { uri = new URI(url, false); // Extract domain: host = uri.getHost(); } catch (Exception e) { // Return a special hostname if parsing failed: host = "malformed.host"; } return host; }