List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:com.sina.cloudstorage.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.schemeSpecificPart = uri.getSchemeSpecificPart(); this.authority = uri.getAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.userInfo = uri.getUserInfo(); this.path = uri.getPath(); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.fragment = uri.getFragment(); }
From source file:org.apache.gobblin.service.FlowConfigResourceLocalHandler.java
/** * Get flow config//w w w. jav a 2 s .co m */ public FlowConfig getFlowConfig(FlowId flowId) throws FlowConfigLoggedException { log.info("[GAAS-REST] Get called with flowGroup {} flowName {}", flowId.getFlowGroup(), flowId.getFlowName()); try { URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null); URI flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowId.getFlowGroup() + "/" + flowId.getFlowName(), null, null); FlowSpec spec = (FlowSpec) flowCatalog.getSpec(flowUri); FlowConfig flowConfig = new FlowConfig(); Properties flowProps = spec.getConfigAsProperties(); Schedule schedule = null; if (flowProps.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { schedule = new Schedule(); schedule.setCronSchedule(flowProps.getProperty(ConfigurationKeys.JOB_SCHEDULE_KEY)); } if (flowProps.containsKey(ConfigurationKeys.JOB_TEMPLATE_PATH)) { flowConfig.setTemplateUris(flowProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH)); } else if (spec.getTemplateURIs().isPresent()) { flowConfig.setTemplateUris(StringUtils.join(spec.getTemplateURIs().get(), ",")); } else { flowConfig.setTemplateUris("NA"); } if (schedule != null) { if (flowProps.containsKey(ConfigurationKeys.FLOW_RUN_IMMEDIATELY)) { schedule.setRunImmediately( Boolean.valueOf(flowProps.getProperty(ConfigurationKeys.FLOW_RUN_IMMEDIATELY))); } flowConfig.setSchedule(schedule); } // remove keys that were injected as part of flowSpec creation flowProps.remove(ConfigurationKeys.JOB_SCHEDULE_KEY); flowProps.remove(ConfigurationKeys.JOB_TEMPLATE_PATH); StringMap flowPropsAsStringMap = new StringMap(); flowPropsAsStringMap.putAll(Maps.fromProperties(flowProps)); return flowConfig .setId(new FlowId().setFlowGroup(flowId.getFlowGroup()).setFlowName(flowId.getFlowName())) .setProperties(flowPropsAsStringMap); } catch (URISyntaxException e) { throw new FlowConfigLoggedException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowId.getFlowName(), e); } catch (SpecNotFoundException e) { throw new FlowConfigLoggedException(HttpStatus.S_404_NOT_FOUND, "Flow requested does not exist: " + flowId.getFlowName(), null); } }
From source file:org.opentravel.schemacompiler.security.impl.DefaultAuthorizationProvider.java
/** * Returns the namespace hierarchy in the order that it must be traversed in order to determine * a user's authorization scheme.// w w w . j a v a 2 s. co m * * @param namespace * the namespace for which to return the hierarchy * @return List<String> * @throws RepositorySecurityException * thrown if the namespace URI is not valid */ private List<String> getNamespaceHierarchy(String namespace) throws RepositorySecurityException { try { List<String> hierarchy = new ArrayList<String>(); URI ns = new URI(namespace); String nsScheme = ns.getScheme(); String nsAuthority = ns.getAuthority(); String nsPath = ns.getPath(); hierarchy.add(null); // null hierarchy member represents global authorizations if ((nsScheme != null) && (nsAuthority != null) && (nsPath != null)) { String[] pathParts = ns.getPath().split("/"); StringBuilder nsBuilder = new StringBuilder(); nsBuilder.append(nsScheme).append("://").append(nsAuthority); hierarchy.add(nsBuilder.toString()); for (String pathPart : pathParts) { if ((pathPart != null) && !pathPart.equals("")) { nsBuilder.append("/").append(pathPart); hierarchy.add(nsBuilder.toString()); } } } else { throw new URISyntaxException(namespace, "Invalid namespace URI format."); } return hierarchy; } catch (URISyntaxException e) { throw new RepositorySecurityException( "Unable to determine security hierarchy for namespace: " + namespace, e); } }
From source file:de.vanita5.twittnuker.util.net.TwidereHttpClientImpl.java
@Override public twitter4j.http.HttpResponse request(final twitter4j.http.HttpRequest req) throws TwitterException { final HostAddressResolver resolver = FactoryUtils.getHostAddressResolver(conf); final String urlString = req.getURL(); final URI urlOrig = ParseUtils.parseURI(urlString); final String host = urlOrig.getHost(), authority = urlOrig.getAuthority(); try {//from www . j a v a 2 s .c om HttpRequestBaseHC4 commonsRequest; final String resolvedHost = resolver != null ? resolver.resolve(host) : null; final String resolvedUrl = !isEmpty(resolvedHost) ? urlString.replace("://" + host, "://" + resolvedHost) : urlString; final RequestMethod method = req.getMethod(); if (method == RequestMethod.GET) { commonsRequest = new HttpGetHC4(resolvedUrl); } else if (method == RequestMethod.POST) { final HttpPostHC4 post = new HttpPostHC4(resolvedUrl); post.setEntity(getAsEntity(req.getParameters())); post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); commonsRequest = post; } else if (method == RequestMethod.DELETE) { commonsRequest = new HttpDeleteHC4(resolvedUrl); } else if (method == RequestMethod.HEAD) { commonsRequest = new HttpHeadHC4(resolvedUrl); } else if (method == RequestMethod.PUT) { final HttpPutHC4 put = new HttpPutHC4(resolvedUrl); put.setEntity(getAsEntity(req.getParameters())); commonsRequest = put; } else throw new TwitterException("Unsupported request method " + method); final HttpParams httpParams = commonsRequest.getParams(); HttpClientParams.setRedirecting(httpParams, false); final Map<String, String> headers = req.getRequestHeaders(); for (final String headerName : headers.keySet()) { commonsRequest.addHeader(headerName, headers.get(headerName)); } final Authorization authorization = req.getAuthorization(); final String authorizationHeader = authorization != null ? authorization.getAuthorizationHeader(req) : null; if (authorizationHeader != null) { commonsRequest.addHeader(HttpHeaders.AUTHORIZATION, authorizationHeader); } if (resolvedHost != null && !resolvedHost.isEmpty() && !resolvedHost.equals(host)) { commonsRequest.addHeader(HttpHeaders.HOST, authority); } final ApacheHttpClientHttpResponseImpl res; try { final HttpContext httpContext = new BasicHttpContextHC4(); httpContext.setAttribute(HostResolvedSSLConnectionSocketFactory.HTTP_CONTEXT_KEY_ORIGINAL_HOST, host); res = new ApacheHttpClientHttpResponseImpl(client.execute(commonsRequest, httpContext), conf); } catch (final IllegalStateException e) { throw new TwitterException("Please check your API settings.", e); } catch (final NullPointerException e) { // Bug http://code.google.com/p/android/issues/detail?id=5255 throw new TwitterException("Please check your APN settings, make sure not to use WAP APNs.", e); } catch (final OutOfMemoryError e) { // I don't know why OOM thown, but it should be catched. System.gc(); throw new TwitterException("Unknown error", e); } final int statusCode = res.getStatusCode(); if (statusCode < OK || statusCode > ACCEPTED) throw new TwitterException(res.asString(), req, res); return res; } catch (final IOException e) { // TODO if (resolver instanceof TwidereHostAddressResolver) { final TwidereHostAddressResolver twidereResolver = (TwidereHostAddressResolver) resolver; twidereResolver.removeCachedHost(host); } throw new TwitterException(e); } }
From source file:org.apache.gobblin.service.FlowConfigsResource.java
/** * Delete a configured flow. Running flows are not affected. The schedule will be removed for scheduled flows. * @param key composite key containing flow group and flow name that identifies the flow to remove from the * {@link FlowCatalog}//from w ww .ja va 2 s . c om * @return {@link UpdateResponse} */ @Override public UpdateResponse delete(ComplexResourceKey<FlowId, EmptyRecord> key) { String flowGroup = key.getKey().getFlowGroup(); String flowName = key.getKey().getFlowName(); URI flowUri = null; LOG.info("Delete called with flowGroup " + flowGroup + " flowName " + flowName); try { URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null); flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowGroup + "/" + flowName, null, null); getFlowCatalog().remove(flowUri); return new UpdateResponse(HttpStatus.S_200_OK); } catch (URISyntaxException e) { logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowUri, e); } return null; }
From source file:org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.LoadConstraint.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 {/*from w ww . j a va2 s. c o m*/ FileSystem fs = FileSystem.get(fromPath.toUri(), context.hiveConf); JSONObject json = new JSONObject(EximUtil.readAsString(fs, fromPath)); String pksString = json.getString("pks"); String fksString = json.getString("fks"); String uksString = json.getString("uks"); String nnsString = json.getString("nns"); List<Task<? extends Serializable>> tasks = new ArrayList<Task<? extends Serializable>>(); if (pksString != null && !pksString.isEmpty() && !isPrimaryKeysAlreadyLoaded(pksString)) { AddPrimaryKeyHandler pkHandler = new AddPrimaryKeyHandler(); DumpMetaData pkDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_PRIMARYKEY, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf); pkDumpMetaData.setPayload(pksString); tasks.addAll(pkHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, pkDumpMetaData, context.hiveConf, context.hiveDb, context.nestedContext, LOG))); } if (uksString != null && !uksString.isEmpty() && !isUniqueConstraintsAlreadyLoaded(uksString)) { AddUniqueConstraintHandler ukHandler = new AddUniqueConstraintHandler(); DumpMetaData ukDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_UNIQUECONSTRAINT, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf); ukDumpMetaData.setPayload(uksString); tasks.addAll(ukHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, ukDumpMetaData, context.hiveConf, context.hiveDb, context.nestedContext, LOG))); } if (nnsString != null && !nnsString.isEmpty() && !isNotNullConstraintsAlreadyLoaded(nnsString)) { AddNotNullConstraintHandler nnHandler = new AddNotNullConstraintHandler(); DumpMetaData nnDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_NOTNULLCONSTRAINT, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf); nnDumpMetaData.setPayload(nnsString); tasks.addAll(nnHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, nnDumpMetaData, context.hiveConf, context.hiveDb, context.nestedContext, LOG))); } if (fksString != null && !fksString.isEmpty() && !isForeignKeysAlreadyLoaded(fksString)) { AddForeignKeyHandler fkHandler = new AddForeignKeyHandler(); DumpMetaData fkDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_FOREIGNKEY, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf); fkDumpMetaData.setPayload(fksString); tasks.addAll(fkHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, fkDumpMetaData, context.hiveConf, context.hiveDb, context.nestedContext, LOG))); } tasks.forEach(tracker::addTask); return tracker; } catch (Exception e) { throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e); } }
From source file:com.cloudera.impala.planner.S3PlannerTest.java
/** * Remove any non-constant components of the given file path. For S3, the * actual bucket name, which will be unique to the tester's setup, needs to * be replaced with a fixed bucket name. *//*from w ww . j a va2 s . c o m*/ @Override protected Path cleanseFilePath(Path path) { path = super.cleanseFilePath(path); URI fsURI = fsName.toUri(); URI pathURI = path.toUri(); Assert.assertTrue("error: " + path + " is not on filesystem " + fsName, fsURI.getScheme().equals(pathURI.getScheme()) && fsURI.getAuthority().equals(pathURI.getAuthority())); return Path.mergePaths(S3A_CANONICAL_BUCKET, path); }
From source file:com.metamx.druid.indexing.common.index.StaticS3FirehoseFactory.java
@Override public Firehose connect() throws IOException { Preconditions.checkNotNull(s3Client, "null s3Client"); return new Firehose() { LineIterator lineIterator = null; final Queue<URI> objectQueue = Lists.newLinkedList(uris); // Rolls over our streams and iterators to the next file, if appropriate private void maybeNextFile() throws Exception { if (lineIterator == null || !lineIterator.hasNext()) { // Close old streams, maybe. if (lineIterator != null) { lineIterator.close(); }// w w w . j a v a2 s .co m // Open new streams, maybe. final URI nextURI = objectQueue.poll(); if (nextURI != null) { final String s3Bucket = nextURI.getAuthority(); final S3Object s3Object = new S3Object( nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath()); log.info("Reading from bucket[%s] object[%s] (%s)", s3Bucket, s3Object.getKey(), nextURI); int ntry = 0; try { final InputStream innerInputStream = s3Client.getObject(s3Bucket, s3Object.getKey()) .getDataInputStream(); final InputStream outerInputStream = s3Object.getKey().endsWith(".gz") ? new GZIPInputStream(innerInputStream) : innerInputStream; lineIterator = IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (IOException e) { log.error(e, "Exception reading from bucket[%s] object[%s] (try %d) (sleeping %d millis)", s3Bucket, s3Object.getKey(), ntry, retryMillis); ntry++; if (ntry <= retryCount) { Thread.sleep(retryMillis); } } } } } @Override public boolean hasMore() { try { maybeNextFile(); } catch (Exception e) { throw Throwables.propagate(e); } return lineIterator != null && lineIterator.hasNext(); } @Override public InputRow nextRow() { try { maybeNextFile(); } catch (Exception e) { throw Throwables.propagate(e); } if (lineIterator == null) { throw new NoSuchElementException(); } return parser.parse(lineIterator.next()); } @Override public Runnable commit() { // Do nothing. return new Runnable() { public void run() { } }; } @Override public void close() throws IOException { objectQueue.clear(); if (lineIterator != null) { lineIterator.close(); } } }; }
From source file:org.apache.hadoop.fs.tar.TarFileSystem.java
/** * Creates an URI for base tar-ball from an URI in tar FS schema * @param tarPath/* www . java 2s .co m*/ * @return * @throws URISyntaxException */ private Path getBaseTarPath(Path tarPath) { URI uri = tarPath.toUri(); // form the prefix part String basePrefix = uri.getAuthority(); if (basePrefix != null) basePrefix = basePrefix.replaceFirst("-", "://"); else basePrefix = ""; // form the path component String basePath = uri.getPath(); // strip the part containing inFile name int lastPlusIndex = basePath.lastIndexOf(TAR_INFILESEP); if (lastPlusIndex != -1) basePath = basePath.substring(0, lastPlusIndex); basePath = basePrefix + basePath; return new Path(basePath); }
From source file:org.mule.endpoint.ResourceNameEndpointURIBuilder.java
protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException { address = StringUtils.EMPTY;//from ww w .j a va 2 s . c o m String host = uri.getHost(); if (host != null && !"localhost".equals(host)) { address = host; } String path = uri.getPath(); String authority = uri.getAuthority(); if (path != null && path.length() != 0) { if (address.length() > 0) { address += "/"; } address += path.substring(1); } else if (authority != null && !authority.equals(address)) { address += authority; int atCharIndex = -1; if (address != null && address.length() != 0 && ((atCharIndex = address.indexOf("@")) > -1)) { userInfo = address.substring(0, atCharIndex); address = address.substring(atCharIndex + 1); } } // is user info specified? int y = address.indexOf("@"); if (y > -1) { userInfo = address.substring(0, y); } // increment to 0 or one char past the @ y++; String credentials = uri.getUserInfo(); if (credentials != null && credentials.length() != 0) { userInfo = credentials; } int x = address.indexOf(":", y); if (x > -1) { String resourceInfo = address.substring(y, x); props.setProperty(RESOURCE_INFO_PROPERTY, resourceInfo); address = address.substring(x + 1); } }