Example usage for java.net URI getPort

List of usage examples for java.net URI getPort

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Returns the port number of this URI.

Usage

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:com.xx_dev.apn.proxy.utils.HostNamePortUtil.java

public static int getPort(HttpRequest httpRequest) {
    int originalPort = 80;

    if (httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalPort = 443;/*  ww  w.j av a2s  .c o  m*/
    }

    String originalHostHeader = httpRequest.headers().get(HttpHeaders.Names.HOST);

    if (StringUtils.isBlank(originalHostHeader) && httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalHostHeader = httpRequest.getUri();
    }

    if (StringUtils.isNotBlank(originalHostHeader)) {
        if (StringUtils.split(originalHostHeader, ": ").length == 2) {
            originalPort = Integer.parseInt(StringUtils.split(originalHostHeader, ": ")[1]);
        }
    } else {
        String uriStr = httpRequest.getUri();
        try {
            URI uri = URI.create(uriStr);

            if (uri.getPort() > 0) {
                originalPort = uri.getPort();
            }
        } catch (IllegalArgumentException e) {
            logger.error(e.getMessage(), e);
            originalPort = -1;
        }
    }

    return originalPort;
}

From source file:org.thoughtcrime.securesms.mms.MmsDownloadHelper.java

private static byte[] makeRequest(MmsConnectionParameters connectionParameters, String url)
        throws ClientProtocolException, IOException {
    try {/*from  ww  w  .  j av a 2 s.c o 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");
    }
}

From source file:com.amazon.s3.util.HttpUtils.java

/**
 * Returns true if the specified URI is using a non-standard port (i.e. any
 * port other than 80 for HTTP URIs or any port other than 443 for HTTPS
 * URIs)./*from ww w .  jav a 2  s .c om*/
 * 
 * @param uri
 * 
 * @return True if the specified URI is using a non-standard port, otherwise
 *         false.
 */
public static boolean isUsingNonDefaultPort(URI uri) {
    String scheme = uri.getScheme().toLowerCase();
    int port = uri.getPort();

    if (port <= 0)
        return false;
    if (scheme.equals("http") && port == 80)
        return false;
    if (scheme.equals("https") && port == 443)
        return false;

    return true;
}

From source file:org.thoughtcrime.securesms.mms.MmsSendHelper.java

private static byte[] makePost(MmsConnectionParameters parameters, byte[] mms)
        throws ClientProtocolException, IOException {
    Log.w("MmsSender", "Sending MMS1 of length: " + mms.length);
    try {/*w  w w  . j  a  v a  2 s .  com*/
        HttpClient client = constructHttpClient(parameters);
        URI hostUrl = new URI(parameters.getMmsc());
        HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.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");

        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");
    }
}

From source file:com.knowledgecode.cordova.websocket.ConnectionTask.java

/**
 * Complement default port number.//from   w w w. ja  v  a  2  s  .  co  m
 *
 * @param url
 * @return URI
 * @throws URISyntaxException
 */
private static URI complementPort(String url) throws URISyntaxException {
    URI uri = new URI(url);
    int port = uri.getPort();

    if (port < 0) {
        if ("ws".equals(uri.getScheme())) {
            port = 80;
        } else if ("wss".equals(uri.getScheme())) {
            port = 443;
        }
        uri = new URI(uri.getScheme(), "", uri.getHost(), port, uri.getPath(), uri.getQuery(), "");
    }
    return uri;
}

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

private static int getPort(URI uri) {
    int port = uri.getPort();
    if (port == -1) {
        if (("https").equalsIgnoreCase(uri.getScheme())) {
            port = 443;/*from  w ww  . jav a 2  s.  co m*/
        } else if (("http").equalsIgnoreCase(uri.getScheme())) {
            port = 80;
        }
    }
    return port;
}

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

private static byte[] makeRequest(Context context, MmsConnectionParameters connectionParameters, String url)
        throws IOException {
    AndroidHttpClient client = null;/*from ww w. j  a v  a 2 s.  c o m*/

    try {
        client = constructHttpClient(context, connectionParameters);
        URI targetUrl = new URI(url.trim());
        HttpHost target = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
        HttpGet request = new HttpGet(url.trim());

        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("MmsDownloadHelper", use);
        throw new IOException("Couldn't parse URI");
    } finally {
        if (client != null)
            client.close();
    }
}

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 {//from w  ww  . j  a v  a 2  s .c  om
        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();
        }
    }
}