package com.eactive.eai.common.circuitBreaker.type;

import java.net.URI;

public class URLUtils {
	public static URI createURI(String uri) {
		return URI.create(uri);
	}

	public static String getURLWithoutQuery(URI uri) {
		String result = uri.getScheme() + "://" + uri.getHost();
		if (uri.getPort() != -1) {
			result = result + ":" + uri.getPort();
		}

		result = result + uri.getPath();
		return result;
	}

	public static String getHost(URI uri) {
		return uri.getHost();
	}

	public static void main(String[] args) throws Exception {
		URI uri = URI.create("http://localhost:8001/path?query=a");
		System.out.println(uri.getHost());
		System.out.println(uri.getPath());
		System.out.println(uri.toString());
		System.out.println(uri.getRawPath());
		System.out.println(uri.toURL());
		System.out.println(getURLWithoutQuery(uri));
		System.out.println(getHost(uri));
		uri = URI.create("http://localhost/path?query=a");
		System.out.println(getURLWithoutQuery(uri));
		System.out.println(getHost(uri));
		uri = URI.create("http://localhost/path?query=a");
		System.out.println(getURLWithoutQuery(uri));
		System.out.println(getHost(uri));
		uri = URI.create("http://127.0.0.1/path?query=a");
		System.out.println(getURLWithoutQuery(uri));
		System.out.println(getHost(uri));
		uri = URI.create("http://www.example.com:8080/test/path?query=a");
		System.out.println(getURLWithoutQuery(uri));
		System.out.println(getHost(uri));
	}
}