List of usage examples for java.net URI getHost
public String getHost()
From source file:com.sap.core.odata.testutil.tool.core.SupaController.java
private void init() { httpClient = new DefaultHttpClient(); if (config.isProxySet()) { initProxy();/*from w w w . j a v a2s . co m*/ } if (config.isBasicAuthCredentialsSet()) { final URI baseUri = config.getBaseUri(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(baseUri.getHost(), baseUri.getPort()), new UsernamePasswordCredentials(config.getBasicAuthCredentials())); } }
From source file:com.bodeme.easycloud.syncadapter.EnterCredentialsFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { boolean ok = editUserName.getText().length() > 0 && editPassword.getText().length() > 0; // check host name if (Constants.OWNCLOUD_URL == null) { try {//www .java 2s .c om URI uri = new URI(URIUtils.sanitize(editURL.getText().toString())); if (StringUtils.isBlank(uri.getHost())) ok = false; } catch (URISyntaxException e) { ok = false; } } MenuItem item = menu.findItem(R.id.next); item.setEnabled(ok); }
From source file:com.thoughtworks.go.util.command.UrlArgument.java
@Override public String forDisplay() { try {/*from www. j a va 2 s. co m*/ URI uri = new URI(sanitizeUrl()); if (uri.getUserInfo() != null) { uri = new URI(uri.getScheme(), clean(uri.getScheme(), uri.getUserInfo()), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } return uri.toString(); } catch (URISyntaxException e) { return url; } }
From source file:com.rinxor.cloud.cloudstack.api.CloudstackClient.java
public CloudstackResponse executeConsoleGetRedirect(CloudstackRequest cloudstackRequest) { CloudstackResponse cloudstackResponse = new CloudstackResponse(); try {//from w w w.j av a 2 s.c o m HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet( CloudstackAPI.buildApiRequestURL(cfg.getConsoleUrl(), cloudstackRequest.getUrlCommand())); getRequest.addHeader("Cookie", cloudstackRequest.getCookie()); getRequest.addHeader("Referer", cloudstackRequest.getReferer()); URI u = new URI(cfg.getConsoleUrl()); getRequest.addHeader("Host", u.getHost() + ":" + u.getPort()); HttpResponse response = httpClient.execute(getRequest); String responseString = new BasicResponseHandler().handleResponse(response); cloudstackResponse.setStatusCode(response.getStatusLine().getStatusCode()); cloudstackResponse.setResponseBody(responseString); } catch (ClientProtocolException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } return cloudstackResponse; }
From source file:com.rinxor.cloud.cloudstack.api.CloudstackClient.java
public CloudstackResponse executeApiGetRedirect(CloudstackRequest cloudstackRequest) { CloudstackResponse cloudstackResponse = new CloudstackResponse(); try {/*from ww w . j a va 2 s . c om*/ HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet( CloudstackAPI.buildApiRequestURL(cfg.getApiUrl(), cloudstackRequest.getUrlCommand())); // login do not require Cookie but we send. getRequest.addHeader("Cookie", cloudstackRequest.getCookie()); getRequest.addHeader("Referer", cloudstackRequest.getReferer()); URI u = new URI(cfg.getApiUrl()); getRequest.addHeader("Host", u.getHost() + ":" + u.getPort()); HttpResponse response = httpClient.execute(getRequest); cloudstackResponse.setStatusCode(response.getStatusLine().getStatusCode()); cloudstackResponse.setResponseBody(EntityUtils.toString(response.getEntity())); // login response we must send cookie back to client if (response.getFirstHeader("Set-Cookie") != null) { cloudstackResponse.setSetCookie(response.getFirstHeader("Set-Cookie").getValue()); } } catch (ClientProtocolException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } return cloudstackResponse; }
From source file:com.seajas.search.profiler.service.category.CategoryService.java
/** * Fill the RSS category based on those domains not belonging to any other categories. * * @param rssCategory//from w w w. j a v a 2s. co m * @param feeds */ private void fillRssCategory(final FeedCategory rssCategory, final List<Feed> feeds, final List<FeedCategory> otherCategories, final Boolean includeDisabled) { for (Feed feed : feeds) { if (!includeDisabled && !feed.getIsEnabled()) continue; for (FeedUrl feedUrl : feed.getFeedUrls()) { URI uri = URI.create(feedUrl.getUrl()); if (uri != null) { String host = uri.getHost(), cleanHost = cleanUrl(host); // Check if it already exists if (!exists(cleanHost, otherCategories) && !exists(cleanHost, rssCategory)) { FeedCategoryDomain domain = new FeedCategoryDomain(); domain.setUrl(cleanHost); domain.setOriginal(Arrays.asList(host)); rssCategory.getDomains().add(domain); } } } } }
From source file:io.druid.storage.google.GoogleDataSegmentPuller.java
@Override public InputStream getInputStream(URI uri) throws IOException { String path = uri.getPath();/*from w w w . ja v a 2 s .c o m*/ if (path.startsWith("/")) { path = path.substring(1); } return storage.get(uri.getHost(), path); }
From source file:ddf.registry.server.rest.internal.RestRegistryServer.java
/** * Combines the URI and relative URL to form a full URL for external clients to use. * * @param registryUri URI from the calling context * @param relativeUrl URL Relative URL for a service * @return Absolute URL for the service//from w w w . j a v a 2 s.c o m */ private String combineUrl(URI registryUri, String relativeUrl) { StringBuilder serviceUrl = new StringBuilder(); serviceUrl.append(registryUri.getScheme()); serviceUrl.append("://"); serviceUrl.append(registryUri.getHost()); serviceUrl.append(":"); serviceUrl.append(registryUri.getPort()); serviceUrl.append(relativeUrl); return serviceUrl.toString(); }
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java
/** * Get the {@link AuthScope} for the {@link #server} * //w ww.ja v a 2 s .c o m * @return the {@link AuthScope} */ private AuthScope getAuthScope() { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; try { final URI hostUri = new URI(server.getHost()); host = hostUri.getHost(); if (hostUri.getPort() > -1) { port = hostUri.getPort(); } else if ("http".equalsIgnoreCase(hostUri.getScheme())) { port = 80; } else if ("https".equalsIgnoreCase(hostUri.getScheme())) { port = 443; } } catch (URISyntaxException e) { // Failed to parse the server host URI // Fall-back on preset defaults log.error("Failed to parse the host URI", e); } return new AuthScope(host, port, "realm"); }
From source file:org.stem.ClusterManagerDaemon.java
private HttpServer createServer(URI uri, ResourceConfig resourceCfg) { final String host = uri.getHost(); final int port = uri.getPort(); final HttpServer server = new HttpServer(); final NetworkListener listener = new NetworkListener("grizzly", host, port); listener.getTransport().setWorkerThreadPoolConfig(adjustThreadPool()); server.addListener(listener);//ww w. java2s.c om final ServerConfiguration config = server.getServerConfiguration(); final HttpHandler handler = ContainerFactory.createContainer(HttpHandler.class, resourceCfg); if (handler != null) config.addHttpHandler(handler, uri.getPath()); return server; }