Java URI Create getUriByEndpoint(String endpoint)

Here you can find the source of getUriByEndpoint(String endpoint)

Description

Get the URI object for the given endpoint.

License

Apache License

Declaration

private static URI getUriByEndpoint(String endpoint) 

Method Source Code

//package com.java2s;
/*/*  w ww  .j ava  2  s  . c om*/
 * Copyright 2013-2016 Amazon Technologies, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *    http://aws.amazon.com/apache2.0
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and
 * limitations under the License.
 */

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**
     * Get the URI object for the given endpoint. URI class cannot correctly
     * parse the endpoint if it doesn't include protocol. This method will add
     * the protocol if this happens.
     */
    private static URI getUriByEndpoint(String endpoint) {
        URI targetEndpointUri = null;
        try {
            targetEndpointUri = new URI(endpoint);
            if (targetEndpointUri.getHost() == null) {
                targetEndpointUri = new URI("http://" + endpoint);
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException("Unable to parse service endpoint: " + e.getMessage());
        }
        return targetEndpointUri;
    }
}

Related

  1. getURI(String protocol, String authority, String path, Hashtable params)
  2. getUri(String s, String h, int p, String path)
  3. getURI(String spec)
  4. getUri(String uriName)
  5. getURIAddress(URI uri)
  6. getURIFilename(final String s)
  7. getURIFromEncodedString(String unencoded)
  8. getURIFromPath(String fileOrURI)
  9. getURIFromPath(String path)