List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:org.apache.sentry.provider.file.WildcardPermission.java
/** * URI is a a special case. For URI's, /a implies /a/b. * Therefore the test is "/a/b".startsWith("/a"); *//*from w w w .j a v a 2 s. c o m*/ @VisibleForTesting protected static boolean impliesURI(String policy, String request) { try { URI policyURI = new URI(new StrSubstitutor(System.getProperties()).replace(policy)); URI requestURI = new URI(request); if (policyURI.getScheme() == null || policyURI.getPath() == null) { LOGGER.warn("Policy URI " + policy + " is not valid. Either no scheme or no path."); return false; } if (requestURI.getScheme() == null || requestURI.getPath() == null) { LOGGER.warn("Request URI " + request + " is not valid. Either no scheme or no path."); return false; } // schemes are equal && // request path does not contain relative parts /a/../b && // request path starts with policy path && // authorities (nullable) are equal if (policyURI.getScheme().equals(requestURI.getScheme()) && requestURI.getPath().equals(new URI(request).normalize().getPath()) && requestURI.getPath().startsWith(policyURI.getPath()) && Strings.nullToEmpty(policyURI.getAuthority()) .equals(Strings.nullToEmpty(requestURI.getAuthority()))) { return true; } return false; } catch (URISyntaxException e) { LOGGER.warn("Request URI " + request + " is not a URI", e); return false; } }
From source file:org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.LoadFunction.java
public TaskTracker tasks() throws IOException, SemanticException { URI fromURI = EximUtil.getValidatedURI(context.hiveConf, stripQuotes(event.rootDir().toUri().toString())); Path fromPath = new Path(fromURI.getScheme(), fromURI.getAuthority(), fromURI.getPath()); try {/* w w w .ja v a 2 s . c om*/ if (isFunctionAlreadyLoaded(fromPath)) { return tracker; } CreateFunctionHandler handler = new CreateFunctionHandler(); List<Task<? extends Serializable>> tasks = handler .handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, null, context.hiveConf, context.hiveDb, context.nestedContext, LOG)); createFunctionReplLogTask(tasks, handler.getFunctionName()); tasks.forEach(tracker::addTask); return tracker; } catch (Exception e) { throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e); } }
From source file:ch.netcetera.eclipse.projectconfig.core.configurationcommands.DownloadProjectConfigurationCommand.java
/** * Downloads a file from a local (file://) source. * * @param fileUrl the file url// w ww.j a v a2s.com * @param targetFile the target file * @return the status */ private IStatus downloadFileFromFile(String fileUrl, File targetFile) { IStatus status = Status.OK_STATUS; try { URI uri = new URI(fileUrl); if (uri.getAuthority() == null) { File sourceFile = new File(uri); if (sourceFile.canRead()) { OutputStream outputStream = null; InputStream inputStream = null; try { outputStream = new FileOutputStream(targetFile); inputStream = new FileInputStream(sourceFile); copyFile(inputStream, outputStream); } finally { IOUtil.closeSilently(outputStream); IOUtil.closeSilently(inputStream); } } else { status = createStatus(IStatus.ERROR, getTextAccessor().getText("error.cannot.read.local.file")); } } else { status = createStatus(IStatus.ERROR, getTextAccessor().getText("error.cannot.read.local.file")); } } catch (IOException e) { status = createStatus(IStatus.ERROR, e.getLocalizedMessage(), e); } catch (URISyntaxException e) { status = createStatus(IStatus.ERROR, e.getLocalizedMessage(), e); } return status; }
From source file:org.apache.shindig.gadgets.servlet.UrlGeneratorTest.java
@Test public void getIframeUrlTypeUrl() throws Exception { String xml = "<Module>" + " <ModulePrefs title='test'/>" + " <Content type='url' href='" + StringEscapeUtils.escapeHtml(TYPE_URL_HREF) + "'/>" + " <UserPref name='" + UP_NAME + "' datatype='string'/>" + "</Module>"; GadgetSpec spec = new GadgetSpec(URI.create(SPEC_URL), xml); Gadget gadget = new Gadget(context, spec, Collections.<JsLibrary>emptyList()); fixture.replay();/*from w w w . j a v a2 s .c om*/ URI iframeUrl = URI.create(urlGenerator.getIframeUrl(gadget)); assertEquals(TYPE_URL_HREF_HOST, iframeUrl.getAuthority()); assertEquals(TYPE_URL_HREF_PATH, iframeUrl.getPath()); StringAssert.assertContains(TYPE_URL_HREF_QUERY, iframeUrl.getQuery()); StringAssert.assertContains("container=" + CONTAINER, iframeUrl.getQuery()); StringAssert.assertContains("up_" + UP_NAME + '=' + UP_VALUE, iframeUrl.getQuery()); StringAssert.assertContains("mid=" + MODULE_ID, iframeUrl.getQuery()); }
From source file:org.apache.hadoop.fs.FCStatisticsBaseTest.java
protected URI getSchemeAuthorityUri() { URI uri = getFsUri(); String SchemeAuthString = uri.getScheme() + "://"; if (uri.getAuthority() == null) { SchemeAuthString += "/"; } else {//w ww. j a v a 2 s . c o m SchemeAuthString += uri.getAuthority(); } return URI.create(SchemeAuthString); }
From source file:org.mule.providers.jmx.JmxEndpointBuilder.java
protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException { String path = uri.getPath();//from w w w . j av a 2s . c o m String authority = uri.getAuthority(); address = uri.getScheme() + "://" + (authority == null ? "" : authority) + (path == null ? "" : path); if (path != null && path.startsWith("/")) { props.put("resourceInfo", path.substring(1)); } if (uri.getScheme().equals("notification")) { try { NotificationFilter filter = createNotificationFilter(authority, props); if (filter != null) { props.put(PROP_FILTER, filter); } } catch (MalformedObjectNameException e) { throw new MalformedEndpointException(address, e); } } }
From source file:de.tuberlin.cit.livescale.messaging.endpoints.GCMEndpoint.java
@Override protected void performSend(MessageManifest manifest) { for (de.tuberlin.cit.livescale.messaging.Message m : manifest.getMessages()) { try {/*w w w . j av a2 s . com*/ Result result = this.sender.send(this.createMessage(m), manifest.getTargetURI().getPath().substring(1), 5); // let's check for side conditions ... if (result.getMessageId() != null) { String canonicalRegId = result.getCanonicalRegistrationId(); if (canonicalRegId != null) { // user has a new address URI localURI = getLocalEndpointURI(); URI newTargetURI = new URI(localURI.getScheme(), localURI.getAuthority(), canonicalRegId, "", ""); notifyListenersDeliveryEvent(new TargetMovedSuccess(manifest, newTargetURI)); } } else { // User's gone. String error = result.getErrorCodeName(); if (error.equals(Constants.ERROR_NOT_REGISTERED)) { notifyListenersDeliveryEvent(new TargetMovedFailure(manifest)); } } } catch (IOException e) { notifyListenersDeliveryEvent(new ServiceUnavailableFailure(manifest)); } catch (URISyntaxException e) { LOG.debug("Error building a new URI from the local one. THIS SHOULD NEVER HAPPEN!", e); } } }
From source file:common.NameNode.java
public static InetSocketAddress getAddress(Configuration conf) { URI filesystemURI = FileSystem.getDefaultUri(conf); String authority = filesystemURI.getAuthority(); if (authority == null) { throw new IllegalArgumentException( String.format("Invalid URI for NameNode address (check %s): %s has no authority.", FileSystem.FS_DEFAULT_NAME_KEY, filesystemURI.toString())); }/* www .jav a2 s.c o m*/ if (!FSConstants.HDFS_URI_SCHEME.equalsIgnoreCase(filesystemURI.getScheme())) { throw new IllegalArgumentException( String.format("Invalid URI for NameNode address (check %s): %s is not of scheme '%s'.", FileSystem.FS_DEFAULT_NAME_KEY, filesystemURI.toString(), FSConstants.HDFS_URI_SCHEME)); } return getAddress(authority); }
From source file:org.eclipse.orion.server.git.objects.StashPage.java
@PropertyDescription(name = ProtocolConstants.KEY_PREVIOUS_LOCATION) protected URI getPreviousPageLocation() throws URISyntaxException { if (page > 1) { URI location = getLocation(); String query = String.format("page=%d&pageSize=%d", (page - 1), pageSize); //$NON-NLS-1$ return new URI(location.getScheme(), location.getAuthority(), location.getPath(), query, location.getFragment()); }// w w w .ja va2 s . com return null; }
From source file:org.eclipse.orion.server.git.objects.StashPage.java
@PropertyDescription(name = ProtocolConstants.KEY_NEXT_LOCATION) protected URI getNextPageLocation() throws URISyntaxException { if (hasNextPage()) { URI location = getLocation(); String query = String.format("page=%d&pageSize=%d", (page + 1), pageSize); //$NON-NLS-1$ return new URI(location.getScheme(), location.getAuthority(), location.getPath(), query, location.getFragment()); }//from w ww . j a va 2 s. co m return null; }