Example usage for java.net URI getHost

List of usage examples for java.net URI getHost

Introduction

In this page you can find the example usage for java.net URI getHost.

Prototype

public String getHost() 

Source Link

Document

Returns the host component of this URI.

Usage

From source file:org.fdroid.enigtext.mms.MmsSendHelper.java

private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms)
        throws ClientProtocolException, IOException {
    AndroidHttpClient client = null;/*  w  w  w  .  j  a v a  2 s .c  o m*/

    try {
        Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null"));
        client = constructHttpClient(context, parameters);
        URI targetUrl = new URI(parameters.getMmsc());

        if (Util.isEmpty(targetUrl.getHost()))
            throw new IOException("Invalid target host: " + targetUrl.getHost() + " , " + targetUrl);

        HttpHost target = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
        HttpPost request = new HttpPost(parameters.getMmsc());
        ByteArrayEntity entity = new ByteArrayEntity(mms);

        entity.setContentType("application/vnd.wap.mms-message");

        request.setEntity(entity);
        request.setParams(client.getParams());
        request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
        request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
        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("MmsSendHelper", use);
        throw new IOException("Couldn't parse URI.");
    } finally {
        if (client != null)
            client.close();
    }
}

From source file:com.xx_dev.apn.proxy.utils.HostNamePortUtil.java

public static String getHostName(HttpRequest httpRequest) {
    String originalHostHeader = httpRequest.headers().get(HttpHeaders.Names.HOST);

    if (StringUtils.isBlank(originalHostHeader) && httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalHostHeader = httpRequest.getUri();
    }/*from   ww  w  . jav  a 2 s  .c o m*/

    if (StringUtils.isNotBlank(originalHostHeader)) {
        String originalHost = StringUtils.split(originalHostHeader, ": ")[0];
        return originalHost;
    } else {
        String uriStr = httpRequest.getUri();
        try {
            URI uri = new URI(uriStr);

            String schema = uri.getScheme();

            String originalHost = uri.getHost();

            return originalHost;
        } catch (URISyntaxException e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
}

From source file:org.brutusin.rpc.RpcUtils.java

public static boolean doOriginsMatch(String origin1, String origin2) {
    try {/*from w  ww  .  j  a  v a2s. c  o m*/
        if (origin1 == null || origin2 == null) {
            return false;
        }
        if (origin1.equals("*") || origin2.equals("*")) {
            return true;
        }
        URI uri1 = getURI(origin1);
        URI uri2 = getURI(origin2);
        if (!uri1.getHost().equals(uri2.getHost())) {
            return false;
        }
        return getPort(uri1) == getPort(uri2);
    } catch (URISyntaxException ex) {
        return false;
    }
}

From source file:cf.service.integration.FunctionalTest.java

private static String localIp(String cloudControllerUri) {
    final URI uri = URI.create(cloudControllerUri);
    final int port = uri.getPort() == -1 ? 80 : uri.getPort();
    try (Socket socket = new Socket(uri.getHost(), port)) {
        return socket.getLocalAddress().getHostAddress();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }/*w  ww  . j a  va  2s .co m*/
}

From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java

public static OpenIdConfiguration getButDontSave(String baseUrl) throws Exception {

    String url = baseUrl + endpoint;
    System.out.println("URL is '" + url + "'");
    HttpClient client = ServerUtils.getClient();
    URI uri = new URI(url);
    HttpGet get = new HttpGet(uri);
    HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    HttpResponse response = client.execute(host, get);
    try {/*  ww  w.  j  a va 2s .c  o  m*/
        HttpEntity entity2 = response.getEntity();
        String res = EntityUtils.toString(entity2);
        EntityUtils.consume(entity2);
        ObjectMapper mapper = new ObjectMapper();
        //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com");
        OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class);

        return openIdConfigInstance;
    } finally {
        if (response instanceof CloseableHttpResponse) {
            ((CloseableHttpResponse) response).close();
        }
    }
}

From source file:org.ow2.bonita.facade.rest.apachehttpclient.ApacheHttpClientUtil.java

public static HttpClient getHttpClient(String serverAddress, String username, String password)
        throws URISyntaxException {
    URI serverURI = new URI(serverAddress);
    DefaultHttpClient client = new DefaultHttpClient();
    AuthScope authScope = new AuthScope(serverURI.getHost(), serverURI.getPort(), AuthScope.ANY_REALM,
            AuthScope.ANY_SCHEME);/*  w  w w.  j  av a  2 s  . c  o  m*/
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    client.getCredentialsProvider().setCredentials(authScope, credentials);
    return client;
}

From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java

public static OpenIdConfiguration getInstance(String tenantName) throws Exception {
    if (configMap.containsKey(tenantName.toLowerCase())) {
        return configMap.get(tenantName.toLowerCase());
    }/*from  w  w w  . ja  v  a 2  s . co m*/
    String url = ServerUtils.getIDCSBaseURL(tenantName) + endpoint;
    System.out.println("URL for tenant '" + tenantName + "' is '" + url + "'");
    HttpClient client = ServerUtils.getClient(tenantName);
    URI uri = new URI(url);
    HttpGet get = new HttpGet(uri);
    HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    HttpResponse response = client.execute(host, get);
    try {
        HttpEntity entity2 = response.getEntity();
        String res = EntityUtils.toString(entity2);
        EntityUtils.consume(entity2);
        ObjectMapper mapper = new ObjectMapper();
        //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com");
        OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class);

        configMap.put(tenantName.toLowerCase(), openIdConfigInstance);
        return openIdConfigInstance;
    } finally {
        if (response instanceof CloseableHttpResponse) {
            ((CloseableHttpResponse) response).close();
        }
    }
}

From source file:org.lightcouch.URIBuilder.java

public static URIBuilder buildUri(URI uri) {
    URIBuilder builder = URIBuilder.buildUri().scheme(uri.getScheme()).host(uri.getHost()).port(uri.getPort())
            .path(uri.getPath());//from  w  ww  .  j ava2 s.c om
    return builder;
}

From source file:com.microsoft.windowsazure.core.pipeline.apache.HttpServiceRequestContext.java

private static boolean isFullURI(URI uri) {
    if (uri == null) {
        return false;
    }/*from  w  w w .  ja  v a 2s. c o m*/
    String host = uri.getHost();
    if (host == null || host.length() == 0) {
        return false;
    }
    return true;
}

From source file:org.onebusaway.io.client.test.UriAssert.java

/**
 * Check request for matching Uri./*from   ww w  .j  a  v a 2  s  .  c o m*/
 *
 * @param expectedUri   The Uri the test should expect (query values are ignored, use
 *                      expectedQuery)
 * @param expectedQuery A Map of query key/values required to be in the Uri.
 *                      Use asterisk to require key, but ignore value. Order is irrelevant.
 *                      The list is not exhaustive, extra key/values are ignored.
 */
public static void assertUriMatch(URI expectedUri, Map<String, String> expectedQuery, URI actualUri) {
    assertEquals(expectedUri.getHost(), actualUri.getHost());
    assertEquals(expectedUri.getScheme(), actualUri.getScheme());
    assertEquals(expectedUri.getPath(), actualUri.getPath());
    List<NameValuePair> actualParams = URLEncodedUtils.parse(actualUri, "UTF-8");

    if (expectedQuery != null) {
        for (Map.Entry<String, String> entry : expectedQuery.entrySet()) {
            String expectedValue = entry.getValue();
            String actualValue = null;

            // Find actual param
            for (NameValuePair pair : actualParams) {
                if (pair.getName().equalsIgnoreCase(entry.getKey())) {
                    actualValue = pair.getValue();
                }
            }

            if ("*".equals(expectedValue)) {
                assertNotNull("URI missing key \"" + entry.getKey() + "\"", actualValue);
            } else {
                assertEquals("URI mismatch on query key \"" + entry.getKey() + "\"", expectedValue,
                        actualValue);
            }
        }
    }
}