Example usage for java.net URL getHost

List of usage examples for java.net URL getHost

Introduction

In this page you can find the example usage for java.net URL getHost.

Prototype

public String getHost() 

Source Link

Document

Gets the host name of this URL , if applicable.

Usage

From source file:org.openbaton.nfvo.vnfm_reg.impl.register.RestRegister.java

@Scheduled(initialDelay = 15000, fixedDelay = 20000)
public void checkHeartBeat() throws MalformedURLException {
    for (VnfmManagerEndpoint endpoint : vnfmEndpointRepository.findAll()) {
        if (endpoint.getEndpointType().ordinal() == EndpointType.REST.ordinal()) {
            if (endpoint.isEnabled()) {
                try {
                    URL url = new URL(endpoint.getEndpoint());
                    if (!pingHost(url.getHost(), url.getPort(), 2)) {
                        if (endpoint.isActive()) {
                            log.info("Set endpoint " + endpoint.getType() + " to unactive");
                            endpoint.setActive(false);
                            vnfmEndpointRepository.save(endpoint);
                        }/* ww  w  . ja va  2s. c  o  m*/
                    } else {
                        if (!endpoint.isActive()) {
                            log.info("Set endpoint " + endpoint.getType() + " to active");
                            endpoint.setActive(true);
                            vnfmEndpointRepository.save(endpoint);
                        }
                    }
                } catch (MalformedURLException ignored) {
                    if (endpoint.isActive()) {
                        log.warn("Not able to check endpoint: " + endpoint.getEndpoint());
                        endpoint.setActive(false);
                        vnfmEndpointRepository.save(endpoint);
                    }
                }
            }
        }
    }
}

From source file:edu.brandeis.cs.planner.service.Metadata.java

protected void init() {
    boolean use_proxy = ConfigXML.config().getBoolean("connection/proxies/use_proxy");
    if (use_proxy) {
        client.setProxy(ConfigXML.config().getString("connection/proxies/http_proxy"));
    }/*from ww  w .  ja  va 2  s .  c o m*/
    String service_manager = ConfigXML.config().getString("grids/grid/service_manager");
    try {
        URL url = new URL(service_manager);
        String host = url.getHost();
        int port = url.getPort();
        username = ConfigXML.config().getString(
                "connection/credentials/credential[@host='" + host + "' and @port='" + port + "']/username");
        password = ConfigXML.config().getString(
                "connection/credentials/credential[@host='" + host + "' and @port='" + port + "']/password");
        logger.debug("host={}", host);
        logger.debug("port={}", port);
        logger.debug("username={}", username);
    } catch (MalformedURLException e) {
        logger.warn("Wrong Service Manager", e);
        e.printStackTrace();
    }
    for (String wsdlString : wsdls) {
        String metadataString = callMetadata(wsdlString);
        metadataJsons.add(metadataString);
    }
}

From source file:sh.calaba.driver.model.CalabashAndroidDriver.java

public CalabashAndroidDriver(String remoteURL, Map<String, Object> capabilities) {
    this.remoteURL = remoteURL;
    this.requestedCapabilities = capabilities;
    try {//from  w ww  . j  ava  2  s. c  o m
        URL url = new URL(remoteURL);
        port = url.getPort();
        host = url.getHost();
        session = start();
    } catch (Exception e) {
        if (e instanceof CalabashException) {
            throw (CalabashException) e;
        }
        e.printStackTrace();

        throw new CalabashException(e);
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlMeta.java

/**
 * Handles the cookies specified in meta tags,
 * like <tt>&lt;meta http-equiv='set-cookie' content='webm=none; path=/;'&gt;</tt>.
 *//* ww w  .j a v  a  2  s  . c  o  m*/
protected void performSetCookie() {
    final String[] parts = COOKIES_SPLIT_PATTERN.split(getContentAttribute(), 0);
    final String name = StringUtils.substringBefore(parts[0], "=");
    final String value = StringUtils.substringAfter(parts[0], "=");
    final URL url = getPage().getUrl();
    final String host = url.getHost();
    final boolean secure = "https".equals(url.getProtocol());
    String path = null;
    Date expires = null;
    for (int i = 1; i < parts.length; i++) {
        final String partName = StringUtils.substringBefore(parts[i], "=").trim().toLowerCase();
        final String partValue = StringUtils.substringAfter(parts[i], "=").trim();
        if ("path".equals(partName)) {
            path = partValue;
        } else if ("expires".equals(partName)) {
            expires = com.gargoylesoftware.htmlunit.util.StringUtils.parseHttpDate(partValue);
        } else {
            notifyIncorrectness("set-cookie http-equiv meta tag: unknown attribute '" + partName + "'.");
        }
    }
    final Cookie cookie = new Cookie(host, name, value, path, expires, secure);
    getPage().getWebClient().getCookieManager().addCookie(cookie);
}

From source file:bad.robot.http.apache.matchers.CredentialsMatcher.java

private CredentialsMatcher(URL url, String username, String password) {
    this.username = username;
    this.password = password;
    this.scope = new AuthScope(url.getHost(), url.getPort(), ANY_REALM, ANY_SCHEME);
}

From source file:com.brightcove.com.zartan.verifier.video.VideoStillVerifier.java

@ZartanCheck(value = "VideoStill is on the http cdn")
public ResultEnum assertVideoStillCDNCorrect(UploadData upData) throws Throwable {
    URL u = getStillUrl(upData);
    assertEquals("VideoStill should be on the PD", upData.getmAccount().getPdCdn().getHostName(), u.getHost());
    return ResultEnum.PASS;
}

From source file:com.dianping.cosmos.monitor.HttpClientService.java

private HttpUriRequest getGetRequest(String url, boolean useURI) throws Exception {
    HttpUriRequest request;//from   ww  w  .  j  a v  a  2 s . c  o m
    if (useURI) {
        URL requestURL = new URL(url);
        URI uri = new URI(requestURL.getProtocol(), null, requestURL.getHost(), requestURL.getPort(),
                requestURL.getPath(), requestURL.getQuery(), null);
        request = new HttpGet(uri);
    } else {
        request = new HttpGet(url);
    }
    return request;
}

From source file:com.ge.predix.sample.blobstore.connector.spring.BlobstoreServiceConnectorCreator.java

/**
 * Creates the BlobStore context using S3Client
 *
 * @param serviceInfo Object Store Service Info Object
 * @param serviceConnectorConfig Cloud Foundry Service Connector Configuration
 *
 * @return BlobstoreService Instance of the ObjectStore Service
 */// www  .  j  a va  2  s .  com
@Override
public BlobstoreService create(BlobstoreServiceInfo serviceInfo,
        ServiceConnectorConfig serviceConnectorConfig) {
    log.info("create() invoked with serviceInfo? = " + (serviceInfo == null));
    ClientConfiguration config = new ClientConfiguration();
    config.setProtocol(Protocol.HTTPS);

    S3ClientOptions options = new S3ClientOptions();
    config.setSignerOverride("S3SignerType");

    BasicAWSCredentials creds = new BasicAWSCredentials(serviceInfo.getObjectStoreAccessKey(),
            serviceInfo.getObjectStoreSecretKey());
    AmazonS3Client s3Client = new AmazonS3Client(creds, config);
    s3Client.setEndpoint(serviceInfo.getUrl());
    s3Client.setS3ClientOptions(options);

    try {
        // Remove the Credentials from the Object Store URL
        URL url = new URL(serviceInfo.getUrl());
        String urlWithoutCredentials = url.getProtocol() + "://" + url.getHost();

        // Return BlobstoreService
        return new BlobstoreService(s3Client, serviceInfo.getBucket(), urlWithoutCredentials);
    } catch (MalformedURLException e) {
        log.error("create(): Couldnt parse the URL provided by VCAP_SERVICES. Exception = " + e.getMessage());
        throw new RuntimeException("Blobstore URL is Invalid", e);
    }
}

From source file:org.sonatype.nexus.testsuite.NexusHttpsITSupport.java

/**
 * @return CookieOrigin suitable for validating session cookies from the given base URL
 *//* w w  w.j a  v a2 s . c  om*/
protected CookieOrigin cookieOrigin(final URL url) {
    return new CookieOrigin(url.getHost(), url.getPort(), cookiePath(url), url.getProtocol().equals("https"));
}

From source file:top.lionxxw.zuulservice.filter.BookingCarRoutingFilter.java

/**
 * This method allows to set the route host into the Zuul request context provided as parameter.
 * The url is extracted from the orginal request and the host is extracted from it.
 *
 * @param ctx Zuul/* ww w.j av a  2s.  c  o  m*/
 *
 * @throws MalformedURLException
 */
private void setRouteHost(RequestContext ctx) throws MalformedURLException {

    String urlS = ctx.getRequest().getRequestURL().toString();
    URL url = new URL(urlS);
    String protocol = url.getProtocol();
    String rootHost = url.getHost();
    int port = url.getPort();
    String portS = (port > 0 ? ":" + port : "");
    ctx.setRouteHost(new URL(protocol + "://" + rootHost + portS));

}