List of usage examples for com.squareup.okhttp HttpUrl.Builder port
int port
To view the source code for com.squareup.okhttp HttpUrl.Builder port.
Click Source Link
From source file:io.minio.MinioClient.java
License:Apache License
/** * Creates Minio client object using given endpoint, port, access key, secret key and secure option. * * </p><b>Example:</b><br> * <pre>{@code MinioClient minioClient = * new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false); * }</pre>// w w w .j ava 2 s . c o m * * @param endpoint Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.<pre> * Valid endpoints: * * https://s3.amazonaws.com * * https://s3.amazonaws.com/ * * https://play.minio.io:9000 * * http://play.minio.io:9010/ * * localhost * * localhost.localdomain * * play.minio.io * * 127.0.0.1 * * 192.168.1.60 * * ::1</pre> * * @param port Valid port. It should be in between 1 and 65535. Unused if endpoint is an URL. * @param accessKey Access key to access service in endpoint. * @param secretKey Secret key to access service in endpoint. * @param secure If true, access endpoint using HTTPS else access it using HTTP. * * @see #MinioClient(String endpoint) * @see #MinioClient(URL url) * @see #MinioClient(String endpoint, String accessKey, String secretKey) * @see #MinioClient(URL url, String accessKey, String secretKey) * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) */ public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException { if (endpoint == null) { throw new InvalidEndpointException(NULL_STRING, "null endpoint"); } if (port < 0 || port > 65535) { throw new InvalidPortException(port, "port must be in range of 1 to 65535"); } HttpUrl url = HttpUrl.parse(endpoint); if (url != null) { if (!"/".equals(url.encodedPath())) { throw new InvalidEndpointException(endpoint, "no path allowed in endpoint"); } // treat Amazon S3 host as special case String amzHost = url.host(); if (amzHost.endsWith(AMAZONAWS_COM) && !amzHost.equals(S3_AMAZONAWS_COM)) { throw new InvalidEndpointException(endpoint, "for Amazon S3, host should be 's3.amazonaws.com' in endpoint"); } HttpUrl.Builder urlBuilder = url.newBuilder(); Scheme scheme = Scheme.HTTP; if (secure) { scheme = Scheme.HTTPS; } urlBuilder.scheme(scheme.toString()); if (port > 0) { urlBuilder.port(port); } this.baseUrl = urlBuilder.build(); this.accessKey = accessKey; this.secretKey = secretKey; return; } // endpoint may be a valid hostname, IPv4 or IPv6 address if (!this.isValidEndpoint(endpoint)) { throw new InvalidEndpointException(endpoint, "invalid host"); } // treat Amazon S3 host as special case if (endpoint.endsWith(AMAZONAWS_COM) && !endpoint.equals(S3_AMAZONAWS_COM)) { throw new InvalidEndpointException(endpoint, "for amazon S3, host should be 's3.amazonaws.com'"); } Scheme scheme = Scheme.HTTP; if (secure) { scheme = Scheme.HTTPS; } if (port == 0) { this.baseUrl = new HttpUrl.Builder().scheme(scheme.toString()).host(endpoint).build(); } else { this.baseUrl = new HttpUrl.Builder().scheme(scheme.toString()).host(endpoint).port(port).build(); } this.accessKey = accessKey; this.secretKey = secretKey; }