Example usage for java.net URI getPort

List of usage examples for java.net URI getPort

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Returns the port number of this URI.

Usage

From source file:fr.ippon.wip.http.hc.HttpClientDecorator.java

HttpHost getHttpHost(HttpUriRequest request) {
    URI uri = request.getURI();
    return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
}

From source file:com.nesscomputing.httpserver.SoloJetty8HttpServer.java

@Inject
SoloJetty8HttpServer(final SoloHttpServerConfig soloHttpServerConfig, final HttpServerConfig httpServerConfig,
        @Named(CATCHALL_NAME) final Servlet catchallServlet) {
    super(httpServerConfig, catchallServlet);

    final ImmutableMap.Builder<String, HttpConnector> builder = ImmutableMap.builder();

    final URI[] serviceUris = soloHttpServerConfig.getServiceUris();

    Preconditions.checkState(ArrayUtils.isNotEmpty(serviceUris), "at least one valid URI must be given!");

    int count = 0;
    for (URI serviceUri : serviceUris) {

        final String scheme = serviceUri.getScheme();
        final boolean secure = "https".equals(scheme);
        int port = serviceUri.getPort();
        if (port == 0) {
            port = secure ? 443 : 80;/*w  ww  .j  a  v  a  2  s . co m*/
        }
        builder.put(count == 0 ? "service" : String.format("service-%d", count),
                new HttpConnector(secure, scheme, serviceUri.getHost(), port));
        count++;
    }

    connectors = builder.build();
}

From source file:org.restheart.test.performance.AbstractPT.java

public void prepare() {
    Authenticator.setDefault(new Authenticator() {
        @Override//w w w  . ja  v a 2 s.  c  o m
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(id, pwd.toCharArray());
        }
    });

    Configuration conf;

    StringBuilder ymlSB = new StringBuilder();

    if (mongoUri != null) {
        ymlSB.append(Configuration.MONGO_URI_KEY).append(": ").append(mongoUri).append("\n");
    }

    Yaml yaml = new Yaml();

    Map<String, Object> configuration = (Map<String, Object>) yaml.load(ymlSB.toString());

    try {
        MongoDBClientSingleton.init(new Configuration(configuration, true));
    } catch (ConfigurationException ex) {
        System.out.println(ex.getMessage() + ", exiting...");
        System.exit(-1);
    }

    httpExecutor = Executor.newInstance();

    // for perf test better to disable the restheart security
    if (url != null && id != null && pwd != null) {
        String host = "127.0.0.1";
        int port = 8080;
        String scheme = "http";

        try {
            URI uri = new URI(url);

            host = uri.getHost();
            port = uri.getPort();
            scheme = uri.getScheme();
        } catch (URISyntaxException ex) {
            Logger.getLogger(LoadPutPT.class.getName()).log(Level.SEVERE, null, ex);
        }

        httpExecutor.authPreemptive(new HttpHost(host, port, scheme)).auth(new HttpHost(host), id, pwd);
    }
}

From source file:org.jnode.jersey.JNContainer.java

private String getServerAddress(final URI baseUri) throws URISyntaxException {
    return new URI(baseUri.getScheme(), null, baseUri.getHost(), baseUri.getPort(), null, null, null)
            .toString();// w  w w  . j a v a 2 s .  com
}

From source file:edu.harvard.iq.dvn.api.datadeposit.UrlManager.java

String getHostnamePlusBaseUrlPath(String url) throws SwordError {
    String optionalPort = "";
    URI u;
    try {// ww  w.  ja  v a  2 s. co m
        u = new URI(url);
        int port = u.getPort();
        if (port != -1) {
            // https often runs on port 8181 in dev
            optionalPort = ":" + port;
        }
    } catch (URISyntaxException ex) {
        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "unable to part URL");
    }
    String hostName = System.getProperty("dvn.inetAddress");
    return "https://" + hostName + optionalPort + swordConfiguration.getBaseUrlPath();
}

From source file:org.mycontroller.standalone.restclient.RestFactory.java

public T createAPI(URI uri, String userName, String password) {
    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
            new UsernamePasswordCredentials(userName, password));
    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);
    // Add AuthCache to the execution context
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    context.setAuthCache(authCache);//  ww  w.j  ava2  s . c  o  m
    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, context);

    ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
    client.register(JacksonJaxbJsonProvider.class);
    client.register(RequestLogger.class);
    client.register(ResponseLogger.class);
    ProxyBuilder<T> proxyBuilder = client.target(uri).proxyBuilder(proxyClazz);
    return proxyBuilder.build();
}

From source file:com.alibaba.napoli.metamorphosis.cluster.Broker.java

/**
 * @param id// w ww .  j  a  v  a2 s.  c  om
 * @param data
 *            , meta://host:port or meta://host:port?slaveId=xx
 * 
 * */
public Broker(final int id, final String data) {
    this.id = id;
    try {
        final URI uri = new URI(data);
        this.host = uri.getHost();
        this.port = uri.getPort();
        this.slaveId = slaveIdByUri(uri);
    } catch (final URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.nesscomputing.cache.CacheTopologyProvider.java

@Inject
CacheTopologyProvider(final CacheConfiguration config, final ReadOnlyDiscoveryClient discoveryClient,
        @Named("cacheName") String cacheName) {
    this.discoveryClient = discoveryClient;
    this.cacheName = cacheName;

    List<URI> uris = config.getCacheUri();
    if (uris != null) {
        ImmutableList.Builder<InetSocketAddress> addrBuilder = ImmutableList.builder();
        for (URI uri : uris) {
            if ("memcache".equals(uri.getScheme())) {
                addrBuilder.add(new InetSocketAddress(uri.getHost(), uri.getPort()));
            } else {
                LOG.warn("Ignored uri %s due to wrong scheme", uri);
            }//from www . j  a v  a  2s  .c om
        }
        addrs = addrBuilder.build();
        LOG.info("Using configured caches: %s", addrs);
    } else {
        addrs = null;
        LOG.info("Using dynamically discovered caches.");
    }
}

From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurer.java

protected HttpClientConfigurer(URI targetHost) {
    httpClientBuilder = HttpClientBuilder.create();
    this.targetHost = new HttpHost(targetHost.getHost(), targetHost.getPort(), targetHost.getScheme());
}

From source file:f1db.configuration.ProductionProfile.java

@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));
    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);//from   w  w  w .  jav a  2s  .c om
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    return basicDataSource;
}