List of usage examples for java.net URI getHost
public String getHost()
From source file:Main.java
/** * Removes query parameters from url (only for logging, as query parameters may contain sensible informations) * * @param uri/*ww w. j a va 2 s .c o m*/ * @return URI without parameters */ public static String shortenUrl(URI uri) { return uri.getScheme() + "://" + uri.getHost() + uri.getPath(); }
From source file:Main.java
/** * Given an endpoint, calculate the corresponding BrowserID audience. * <p>/*from w ww . j a va 2 s .c o m*/ * This is the domain, in web parlance. * * @param serverURI endpoint. * @return BrowserID audience. * @throws URISyntaxException */ public static String getAudienceForURL(String serverURI) throws URISyntaxException { URI uri = new URI(serverURI); return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), null, null, null).toString(); }
From source file:Main.java
public static String parseRegionName(URI endpoint) { String host = endpoint.getHost(); // If we don't recognize the domain, just return the default if (!host.endsWith(".amazonaws.com")) return "us-east-1"; String serviceAndRegion = host.substring(0, host.indexOf(".amazonaws.com")); // S3 is different from other services, which supports virtual host and // use '-' as separator, the host may look like // 'bucketName.s3-us-west-2.amazonaws.com' if (serviceAndRegion.contains("s3-")) { return serviceAndRegion.substring(serviceAndRegion.lastIndexOf("s3-") + 3); }//from w w w. j a va2 s . c o m char separator = '.'; if (serviceAndRegion.indexOf(separator) == -1) return "us-east-1"; String region = serviceAndRegion.substring(serviceAndRegion.indexOf(separator) + 1); if ("us-gov".equals(region)) { return "us-gov-west-1"; } return region; }
From source file:Main.java
public static String getDomainName(String url) { String domain = ""; URI uri; try {//www . ja v a 2 s. c o m uri = new URI(url); domain = uri.getHost(); } catch (URISyntaxException e) { e.printStackTrace(); } return domain.startsWith("www.") ? domain.substring(4) : domain; }
From source file:Main.java
public static String parseServiceName(URI endpoint) { String host = endpoint.getHost(); // If we don't recognize the domain, throw an exception. if (!host.endsWith(".amazonaws.com")) { throw new IllegalArgumentException("Cannot parse the service name by an unrecognized endpoint(" + host + "). Please specify the service name by setEndpoint(String endpoint, String serviceName, String regionId)."); }/*from w w w . j a v a 2 s . c om*/ String serviceAndRegion = host.substring(0, host.indexOf(".amazonaws.com")); // S3 is different from other services, which supports virtual host and // use '-' as separator, the host may look like // 'bucketName.s3-us-west-2.amazonaws.com' if (serviceAndRegion.contains("s3-")) { return "s3"; } char separator = '.'; // If we don't detect a separator between service name and region, then // assume that the region is not included in the hostname, and it's only // the service name (ex: "http://iam.amazonaws.com"). if (serviceAndRegion.indexOf(separator) == -1) return serviceAndRegion; String service = serviceAndRegion.substring(0, serviceAndRegion.indexOf(separator)); return service; }
From source file:com.jayway.restassured.internal.UriValidator.java
/** * Checks if the <code>potentialUri</code> is a URI. * * @param potentialUri The URI to check. * @return <code>true</code> if it is a URI, <code>false</code> otherwise. *//*from ww w. java 2s. c o m*/ public static boolean isUri(String potentialUri) { if (StringUtils.isBlank(potentialUri)) { return false; } try { URI uri = new URI(potentialUri); return uri.getScheme() != null && uri.getHost() != null; } catch (URISyntaxException e) { return false; } }
From source file:de.mpg.imeji.presentation.util.SearchAndExportHelper.java
public static String getCitation(Publication publication) { URI uri = publication.getUri(); URI searchAndExportUri = URI.create("http://" + uri.getHost() + "/search/SearchAndExport"); String itemId = null;// w w w .j a v a 2 s.c o m if (uri.getQuery() != null && uri.getQuery().contains("itemId=")) { itemId = uri.getQuery().split("itemId=")[1]; } else if (uri.getPath() != null && uri.getPath().contains("/item/")) { itemId = uri.getPath().split("/item/")[1]; } if (UrlHelper.isValidURI(searchAndExportUri)) { try { HttpClient client = new HttpClient(); String exportUri = searchAndExportUri.toString() + "?cqlQuery=" + URLEncoder.encode( "escidoc.objid=" + itemId + " or escidoc.property.version.objid=" + itemId, "ISO-8859-1") + "&exportFormat=" + publication.getExportFormat() + "&outputFormat=html_linked"; GetMethod method = new GetMethod(exportUri); client.executeMethod(method); return method.getResponseBodyAsString(); } catch (Exception e) { return null; } } return null; }
From source file:com.netdimensions.client.Client.java
private static HttpHost host(final URI url) { return new HttpHost(url.getHost(), url.getPort(), url.getScheme()); }
From source file:com.netdimensions.client.Client.java
private static AuthScope authScope(final URI url) { return new AuthScope(url.getHost(), url.getPort() == -1 ? defaultPort(url.getScheme()) : url.getPort()); }
From source file:org.thoughtcrime.securesms.mms.MmsDownloadHelper.java
private static byte[] makeRequest(MmsConnectionParameters connectionParameters, String url) throws ClientProtocolException, IOException { try {/* w w w .j av a2 s .co m*/ HttpClient client = constructHttpClient(connectionParameters); URI hostUrl = new URI(url); HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); HttpRequest request = new HttpGet(url); request.setParams(client.getParams()); request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); HttpResponse response = client.execute(target, request); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase()); return parseResponse(response.getEntity()); } catch (URISyntaxException use) { Log.w("MmsDownlader", use); throw new IOException("Bad URI syntax"); } }