Example usage for org.apache.http.client.utils URIBuilder setPort

List of usage examples for org.apache.http.client.utils URIBuilder setPort

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder setPort.

Prototype

public URIBuilder setPort(final int port) 

Source Link

Document

Sets URI port.

Usage

From source file:integration.IntegrationTestsConfig.java

public static URI getGlServerURL() throws MalformedURLException, URISyntaxException {
    URIBuilder result = new URIBuilder(GL_BASE_URI);
    if (GL_PORT != null) {
        result.setPort(Integer.parseInt(GL_PORT));
    }/*from w ww .  ja  va2  s.  com*/

    final String username;
    final String password;
    if (result.getUserInfo() == null) {
        username = GL_ADMIN_USER;
        password = GL_ADMIN_PASSWORD;
    } else {
        final String[] userInfo = result.getUserInfo().split(":");
        username = (GL_ADMIN_USER != null ? GL_ADMIN_USER : userInfo[0]);
        password = (GL_ADMIN_PASSWORD != null ? GL_ADMIN_PASSWORD : userInfo[1]);
    }

    result.setUserInfo(firstNonNull(username, "admin"), firstNonNull(password, "admin"));

    return result.build();
}

From source file:de.shadowhunt.subversion.internal.URIUtils.java

private static URI createURI0(final URI repository, final Resource... resources) throws URISyntaxException {
    final URIBuilder builder = new URIBuilder();
    builder.setScheme(repository.getScheme());
    builder.setHost(repository.getHost());
    builder.setPort(repository.getPort());
    final StringBuilder completePath = new StringBuilder(repository.getPath());
    for (final Resource resource : resources) {
        completePath.append(resource.getValue());
    }//from ww  w .j  av a2s .  c  o  m
    builder.setPath(completePath.toString());
    return builder.build();
}

From source file:com.jkoolcloud.tnt4j.streams.fields.ActivityCacheTest.java

private static URI makeURI() {
    try {//from  w  w w .j  av a  2  s  .  c o  m
        URIBuilder uriBuilder = new URIBuilder("http://localhost"); // NON-NLS
        uriBuilder.setHost("localhost"); // NON-NLS
        uriBuilder.setPort(TEST_PORT);
        URI url = uriBuilder.build();
        return url;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.redhat.refarch.microservices.trigger.service.TriggerService.java

private static URIBuilder getUriBuilder(Object... path) {

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("gateway-service");
    uriBuilder.setPort(9091);

    StringWriter stringWriter = new StringWriter();
    for (Object part : path) {
        stringWriter.append('/').append(String.valueOf(part));
    }//from  ww  w  . java  2  s  .c o m
    uriBuilder.setPath(stringWriter.toString());
    return uriBuilder;
}

From source file:alluxio.cli.LogLevel.java

private static void setLogLevel(final TargetInfo targetInfo, String logName, String level) throws IOException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost(targetInfo.getHost());
    uriBuilder.setPort(targetInfo.getPort());
    uriBuilder.setPath(Constants.REST_API_PREFIX + "/" + targetInfo.getRole() + "/" + LOG_LEVEL);
    uriBuilder.addParameter(LOG_NAME_OPTION_NAME, logName);
    if (level != null) {
        uriBuilder.addParameter(LEVEL_OPTION_NAME, level);
    }/*from  w  ww. j  a v a2  s. c o  m*/
    HttpUtils.post(uriBuilder.toString(), 5000, new HttpUtils.IProcessInputStream() {
        @Override
        public void process(InputStream inputStream) throws IOException {
            ObjectMapper mapper = new ObjectMapper();
            LogInfo logInfo = mapper.readValue(inputStream, LogInfo.class);
            System.out.println(targetInfo.toString() + logInfo.toString());
        }
    });
}

From source file:org.ireas.mediawiki.MediaWikiUtils.java

/**
 * Constructs an {@code URI} object from {@code scheme}, {@code host},
 * {@code port} and {@code apiPath}. The constructed URI will have the
 * structure {@code "<scheme>://<host>:<port>/<apiPath>"}.
 *
 * @param scheme//from  ww w. ja  v  a2  s  . com
 *            the scheme of the URI, e. g. {@code "https"}
 * @param host
 *            the host of the URI, e. g. {@code "example.org"}
 * @param port
 *            the port of the URI, e. g. {@code 443}. The port must be
 *            non-negative.
 * @param path
 *            the path of the URI, e. g. {@code "/index.html"}
 * @return an {@code URI} constructed from the given parts
 * @throws MediaWikiException
 *             if the given parts do not form a valid URI
 * @throws NullPointerException
 *             if {@code scheme}, {@code host} or {@code path} is
 *             {@code null}
 * @throws IllegalArgumentException
 *             if {@code port} is negative
 */
public static URI buildUri(final String scheme, final String host, final int port, final String path)
        throws MediaWikiException {
    Preconditions.checkNotNull(scheme);
    Preconditions.checkNotNull(host);
    Preconditions.checkNotNull(path);
    Preconditions.checkArgument(port >= 0);

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(scheme);
    uriBuilder.setHost(host);
    uriBuilder.setPort(port);
    uriBuilder.setPath(path);
    try {
        return uriBuilder.build();
    } catch (URISyntaxException exception) {
        throw new MediaWikiException(exception);
    }
}

From source file:com.github.autermann.wps.streaming.ProcessConfiguration.java

private static URI createSocketURI() {
    try {//ww w.  j a va  2  s .  c  o m
        String wpsEndpoint = CapabilitiesConfiguration.ENDPOINT_URL;
        URIBuilder builder = new URIBuilder(wpsEndpoint);
        switch (builder.getScheme()) {
        case HTTP_SCHEME:
            builder.setScheme(WS_SCHEME);
            if (builder.getPort() == DEFAULT_HTTP_PORT) {
                builder.setPort(INVALID_PORT);
            }
            break;
        case HTTPS_SCHEME:
            builder.setScheme(WSS_SCHEME);
            if (builder.getPort() == DEFAULT_HTTPS_PORT) {
                builder.setPort(INVALID_PORT);
            }
            break;
        }
        String webappPath = normalizePath(WebProcessingService.WEBAPP_PATH);
        String servletPath = normalizePath(StreamingSocketEndpoint.PATH);
        if (webappPath != null) {
            builder.setPath(webappPath + servletPath);
        } else {
            builder.setPath(servletPath);
        }
        return builder.build();
    } catch (URISyntaxException ex) {
        return URI.create("ws://localhost:8080/streaming");
    }
}

From source file:org.apache.ambari.server.controller.metrics.timeline.AMSPropertyProvider.java

static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(httpsEnabled ? "https" : "http");
    uriBuilder.setHost(hostname);/* w w w. java  2 s  .co m*/
    uriBuilder.setPort(port);
    uriBuilder.setPath("/ws/v1/timeline/metrics");
    return uriBuilder;
}

From source file:com.vmware.identity.rest.core.client.SimpleHostRetriever.java

@Override
public URIBuilder getURIBuilder() {
    URIBuilder builder = new URIBuilder().setScheme(getScheme()).setHost(host);

    if (hasPort()) {
        builder.setPort(port);
    }//from   w  w w  .  j  a  v a2s.co  m

    return builder;
}

From source file:com.thoughtworks.go.agent.common.AgentBootstrapperBackwardCompatibility.java

public String sslServerUrl(String sslPort) {
    String serverUrl = serverUrl();

    try {/*from  w w  w .j a v a  2 s  . c om*/
        // backward compatibility, since the agent.jar requires an ssl url, but the old bootstrapper does not have one.
        URIBuilder url = new URIBuilder(serverUrl);
        if (url.getScheme().equals("http")) {
            url.setPort(Integer.valueOf(sslPort));
            url.setScheme("https");
        }
        return url.toString();
    } catch (URISyntaxException e) {
        throw bomb(e);
    }

}