List of usage examples for java.net URL getAuthority
public String getAuthority()
From source file:org.commonjava.indy.httprox.util.ProxyResponseHelper.java
/** * Create repositories (group, remote, hosted) when trackingId is present. Otherwise create normal remote * repository with specified name.//from ww w. j av a 2 s . co m * * @param trackingId * @param url * @param name distinct remote repository name. null if trackingId is given */ private ProxyCreationResult createRepo(String trackingId, URL url, String name) throws IndyDataException { UrlInfo info = new UrlInfo(url.toExternalForm()); UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority()); String baseUrl = getBaseUrl(url, false); logger.debug(">>>> Create repo: trackingId=" + trackingId + ", name=" + name); ProxyCreationResult result = repoCreator.create(trackingId, name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass())); ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl()); RemoteRepository remote = result.getRemote(); if (remote != null) { storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata()); } HostedRepository hosted = result.getHosted(); if (hosted != null) { storeManager.storeArtifactStore(hosted, changeSummary, false, true, new EventMetadata()); } Group group = result.getGroup(); if (group != null) { storeManager.storeArtifactStore(group, changeSummary, false, true, new EventMetadata()); } return result; }
From source file:com.sap.cloudlabs.connectivity.proxy.ProxyServlet.java
/** * Returns the URL to the proxy servlet and used destination. *///from w ww. j a v a 2 s . c o m private String getProxyUrl(HttpServletRequest request) throws MalformedURLException { URL url = new URL(request.getRequestURL().toString()); String proxyUrl = request.getScheme() + "://" + url.getAuthority() + request.getContextPath() + request.getServletPath(); return proxyUrl; }
From source file:org.codice.ddf.pax.web.jetty.CsrfFilter.java
/** * Returns true if the supplied URL has an authority (hostname:port) that matches one of the * system's trusted authorities. If the URL is blank or malformed, false is returned. * * @param source source URL/* w w w .j a v a 2s . co m*/ * @return true if matching, false if different or a parsing error occurs */ private Boolean isTrustedAuthority(String source) { if (StringUtils.isBlank(source)) { return false; } else { try { URL url = new URL(source); String sourceAuthority; // if no port is specified, assume default http/https ports if (url.getPort() == -1) { sourceAuthority = url.getHost() + ":" + (url.getProtocol().equals("https") ? "443" : "80"); } else { sourceAuthority = url.getAuthority(); } return (trustedAuthorities.stream().anyMatch(sourceAuthority::equalsIgnoreCase)); } catch (MalformedURLException e) { LOGGER.debug("Could not extract hostname and port from the request URL", e); return false; } } }
From source file:org.apache.taverna.component.profile.ComponentProfileImpl.java
public ComponentProfileImpl(Registry registry, URL profileURL, BaseProfileLocator base) throws ComponentException { logger.info("Loading profile in " + identityHashCode(this) + " from " + profileURL); this.base = base; try {/*from w w w. j av a 2 s . c om*/ URL url = profileURL; if (url.getProtocol().startsWith("http")) url = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef()) .toURL(); loadProfile(this, url, base); } catch (MalformedURLException e) { logger.warn("Malformed URL? " + profileURL); } catch (URISyntaxException e) { logger.warn("Malformed URL? " + profileURL); } parentRegistry = registry; }
From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDTFParseUrlTuple.java
private String evaluate(URL url, int index) { if (url == null || index < 0 || index >= partnames.length) { return null; }//w w w. j a v a 2s .c om switch (partnames[index]) { case HOST: return url.getHost(); case PATH: return url.getPath(); case QUERY: return url.getQuery(); case REF: return url.getRef(); case PROTOCOL: return url.getProtocol(); case FILE: return url.getFile(); case AUTHORITY: return url.getAuthority(); case USERINFO: return url.getUserInfo(); case QUERY_WITH_KEY: return evaluateQuery(url.getQuery(), paths[index]); case NULLNAME: default: return null; } }
From source file:org.mozilla.gecko.AboutHomeContent.java
private String getPageUrlFromIconUrl(String iconUrl) { // Addon icon URLs come with a query argument that is usually // used for expiration purposes. We want the "page URL" here to be // stable enough to avoid unnecessary duplicate records of the // same addon. String pageUrl = iconUrl;/*from ww w . ja v a 2 s. com*/ try { URL urlForIcon = new URL(iconUrl); URL urlForPage = new URL(urlForIcon.getProtocol(), urlForIcon.getAuthority(), urlForIcon.getPath()); pageUrl = urlForPage.toString(); } catch (MalformedURLException e) { // Defaults to pageUrl = iconUrl in case of error } return pageUrl; }
From source file:org.apache.ranger.biz.KmsKeyMgr.java
private String[] createProvider(String dbKmsUrl, String uri) throws IOException, URISyntaxException { URI providerUri = new URI(uri); URL origUrl = new URL(extractKMSPath(providerUri).toString()); String authority = origUrl.getAuthority(); // check for ';' which delimits the backup hosts if (Strings.isNullOrEmpty(authority)) { throw new IOException("No valid authority in kms uri [" + origUrl + "]"); }/*www . ja v a 2 s .c o m*/ // Check if port is present in authority // In the current scheme, all hosts have to run on the same port int port = -1; String hostsPart = authority; if (authority.contains(":")) { String[] t = authority.split(":"); try { port = Integer.parseInt(t[1]); } catch (Exception e) { throw new IOException("Could not parse port in kms uri [" + origUrl + "]"); } hostsPart = t[0]; } return createProvider(dbKmsUrl, providerUri, origUrl, port, hostsPart); }
From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java
/** * Parse url and return various components of the URL. * If accept any null arguments, return null. * * @param urlStr URL string.// w ww . j a v a2s .com * @param partToExtract determines which components would return. * accept values: * HOST,PATH,QUERY,REF, * PROTOCOL,FILE,AUTHORITY,USERINFO * @return target value. */ public static String parseUrl(String urlStr, String partToExtract) { URL url; try { url = URL_CACHE.get(urlStr); } catch (Exception e) { LOG.error("Parse URL error: " + urlStr, e); return null; } if ("HOST".equals(partToExtract)) { return url.getHost(); } if ("PATH".equals(partToExtract)) { return url.getPath(); } if ("QUERY".equals(partToExtract)) { return url.getQuery(); } if ("REF".equals(partToExtract)) { return url.getRef(); } if ("PROTOCOL".equals(partToExtract)) { return url.getProtocol(); } if ("FILE".equals(partToExtract)) { return url.getFile(); } if ("AUTHORITY".equals(partToExtract)) { return url.getAuthority(); } if ("USERINFO".equals(partToExtract)) { return url.getUserInfo(); } return null; }
From source file:org.apache.tez.dag.app.web.AMWebController.java
@VisibleForTesting public void setCorsHeaders() { final HttpServletResponse res = response(); /*//from w ww. j av a 2s. co m * ideally the Origin and other CORS headers should be checked and response headers set only * if it matches the allowed origins. however rm does not forward these headers. */ String historyUrlBase = appContext.getAMConf().get(TezConfiguration.TEZ_HISTORY_URL_BASE, ""); String origin = request().getHeader(ORIGIN); if (origin == null) { try { URL url = new URL(historyUrlBase); origin = url.getProtocol() + "://" + url.getAuthority(); } catch (MalformedURLException e) { if (LOG.isDebugEnabled()) { LOG.debug("Invalid url set for tez history url base: " + historyUrlBase, e); } } } if (origin != null) { origin = encodeHeader(origin); res.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, origin); } res.setHeader(ACCESS_CONTROL_ALLOW_METHODS, ALLOWED_METHODS); res.setHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE.toString()); res.setHeader(ACCESS_CONTROL_ALLOW_HEADERS, ALLOWED_HEADERS); res.setHeader(ACCESS_CONTROL_MAX_AGE, "1800"); }
From source file:com.lizardtech.expresszip.model.Job.java
public String getDL_URL() { String url = ""; if (getRunState() == RunState.FinishedOK) { URL u = getUrl(); String containerURL = u.getProtocol() + "://" + u.getAuthority(); url = containerURL + "/exportdir/" + jobParams.getJobName() + "/" + _archiveName; }// w w w . j a va2 s . c o m return url; }