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:org.robertburrelldonkin.template4couchdb.rest.HttpClientRestClientTest.java

@Test
public void testGetUrl() throws Exception {
    subject.get(URL, mapper);// w  ww. j  av  a2s.com
    ArgumentCaptor<HttpGet> argument = ArgumentCaptor.forClass(HttpGet.class);
    verify(client).execute(argument.capture(), eq(handler));
    URI uri = argument.getValue().getURI();
    assertThat(PORT, is(uri.getPort()));
    assertThat(HOST, is(uri.getHost()));
    assertThat(PROTOCOL, is(uri.getScheme()));
    assertThat(PATH, is(uri.getPath()));
}

From source file:org.robertburrelldonkin.template4couchdb.rest.HttpClientRestClientTest.java

@Test
public void testPostUrl() throws Exception {
    ArgumentCaptor<HttpPost> argument = ArgumentCaptor.forClass(HttpPost.class);
    this.subject.post(URL, documentMarshaller, document, responseUnmarshaller);
    verify(client).execute(argument.capture(), eq(handler));
    URI uri = argument.getValue().getURI();
    assertThat(PORT, is(uri.getPort()));
    assertThat(HOST, is(uri.getHost()));
    assertThat(PROTOCOL, is(uri.getScheme()));
    assertThat(PATH, is(uri.getPath()));
}

From source file:com.almende.eve.transport.xmpp.XmppTransport.java

/**
 * Instantiates a new xmpp transport./*from   w  ww.j  a v a2  s .c  o  m*/
 * 
 * @param config
 *            the config
 * @param handle
 *            the handle
 * @param service
 *            the service
 */
public XmppTransport(final XmppTransportConfig config, final Handler<Receiver> handle,
        final TransportService service) {
    // TODO: support more parameter structures.
    super(config.getAddress(), handle, service, config);

    final URI address = super.getAddress();
    host = address.getHost();
    port = address.getPort();
    if (port < 0) {
        port = 5222;
    }
    username = address.getUserInfo();
    resource = address.getPath().substring(1);
    if (serviceName == null) {
        serviceName = host;
    }
    password = config.getPassword();
}

From source file:com.zimbra.qa.unittest.TestCollectConfigServletsAccess.java

/**
 * Verify that delegated admin canNOT access servlet at /service/collectconfig/
 * @throws Exception//  w w w .j av  a2 s . c om
 */
@Test
public void testConfigDelegatedAdmin() throws Exception {
    ZAuthToken at = TestUtil.getAdminSoapTransport(TEST_ADMIN_NAME, PASSWORD).getAuthToken();
    URI servletURI = new URI(getConfigServletUrl());
    HttpState initialState = HttpClientUtil.newHttpState(at, servletURI.getHost(), true);
    HttpClient restClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    restClient.setState(initialState);
    restClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    GetMethod get = new GetMethod(servletURI.toString());
    int statusCode = HttpClientUtil.executeMethod(restClient, get);
    assertEquals("This request should NOT succeed. Getting status code " + statusCode,
            HttpStatus.SC_UNAUTHORIZED, statusCode);
}

From source file:com.ericsson.gerrit.plugins.syncindex.HttpClientProvider.java

private BasicCredentialsProvider buildCredentials() {
    URI uri = URI.create(cfg.getUrl());
    BasicCredentialsProvider creds = new BasicCredentialsProvider();
    creds.setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
            new UsernamePasswordCredentials(cfg.getUser(), cfg.getPassword()));
    return creds;
}

From source file:com.nirima.jenkins.SimpleArtifactCopier.java

private void init() throws URISyntaxException {
    URI targetURI = host.toURI();

    targetHost = new HttpHost(targetURI.getHost(), targetURI.getPort());

    params = new BasicHttpParams();
    params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
    params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024);

    httpexecutor = new HttpRequestExecutor();
    httpproc = new BasicHttpProcessor();
    // Required protocol interceptors
    httpproc.addInterceptor(new RequestContent());
    httpproc.addInterceptor(new RequestTargetHost());
    // Recommended protocol interceptors
    httpproc.addInterceptor(new RequestConnControl());
    httpproc.addInterceptor(new RequestUserAgent());
    httpproc.addInterceptor(new RequestExpectContinue());

    context = new BasicHttpContext();

    conn = new DefaultHttpClientConnection();

    connStrategy = new DefaultConnectionReuseStrategy();
}

From source file:com.shazam.fork.reporter.gradle.JenkinsDownloader.java

@Nonnull
private URL getArtifactUrl(Build build, Artifact artifact) {
    try {/*from  www. ja va2  s .  co m*/
        URI uri = new URI(build.getUrl());
        String artifactPath = uri.getPath() + "artifact/" + artifact.getRelativePath();
        URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
                artifactPath, "", "");
        return artifactUri.toURL();
    } catch (URISyntaxException | MalformedURLException e) {
        throw new GradleException("Error when trying to construct artifact URL for: " + build.getUrl(), e);
    }
}

From source file:fr.wseduc.webutils.email.SendInBlueSender.java

public SendInBlueSender(Vertx vertx, Container container, JsonObject config)
        throws InvalidConfigurationException, URISyntaxException {
    super(vertx, container);
    if (config != null && isNotEmpty(config.getString("uri")) && isNotEmpty(config.getString("api-key"))) {
        URI uri = new URI(config.getString("uri"));
        httpClient = vertx.createHttpClient().setHost(uri.getHost()).setPort(uri.getPort()).setMaxPoolSize(16)
                .setSSL("https".equals(uri.getScheme())).setKeepAlive(false);
        apiKey = config.getString("api-key");
        dedicatedIp = config.getString("ip");
        splitRecipients = config.getBoolean("split-recipients", false);
        mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    } else {/*from w  ww .j  a v a 2 s.c  om*/
        throw new InvalidConfigurationException("missing.parameters");
    }
}

From source file:com.amazon.s3.http.HttpRequestFactory.java

/** Configures the headers in the specified Apache HTTP request. */
private void configureHeaders(HttpRequestBase httpRequest, Request<?> request, ExecutionContext context,
        ClientConfiguration clientConfiguration) {
    /*/*from w ww .j  a va 2  s  .c  o  m*/
     * Apache HttpClient omits the port number in the Host header (even if
     * we explicitly specify it) if it's the default port for the protocol
     * in use. To ensure that we use the same Host header in the request and
     * in the calculated string to sign (even if Apache HttpClient changed
     * and started honoring our explicit host with endpoint), we follow this
     * same behavior here and in the QueryString signer.
     */
    URI endpoint = request.getEndpoint();
    String hostHeader = endpoint.getHost();
    if (HttpUtils.isUsingNonDefaultPort(endpoint)) {
        hostHeader += ":" + endpoint.getPort();
    }
    httpRequest.addHeader("Host", hostHeader);

    // Copy over any other headers already in our request
    for (Entry<String, String> entry : request.getHeaders().entrySet()) {
        /*
         * HttpClient4 fills in the Content-Length header and complains if
         * it's already present, so we skip it here. We also skip the Host
         * header to avoid sending it twice, which will interfere with some
         * signing schemes.
         */
        if (entry.getKey().equalsIgnoreCase("Content-Length") || entry.getKey().equalsIgnoreCase("Host"))
            continue;

        httpRequest.addHeader(entry.getKey(), entry.getValue());
    }

    /* Set content type and encoding */
    if (httpRequest.getHeaders("Content-Type") == null || httpRequest.getHeaders("Content-Type").length == 0) {
        httpRequest.addHeader("Content-Type",
                "application/x-www-form-urlencoded; " + "charset=" + DEFAULT_ENCODING.toLowerCase());
    }

    // Override the user agent string specified in the client params if the
    // context requires it
    if (context != null && context.getContextUserAgent() != null) {
        httpRequest.addHeader("User-Agent",
                createUserAgentString(clientConfiguration, context.getContextUserAgent()));
    }
}

From source file:org.datacleaner.user.MonitorConnection.java

/**
 * Determines if a {@link URI} matches the configured DC Monitor settings.
 * /*  ww  w  .j  a  va2 s.c o m*/
 * @param uri
 * @return
 */
public boolean matchesURI(URI uri) {
    if (uri == null) {
        return false;
    }
    final String host = uri.getHost();
    if (host.equals(_hostname)) {
        final int port = uri.getPort();
        if (port == _port || port == -1) {
            final String path = removeBeginningSlash(uri.getPath());
            if (StringUtils.isNullOrEmpty(_contextPath) || path.startsWith(_contextPath)) {
                return true;
            }
        }
    }
    return false;
}