List of usage examples for java.net URI getHost
public String getHost()
From source file:main.java.miro.validator.fetcher.RsyncFetcher.java
public String getRelativePath(URI uri) { return baseDirectory + uri.getHost() + uri.getPath(); }
From source file:co.mcme.barry.listeners.ChatListener.java
@EventHandler(priority = EventPriority.MONITOR) public void onYTChat(AsyncPlayerChatEvent event) { String message = event.getMessage(); for (String str : message.split(" ")) { Matcher matcher = url.matcher(str); if (matcher.matches()) { try { URI uri = new URI(str); if (uri.getHost().contains("youtube.com")) { if (uri.getQuery().contains("v=")) { String id = uri.getQuery().replaceAll("v=", ""); String daturl = "http://gdata.youtube.com/feeds/api/videos/" + id + "?alt=json"; YoutubeVideo video = UrlWatcher.getYoutubeInfo(daturl); BarryPlugin.sendGlobalMessage(video.getMessageForTitle()); BarryPlugin.sendGlobalMessage(video.getMessageForDurationLinker(event.getPlayer())); }//from w ww . ja va2 s . com } else if (uri.getHost().contains("youtu.be")) { String[] split = str.split(".be/"); String id = split[1]; String daturl = "http://gdata.youtube.com/feeds/api/videos/" + id + "?alt=json"; YoutubeVideo video = UrlWatcher.getYoutubeInfo(daturl); BarryPlugin.sendGlobalMessage(video.getMessageForTitle()); BarryPlugin.sendGlobalMessage(video.getMessageForDurationLinker(event.getPlayer())); } } catch (URISyntaxException ex) { } } } }
From source file:io.soabase.client.apache.WrappedHttpClient.java
private HttpHost toHost(URI uri) { return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:ch.cyberduck.core.cdn.DistributionUrlProvider.java
/** * @param file File in origin container * @param origin Distribution URL//from w w w . j av a 2s . c om * @return URL to file in distribution */ private URI toUrl(final Path file, final URI origin) { final StringBuilder b = new StringBuilder(String.format("%s://%s", origin.getScheme(), origin.getHost())); if (distribution.getMethod().equals(Distribution.CUSTOM)) { b.append(Path.DELIMITER) .append(URIEncoder.encode(PathRelativizer.relativize(origin.getRawPath(), file.getAbsolute()))); } else { if (StringUtils.isNotEmpty(origin.getRawPath())) { b.append(origin.getRawPath()); } if (StringUtils.isNotEmpty(containerService.getKey(file))) { b.append(Path.DELIMITER).append(URIEncoder.encode(containerService.getKey(file))); } } return URI.create(b.toString()).normalize(); }
From source file:com.msopentech.odatajclient.engine.client.http.AbstractBasicAuthHttpClientFactory.java
@Override public HttpClient createHttpClient(final HttpMethod method, final URI uri) { final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri); httpclient.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(getUsername(), getPassword())); return httpclient; }
From source file:org.esco.portlet.flashinfo.service.bean.FlashUrlBuilderImpl.java
@Override public String transform(final PortletRequest request, final String url) { String rewroteUrl = url;/* w w w .j a v a 2 s . c o m*/ if (log.isDebugEnabled()) { log.debug("Url in entry is '{}'", rewroteUrl); } final Matcher matcher = p.matcher(url); if (matcher.find()) { for (int i = 1; i <= matcher.groupCount(); i++) { // Using the first value only final List<String> values = userResource.getUserInfo(request, matcher.group(i)); if (values != null && !values.isEmpty()) { rewroteUrl = rewroteUrl.replaceAll("\\{" + matcher.group(i) + "\\}", values.get(0)); } else { log.warn("No value was retrived from user info of '{}' on attribute '{}'", request.getUserPrincipal(), matcher.group(i)); } } } if (log.isDebugEnabled()) { log.debug("Replacement regexp of flashUrl from {} to {}", url, rewroteUrl); } try { final URI uri = new URI(rewroteUrl); if (uri.getScheme() == null && uri.getHost() == null) { final int tmpPort = request.getServerPort(); final String port = ((tmpPort != 80) && (tmpPort != 443) && (tmpPort > 0)) ? ":" + tmpPort : ""; // if start with // we add only the scheme // else if relative url start with / we add to the url only the scheme and domain // else if relative url we add sheme + domain + contextPath so in this case only we need to context path final String ctx = (!rewroteUrl.startsWith("//") && !rewroteUrl.startsWith("/")) ? request.getContextPath() + "/" : ""; if (log.isDebugEnabled()) { log.debug( "Rewrite flashUrl from {} to {}, with params scheme {}, host {}, port {}, context path {}", rewroteUrl, request.getScheme() + "://" + request.getServerName() + port + ctx + rewroteUrl, request.getScheme(), request.getServerName(), port, ctx); } rewroteUrl = request.getScheme() + "://" + request.getServerName() + port + ctx + rewroteUrl; } else if (uri.getScheme() == null) { final String path = !rewroteUrl.startsWith("//") ? "//" : ""; if (log.isDebugEnabled()) { log.debug("Rewrite flashUrl from {} to {}, with params scheme {}", rewroteUrl, request.getScheme() + ":" + path + rewroteUrl, request.getScheme() + path); } rewroteUrl = request.getScheme() + ":" + path + rewroteUrl; } } catch (URISyntaxException e) { log.error("The url '" + rewroteUrl + "' to get flashInfos is malformed !", e); return null; } if (log.isDebugEnabled()) { log.debug("Url at end is '{}'", rewroteUrl); } return rewroteUrl; }
From source file:com.adobe.aem.importer.impl.GitListenerImpl.java
public void handleEvent(final Event osgiEvent) { Project gitProject = (Project) osgiEvent.getProperty(GitHubPushConstants.EVT_PROJECT); GitHubPushEvent gitHubPushEvent = (GitHubPushEvent) osgiEvent.getProperty(GitHubPushConstants.EVT_GHEVENT); URI gitRepoUrl = gitHubPushEvent.getRepoUrl(); String sourcePath = DocImporter.GIT_REPOS_FOLDER_PATH + "/" + gitRepoUrl.getHost() + gitRepoUrl.getPath(); List<String> added = gitHubPushEvent.getAddedFileNames(); List<String> modified = gitHubPushEvent.getModifiedFileNames(); List<String> deleted = gitHubPushEvent.getDeletedFileNames(); modified.addAll(added);//from w ww.java 2s . c o m Session session; try { session = repository.loginAdministrative(null); for (String path : modified) { String[] split = path.split("/"); String fileName = split[split.length - 1]; int lastForwardSlashPos = path.lastIndexOf("/"); String parentPath = sourcePath; if (lastForwardSlashPos > 0) { parentPath = parentPath + "/" + path.substring(0, lastForwardSlashPos); } File gitFile = gitProject.getFile(EncodeUtil.escapePath(path)); Node parentNode = JcrUtils.getOrCreateByPath(parentPath, "nt:folder", "nt:folder", session, true); InputStream in = IOUtils.toInputStream(gitFile.getContent(), "UTF-8"); JcrUtils.putFile(parentNode, fileName, "application/xml", in); session.save(); } for (String path : deleted) { String deleteNodePath = sourcePath + "/" + path; if (session.nodeExists(deleteNodePath)) { session.getNode(deleteNodePath).remove(); session.save(); } } docImporter.doImport(sourcePath); } catch (Exception e) { log.error("Exception", e); } }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientManagerImpl.java
/** * Normalizes proxy repository's hostname extracted from it's {@link ProxyRepository#getRemoteUrl()} method. Never * returns {@code null}./*from w w w .ja va 2 s. com*/ * * @see #normalizeHostname(String) */ private String normalizeHostname(final ProxyRepository proxyRepository) { try { final URI uri = new URI(proxyRepository.getRemoteUrl()); return normalizeHostname(uri.getHost()); } catch (URISyntaxException e) { // ignore } return ""; }
From source file:com.woonoz.proxy.servlet.UrlRewriterImpl.java
private boolean hostIsSameAsServletHost(final URI requestedUrl) throws MalformedURLException { return requestedUrl.getHost().equals(getServletHost()) && getPortOrDefault(requestedUrl.toURL()) == getServletPort(); }
From source file:fr.ippon.wip.http.hc.HttpClientDecorator.java
HttpHost getHttpHost(HttpUriRequest request) { URI uri = request.getURI(); return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }