Here you can find the source of getHostname(String completeUrl)
Parameter | Description |
---|---|
vDCUrl | the VDC Href to parse |
public static String getHostname(String completeUrl)
//package com.java2s; /*/*from www .j a va 2 s. c om*/ * Copyright (c) 2013 VMware, Inc. All Rights Reserved. * * 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://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed * under the License 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.MalformedURLException; import java.net.URL; public class Main { /** * This method will parse the passed in String which is presumably a complete URL and return the * base URL e.g. https://vchs.vmware.api/ from the component parts of the passed in URL. * * @param vDCUrl * the VDC Href to parse * @return the base url of the vCloud */ public static String getHostname(String completeUrl) { URL baseUrl = null; try { // First create a URL object baseUrl = new URL(completeUrl); // Now use the URL implementation to provide the component parts, leaving out // some parts so that we can build just the base URL without the path and query string return new URL(baseUrl.getProtocol(), baseUrl.getHost(), baseUrl.getPort(), "").toString(); } catch (MalformedURLException e) { throw new RuntimeException("Invalid URL: " + completeUrl); } } }