List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:org.apache.hadoop.hdfs.DFSUtil.java
/** * Lookup the HTTP / HTTPS address of the namenode, and replace its hostname * with defaultHost when it found out that the address is a wildcard / local * address./* www .j av a2 s . co m*/ * * @param defaultHost * The default host name of the namenode. * @param conf * The configuration * @param scheme * HTTP or HTTPS * @throws IOException */ public static URI getInfoServerWithDefaultHost(String defaultHost, Configuration conf, final String scheme) throws IOException { URI configuredAddr = getInfoServer(null, conf, scheme); String authority = substituteForWildcardAddress(configuredAddr.getAuthority(), defaultHost); return URI.create(scheme + "://" + authority); }
From source file:org.apache.hadoop.hive.ql.session.DependencyResolver.java
/** * * @param uri//from w w w . jav a2s. c om * @return List of URIs of downloaded jars * @throws URISyntaxException * @throws IOException */ public List<URI> downloadDependencies(URI uri) throws URISyntaxException, IOException { Map<String, Object> dependencyMap = new HashMap<String, Object>(); String authority = uri.getAuthority(); if (authority == null) { throw new URISyntaxException(authority, "Invalid url: Expected 'org:module:version', found null"); } String[] authorityTokens = authority.toLowerCase().split(":"); if (authorityTokens.length != 3) { throw new URISyntaxException(authority, "Invalid url: Expected 'org:module:version', found " + authority); } dependencyMap.put("org", authorityTokens[0]); dependencyMap.put("module", authorityTokens[1]); dependencyMap.put("version", authorityTokens[2]); Map<String, Object> queryMap = parseQueryString(uri.getQuery()); if (queryMap != null) { dependencyMap.putAll(queryMap); } return grab(dependencyMap); }
From source file:org.apache.hadoop.fs.tar.TarFileSystem.java
private void initURI(URI name, Configuration conf) { if (name.getAuthority() != null) { String uriStr = name.getScheme() + "://" + name.getAuthority(); this.uri = URI.create(uriStr); } else {/* w ww . ja v a 2 s . c o m*/ this.uri = URI.create(name.getScheme() + ":///"); } }
From source file:org.apache.falcon.hadoop.HadoopClientFactory.java
private void validateNameNode(URI uri, Configuration conf) throws FalconException { String nameNode = uri.getAuthority(); if (nameNode == null) { nameNode = getNameNode(conf);//from w w w . j ava2s . c o m if (nameNode != null) { try { new URI(nameNode).getAuthority(); } catch (URISyntaxException ex) { throw new FalconException("Exception while getting FileSystem", ex); } } } }
From source file:com.alibaba.dubbo.rpc.protocol.springmvc.support.ApacheHttpClient.java
HttpUriRequest toHttpUriRequest(Request request, Request.Options options) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException { RequestBuilder requestBuilder = RequestBuilder.create(request.method()); //per request timeouts // RequestConfig requestConfig = RequestConfig // .custom() // .setConnectTimeout(options.connectTimeoutMillis()) // .setSocketTimeout(options.readTimeoutMillis()) // .build(); //requestBuilder.setConfig(requestConfig); URI uri = new URIBuilder(request.url()).build(); requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath()); //request query params List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name()); for (NameValuePair queryParam : queryParams) { requestBuilder.addParameter(queryParam); }//from w ww . ja v a2 s . co m //request headers boolean hasAcceptHeader = false; for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) { String headerName = headerEntry.getKey(); if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) { hasAcceptHeader = true; } if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) { // The 'Content-Length' header is always set by the Apache client and it // doesn't like us to set it as well. continue; } for (String headerValue : headerEntry.getValue()) { requestBuilder.addHeader(headerName, headerValue); } } //some servers choke on the default accept string, so we'll set it to anything if (!hasAcceptHeader) { requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*"); } //request body if (request.body() != null) { HttpEntity entity = null; if (request.charset() != null) { ContentType contentType = getContentType(request); String content = new String(request.body(), request.charset()); entity = new StringEntity(content, contentType); } else { entity = new ByteArrayEntity(request.body()); } requestBuilder.setEntity(entity); } return requestBuilder.build(); }
From source file:eu.stratosphere.nephele.fs.hdfs.DistributedFileSystem.java
/** * {@inheritDoc}//from w w w . j a va2 s .c o m */ @Override public void initialize(URI name) throws IOException { // For HDFS we have to have an authority if (name.getAuthority() == null) { name = URI.create(this.conf.get("fs.default.name")); } // Initialize HDFS this.fs.initialize(name, this.conf); }
From source file:feign.httpclient.ApacheHttpClient.java
HttpUriRequest toHttpUriRequest(Request request, Request.Options options) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException { RequestBuilder requestBuilder = RequestBuilder.create(request.method()); //per request timeouts RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(options.connectTimeoutMillis()) .setSocketTimeout(options.readTimeoutMillis()).build(); requestBuilder.setConfig(requestConfig); URI uri = new URIBuilder(request.url()).build(); requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath()); //request query params List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name()); for (NameValuePair queryParam : queryParams) { requestBuilder.addParameter(queryParam); }// w ww .ja va 2 s . co m //request headers boolean hasAcceptHeader = false; for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) { String headerName = headerEntry.getKey(); if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) { hasAcceptHeader = true; } if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) { // The 'Content-Length' header is always set by the Apache client and it // doesn't like us to set it as well. continue; } for (String headerValue : headerEntry.getValue()) { requestBuilder.addHeader(headerName, headerValue); } } //some servers choke on the default accept string, so we'll set it to anything if (!hasAcceptHeader) { requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*"); } //request body if (request.body() != null) { HttpEntity entity = null; if (request.charset() != null) { ContentType contentType = getContentType(request); String content = new String(request.body(), request.charset()); entity = new StringEntity(content, contentType); } else { entity = new ByteArrayEntity(request.body()); } requestBuilder.setEntity(entity); } return requestBuilder.build(); }
From source file:org.rhq.enterprise.clientapi.RhqDownloadsScriptSourceProvider.java
@Override protected Reader doGetScriptSource(URI scriptUri) { if (remoteClient == null) { return null; }/*w w w .ja v a 2s .co m*/ String path = scriptUri.getPath(); URI remoteUri = remoteClient.getRemoteURI().resolve(URL_PATH_PREFIX + path); String replacementScheme = SecurityUtil.isTransportSecure(remoteUri.getScheme()) ? "https" : "http"; try { remoteUri = new URI(replacementScheme, remoteUri.getAuthority(), remoteUri.getPath(), remoteUri.getQuery(), remoteUri.getFragment()); } catch (URISyntaxException e) { LOG.error("Failed to copy the RHQ server download URI: " + remoteUri + " to the " + replacementScheme + " scheme."); } try { URL downloadUrl = remoteUri.toURL(); return new InputStreamReader(downloadUrl.openStream()); } catch (MalformedURLException e) { LOG.debug("Failed to download the script from the RHQ server using URL: " + remoteUri, e); } catch (IOException e) { LOG.debug("Failed to download the script from the RHQ server using URL: " + remoteUri, e); } return null; }
From source file:jp.primecloud.auto.api.ApiFilter.java
/** * * URI(Signature????)?/* www .j a v a 2 s .c om*/ * * @param decodeParamMap base64?? * @param uri URI() * @return ???URL(Signature????) */ private String createUriQueryParams(LinkedHashMap<String, String> decodeParamMap, URI uri) { String baseUriText = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath() + "?"; StringBuffer uriText = new StringBuffer(baseUriText); String splitChar = ""; for (String key : decodeParamMap.keySet()) { if (PARAM_NAME_SIGNATURE.equals(key) == false) { uriText.append(splitChar + key + "=" + decodeParamMap.get(key)); splitChar = "&"; } } return uriText.toString(); }
From source file:io.servicecomb.serviceregistry.TestRegistry.java
@Test public void testGetRealListenAddress() throws Exception { new Expectations(NetUtils.class) { {/*from w w w . j a v a 2 s . c om*/ NetUtils.getHostAddress(); result = "1.1.1.1"; } }; Assert.assertEquals("rest://172.0.0.0:8080", RegistryUtils.getPublishAddress("rest", "172.0.0.0:8080")); Assert.assertEquals(null, RegistryUtils.getPublishAddress("rest", null)); URI uri = new URI(RegistryUtils.getPublishAddress("rest", "0.0.0.0:8080")); Assert.assertEquals("1.1.1.1:8080", uri.getAuthority()); new Expectations(DynamicPropertyFactory.getInstance()) { { DynamicPropertyFactory.getInstance().getStringProperty(PUBLISH_ADDRESS, ""); result = new DynamicStringProperty(PUBLISH_ADDRESS, "") { public String get() { return "1.1.1.1"; } }; } }; Assert.assertEquals("rest://1.1.1.1:8080", RegistryUtils.getPublishAddress("rest", "172.0.0.0:8080")); InetAddress ethAddress = Mockito.mock(InetAddress.class); Mockito.when(ethAddress.getHostAddress()).thenReturn("1.1.1.1"); new Expectations(DynamicPropertyFactory.getInstance()) { { NetUtils.ensureGetInterfaceAddress("eth20"); result = ethAddress; DynamicPropertyFactory.getInstance().getStringProperty(PUBLISH_ADDRESS, ""); result = new DynamicStringProperty(PUBLISH_ADDRESS, "") { public String get() { return "{eth20}"; } }; } }; String query = URLEncodedUtils.format(Arrays.asList(new BasicNameValuePair("country", " ")), StandardCharsets.UTF_8.name()); Assert.assertEquals("rest://1.1.1.1:8080?" + query, RegistryUtils.getPublishAddress("rest", "172.0.0.0:8080?" + query)); }