List of usage examples for java.net URI getPort
public int getPort()
From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestDescriptor.java
public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters) throws UnsupportedEncodingException, URISyntaxException { super();/*from www . j ava 2 s . c o m*/ this.uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); this.method = method; final String query = uri.getQuery(); if (query != null) { parameters.addAll(URLEncodedUtils.parse(uri, "UTF-8")); } this.parameters = parameters; }
From source file:org.zlogic.vogon.web.PersistenceConfiguration.java
/** * Returns the JPA configuration overrides for database configuration * * @return the map of JPA configuration variables to override for the * database connection/*from ww w . ja v a2s .com*/ */ protected Map<String, Object> getDatabaseConfiguration() { Map<String, Object> jpaProperties = new HashMap<>(); boolean fallback = true; if (serverTypeDetector.getServerType() != ServerTypeDetector.ServerType.WILDFLY) jpaProperties.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider"); //NOI18N if (serverTypeDetector.getDatabaseType() == ServerTypeDetector.DatabaseType.POSTGRESQL) { String dbURL = null; if (serverTypeDetector.getCloudType() == ServerTypeDetector.CloudType.HEROKU) dbURL = System.getenv("DATABASE_URL"); //NOI18N else if (serverTypeDetector.getCloudType() == ServerTypeDetector.CloudType.OPENSHIFT) dbURL = System.getenv("OPENSHIFT_POSTGRESQL_DB_URL") + "/" + System.getenv("OPENSHIFT_APP_NAME"); //NOI18N try { URI dbUri = new URI(dbURL); String dbConnectionURL = "jdbc:postgresql://" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath(); //NOI18N //NOI18N String[] usernamePassword = dbUri.getUserInfo().split(":", 2); //NOI18N jpaProperties.put("javax.persistence.jdbc.url", dbConnectionURL); //NOI18N jpaProperties.put("javax.persistence.jdbc.user", usernamePassword[0]); //NOI18N jpaProperties.put("javax.persistence.jdbc.password", usernamePassword[1]); //NOI18N jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); //NOI18N jpaProperties.put("hibernate.connection.driver_class", "org.postgresql.Driver"); //NOI18N fallback = false; } catch (Exception ex) { log.error(messages.getString("ERROR_EXTRACTING_DATABASE_CONFIGURATION"), ex); } } if (serverTypeDetector.getDatabaseType() == ServerTypeDetector.DatabaseType.H2 || fallback) { String dbConnectionURL = MessageFormat.format("jdbc:h2:{0}/Vogon", new Object[] { getH2DatabasePath() }); //NOI18N jpaProperties.put("javax.persistence.jdbc.url", dbConnectionURL); //NOI18N jpaProperties.put("javax.persistence.jdbc.user", ""); //NOI18N jpaProperties.put("javax.persistence.jdbc.password", ""); //NOI18N jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); //NOI18N jpaProperties.put("hibernate.connection.driver_class", "org.h2.Driver"); //NOI18N } return jpaProperties; }
From source file:com.sap.core.odata.testutil.tool.core.AbstractTestClient.java
private DefaultHttpClient createHttpClient(final CallerConfig config) { DefaultHttpClient httpClient = new DefaultHttpClient(); if (config.isProxySet()) { initProxy(httpClient, config);//from w w w.ja v a 2 s . co m } if (config.isBasicAuthCredentialsSet()) { final URI baseUri = config.getBaseUri(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(baseUri.getHost(), baseUri.getPort()), new UsernamePasswordCredentials(config.getBasicAuthCredentials())); } return httpClient; }
From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java
private URI base(final URI uri) { try {/*from w w w.j a va 2s . c o m*/ URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(uri.getScheme()); uriBuilder.setHost(uri.getHost()); uriBuilder.setPort(uri.getPort()); uriBuilder.setPath(uri.getPath()); if (uri.getUserInfo() != null) { uriBuilder.setUserInfo(uri.getUserInfo()); } return uriBuilder.build(); } catch (final URISyntaxException ignored) { // This should never happen since we are using a valid URI to construct ours. return null; } }
From source file:ch.cyberduck.core.proxy.SystemConfigurationProxy.java
@Override public Proxy find(final Host target) { if (!preferences.getBoolean("connection.proxy.enable")) { return Proxy.DIRECT; }// w ww. j a va 2 s.c o m final String route = this.findNative(provider.get(target)); if (null == route) { if (log.isInfoEnabled()) { log.info(String.format("No poxy configuration found for target %s", target)); } // Direct return Proxy.DIRECT; } final URI proxy; try { proxy = new URI(route); try { return new Proxy(Proxy.Type.valueOf(StringUtils.upperCase(proxy.getScheme())), proxy.getHost(), proxy.getPort()); } catch (IllegalArgumentException e) { log.warn(String.format("Unsupported scheme for proxy %s", proxy)); } } catch (URISyntaxException e) { log.warn(String.format("Invalid proxy configuration %s", route)); } return Proxy.DIRECT; }
From source file:com.thinkbiganalytics.nifi.security.ApplySecurityPolicy.java
protected void checkHdfsUriForTimeout(Configuration config) throws IOException { URI hdfsUri = FileSystem.getDefaultUri(config); String address = hdfsUri.getAuthority(); int port = hdfsUri.getPort(); if (address == null || address.isEmpty() || port < 0) { return;//from w w w . j a v a 2 s.c o m } InetSocketAddress namenode = NetUtils.createSocketAddr(address, port); SocketFactory socketFactory = NetUtils.getDefaultSocketFactory(config); Socket socket = null; try { socket = socketFactory.createSocket(); NetUtils.connect(socket, namenode, 1000); // 1 second timeout } finally { IOUtils.closeQuietly(socket); } }
From source file:com.sap.core.odata.testutil.tool.core.SupaController.java
private void init() { httpClient = new DefaultHttpClient(); if (config.isProxySet()) { initProxy();/*from w w w. ja va2 s. c o m*/ } if (config.isBasicAuthCredentialsSet()) { final URI baseUri = config.getBaseUri(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(baseUri.getHost(), baseUri.getPort()), new UsernamePasswordCredentials(config.getBasicAuthCredentials())); } }
From source file:com.nebhale.cyclinglibrary.repository.RepositoryConfiguration.java
@Bean DataSource dataSource() throws URISyntaxException { String dbUrlProperty = System.getenv(DB_URL_PROPERTY_NAME); Assert.hasText(dbUrlProperty,//from w ww . j a v a 2s.c o m String.format("The enviroment variable '%s' must be specified", DB_URL_PROPERTY_NAME)); URI dbUri = new URI(dbUrlProperty); String username = dbUri.getUserInfo().split(":")[0]; String password = dbUri.getUserInfo().split(":")[1]; String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath() + "?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"; BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(Driver.class.getCanonicalName()); dataSource.setJdbcUrl(dbUrl); dataSource.setUsername(username); dataSource.setPassword(password); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.migrate(); return dataSource; }
From source file:com.rinxor.cloud.cloudstack.api.CloudstackClient.java
public CloudstackResponse executeConsoleGetRedirect(CloudstackRequest cloudstackRequest) { CloudstackResponse cloudstackResponse = new CloudstackResponse(); try {//w ww.j a v a2 s . co m HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet( CloudstackAPI.buildApiRequestURL(cfg.getConsoleUrl(), cloudstackRequest.getUrlCommand())); getRequest.addHeader("Cookie", cloudstackRequest.getCookie()); getRequest.addHeader("Referer", cloudstackRequest.getReferer()); URI u = new URI(cfg.getConsoleUrl()); getRequest.addHeader("Host", u.getHost() + ":" + u.getPort()); HttpResponse response = httpClient.execute(getRequest); String responseString = new BasicResponseHandler().handleResponse(response); cloudstackResponse.setStatusCode(response.getStatusLine().getStatusCode()); cloudstackResponse.setResponseBody(responseString); } catch (ClientProtocolException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } return cloudstackResponse; }
From source file:com.rinxor.cloud.cloudstack.api.CloudstackClient.java
public CloudstackResponse executeApiGetRedirect(CloudstackRequest cloudstackRequest) { CloudstackResponse cloudstackResponse = new CloudstackResponse(); try {//from w w w .ja va 2 s. c o m HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet( CloudstackAPI.buildApiRequestURL(cfg.getApiUrl(), cloudstackRequest.getUrlCommand())); // login do not require Cookie but we send. getRequest.addHeader("Cookie", cloudstackRequest.getCookie()); getRequest.addHeader("Referer", cloudstackRequest.getReferer()); URI u = new URI(cfg.getApiUrl()); getRequest.addHeader("Host", u.getHost() + ":" + u.getPort()); HttpResponse response = httpClient.execute(getRequest); cloudstackResponse.setStatusCode(response.getStatusLine().getStatusCode()); cloudstackResponse.setResponseBody(EntityUtils.toString(response.getEntity())); // login response we must send cookie back to client if (response.getFirstHeader("Set-Cookie") != null) { cloudstackResponse.setSetCookie(response.getFirstHeader("Set-Cookie").getValue()); } } catch (ClientProtocolException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } return cloudstackResponse; }