Example usage for java.net URI getHost

List of usage examples for java.net URI getHost

Introduction

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

Prototype

public String getHost() 

Source Link

Document

Returns the host component of this URI.

Usage

From source file:com.jrodeo.remote.TestHttpCore.java

Stats execute(final URI target, final byte[] content, int n, int c) throws Exception {
    this.pool.setMaxTotal(2000);
    this.pool.setDefaultMaxPerRoute(c);
    HttpHost targetHost = new HttpHost(target.getHost(), target.getPort());
    StringBuilder buffer = new StringBuilder();
    buffer.append(target.getPath());/*from  w  ww. java2s  .c  o m*/
    if (target.getQuery() != null) {
        buffer.append("?");
        buffer.append(target.getQuery());
    }
    String requestUri = buffer.toString();

    Stats stats = new Stats(n, c);
    WorkerThread[] workers = new WorkerThread[c];
    for (int i = 0; i < workers.length; i++) {
        workers[i] = new WorkerThread(stats, targetHost, requestUri, content);
    }
    for (int i = 0; i < workers.length; i++) {
        workers[i].start();
    }
    for (int i = 0; i < workers.length; i++) {
        workers[i].join();
    }
    return stats;
}

From source file:com.sap.core.odata.fit.basic.issues.TestIssue105.java

@Test
public void checkContextForDifferentHostNamesRequests()
        throws ClientProtocolException, IOException, ODataException, URISyntaxException {
    URI uri1 = URI.create(getEndpoint().toString() + "$metadata");

    HttpGet get1 = new HttpGet(uri1);
    HttpResponse response1 = getHttpClient().execute(get1);
    assertNotNull(response1);//  w  w  w  . jav  a2s  . com

    URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
    assertEquals(uri1.getHost(), serviceRoot1.getHost());

    get1.reset();

    URI uri2 = new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(),
            uri1.getQuery(), uri1.getFragment());

    HttpGet get2 = new HttpGet(uri2);
    HttpResponse response2 = getHttpClient().execute(get2);
    assertNotNull(response2);

    URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
    assertEquals(uri2.getHost(), serviceRoot2.getHost());
}

From source file:kuona.client.JenkinsHttpClient.java

/**
 * Create an authenticated Jenkins HTTP client
 *
 * @param uri      Location of the jenkins server (ex. http://localhost:8080)
 * @param username Username to use when connecting
 * @param password Password or auth token to use when connecting
 *//*from www.jav  a2 s  . c o m*/
public JenkinsHttpClient(Project project, URI uri, String username, String password) {
    this(project, uri);
    if (isNotBlank(username)) {
        CredentialsProvider provider = client.getCredentialsProvider();
        AuthScope scope = new AuthScope(uri.getHost(), uri.getPort(), "realm");
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
        provider.setCredentials(scope, credentials);

        localContext = new BasicHttpContext();
        localContext.setAttribute("preemptive-auth", new BasicScheme());
        client.addRequestInterceptor(new PreemptiveAuth(), 0);
    }
}

From source file:com.whizzosoftware.hobson.wemo.WeMoPlugin.java

protected String minifyURI(URI uri) {
    if ("http".equals(uri.getScheme()) && uri.getPath().endsWith("setup.xml")) {
        if (uri.getPort() == 49153) {
            return uri.getHost();
        } else {/*from   ww  w . jav  a  2s  .co m*/
            return uri.getHost() + ":" + uri.getPort();
        }
    } else {
        return uri.toASCIIString();
    }
}

From source file:com.sina.cloudstorage.util.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.schemeSpecificPart = uri.getSchemeSpecificPart();
    this.authority = uri.getAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.userInfo = uri.getUserInfo();
    this.path = uri.getPath();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.fragment = uri.getFragment();
}

From source file:chat.viska.xmpp.Connection.java

/**
 * Constructs a {@link Connection} with a full server URI. Convenient method
 * of {@link #Connection(Protocol, String, String, int, String)}.
 *//*w w  w  . j  a  v a 2s  .  co m*/
public Connection(final Protocol protocol, final URI uri) {
    this(protocol, uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath());
}

From source file:net.bluemix.connectors.core.info.IBMObjectStorageServiceInfo.java

public IBMObjectStorageServiceInfo(final String id, final String url) throws URISyntaxException {
    super(id);//from www. ja v a2 s .c  om
    final String modUrl = url.replaceFirst(IBMObjectStorageServiceInfo.SCHEME, "https");
    final URI uri = new URI(modUrl);
    this.authUrl = uri.getScheme() + "://" + uri.getHost();
    if (uri.getPort() > 0) {
        this.authUrl = authUrl + ":" + uri.getPort();
    }
    if (uri.getUserInfo() != null) {
        final String[] credentials = uri.getUserInfo().split(":");
        this.userId = credentials[0];
        this.password = credentials[1];
    }
    if (uri.getPath() != null) {
        //the path includes the '/' after the host
        final String[] path = uri.getPath().split("/");
        if (path.length == 3) {
            this.project = path[1];
            this.domainName = path[2];
        }
    }

}

From source file:com.whizzosoftware.hobson.rest.v1.resource.device.MediaProxyResource.java

protected HttpProps createHttpGet(String varValue) throws ParseException, URISyntaxException {
    URIInfo uriInfo = URLVariableParser.parse(varValue);
    HttpGet get = new HttpGet(uriInfo.getURI());

    // populate the GET request with headers if specified
    if (uriInfo.hasHeaders()) {
        Map<String, String> headers = uriInfo.getHeaders();
        for (String name : headers.keySet()) {
            uriInfo.addHeader(name, headers.get(name));
        }/*from  w  ww. j  a va2s . c o m*/
    }

    CloseableHttpClient httpClient;

    // populate the GET request with auth information if specified
    if (uriInfo.hasAuthInfo()) {
        URI uri = uriInfo.getURI();
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope(uri.getHost(), (uri.getPort() > 0) ? uri.getPort() : DEFAULT_REALM_PORT),
                new UsernamePasswordCredentials(uriInfo.getAuthInfo().getUsername(),
                        uriInfo.getAuthInfo().getPassword()));
        httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    } else {
        httpClient = HttpClients.createDefault();
    }

    return new HttpProps(httpClient, get);
}

From source file:fi.csc.emrex.smp.ThymeController.java

private String generatePersonalLogLine(HttpServletRequest httpRequest, Person person, String source)
        throws Exception {
    String personalLogLine = source + "\t" + person.getFullName();
    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDateTime startTime = (LocalDateTime) context.getSession().getAttribute("sessionStartTime");
    if (startTime == null) {
        startTime = LocalDateTime.now();
    }//from  w  ww  .j  av  a  2  s  . c  o  m
    personalLogLine += "\t" + startTime.format(dateFormatter);

    String url = httpRequest.getHeader("Referer");
    String NCPDomain = "";
    if (url != null) {
        URI uri = new URI(url);
        NCPDomain = uri.getHost();
    }

    personalLogLine += "\t" + NCPDomain;
    personalLogLine += "\t" + httpRequest.getParameter("returnCode");
    return personalLogLine;
}

From source file:net.paoding.spdy.server.tomcat.impl.RequestDecoder.java

private Request decode(SynStream synStream) throws URISyntaxException {
    Request request = new Request();
    request.setStartTime(synStream.getTimestamp());
    CoyoteAttributes.setSynStream(request, synStream);
    ///*from  ww  w .ja  v a 2s. c om*/
    String method = synStream.getHeader("method");
    String url = synStream.getHeader("url");
    String version = synStream.getHeader("version");
    if (method == null && url == null && version == null) {
        throw new IllegalArgumentException("method=" + method + "; url=" + url + "; version=" + version);
    }
    request.method().setString(method);
    URI uri = new URI(url);
    request.protocol().setString(uri.getScheme());
    request.requestURI().setString(uri.getPath());
    request.query().setString(uri.getQuery());
    request.serverName().setString(uri.getHost());
    int port = uri.getPort();
    request.setServerPort(port > 0 ? port : 80);
    // copy headers
    MimeHeaders coyoteHeaders = request.getMimeHeaders();
    Map<String, String> headers = synStream.getHeaders();
    for (Map.Entry<String, String> header : headers.entrySet()) {
        MessageBytes val = coyoteHeaders.addValue(header.getKey());
        val.setString(header.getValue());
    }
    // body
    request.setInputBuffer(new SpdyInputBuffer(synStream));
    //        System.out.println("RequestDecoder.decode: returnrequest " + request.decodedURI());
    return request;
}