List of usage examples for java.net URI getHost
public String getHost()
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 w w. java 2s . co 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.smartitengineering.cms.ws.resources.workspace.WorkspaceFriendliesResource.java
protected WorkspaceResource getWorkspaceResource(final String uri) throws IllegalArgumentException, ContainerException, ClassCastException, UriBuilderException { final URI checkUri; if (uri.startsWith("http:")) { checkUri = URI.create(uri); } else {/*from w w w . j a va2 s . c o m*/ URI absUri = getAbsoluteURIBuilder().build(); checkUri = UriBuilder.fromPath(uri).host(absUri.getHost()).port(absUri.getPort()) .scheme(absUri.getScheme()).build(); } WorkspaceResource resource = getResourceContext().matchResource(checkUri, WorkspaceResource.class); return resource; }
From source file:com.yahoo.gondola.container.LocalTestRoutingServer.java
public LocalTestRoutingServer(Gondola gondola, RoutingHelper routingHelper, ProxyClientProvider proxyClientProvider, Map<String, RoutingService> services, ChangeLogProcessor changeLogProcessor) throws Exception { routingFilter = new RoutingFilter(gondola, routingHelper, proxyClientProvider, services, changeLogProcessor);//from www . j ava2 s . com routingFilter.start(); localTestServer = new LocalTestServer((request, response, context) -> { try { URI requestUri = URI.create(request.getRequestLine().getUri()); URI baseUri = URI .create(requestUri.getScheme() + "://" + requestUri.getHost() + ":" + requestUri.getPort()); ContainerRequest containerRequest = new ContainerRequest(baseUri, requestUri, request.getRequestLine().getMethod(), null, new MapPropertiesDelegate()); routingFilter.filter(containerRequest); Response abortResponse = containerRequest.getAbortResponse(); Response jaxrsResponse; if (abortResponse != null) { jaxrsResponse = abortResponse; } else { jaxrsResponse = new OutboundJaxrsResponse.Builder(null).status(200).build(); } ContainerResponse containerResponse = new ContainerResponse(containerRequest, jaxrsResponse); routingFilter.filter(containerRequest, containerResponse); response.setStatusCode(containerResponse.getStatus()); response.setEntity(new StringEntity(containerResponse.getEntity().toString())); Set<Map.Entry<String, List<Object>>> entries = containerResponse.getHeaders().entrySet(); for (Map.Entry<String, List<Object>> e : entries) { String headerName = e.getKey(); for (Object o : e.getValue()) { String headerValue = o.toString(); response.setHeader(headerName, headerValue); } } } catch (Exception e) { e.printStackTrace(); throw e; } }); host = localTestServer.start(); }
From source file:com.seajas.search.attender.service.mail.MailService.java
/** * Switch the e-mail sender to the inputted mail server, if applicable. *//*from www. j av a 2 s .c o m*/ public void updateWorkingMailServer() { // Use the mail-server override if one has been entered and validated if (attenderService.validateCurrentMailServerDetails()) try { MailSettings settings = attenderService.getMailServerDetails(); URI hostnameURI = settings.getHostnameUri(); ((JavaMailSenderImpl) sender).setHost(hostnameURI.getHost()); Integer schemeStandardPort = "smtps".equals(hostnameURI.getScheme()) ? 465 : 25; ((JavaMailSenderImpl) sender) .setPort(hostnameURI.getPort() != -1 ? hostnameURI.getPort() : schemeStandardPort); if (!StringUtils.isEmpty(settings.getUsername())) ((JavaMailSenderImpl) sender).setUsername(settings.getUsername()); if (!StringUtils.isEmpty(settings.getPassword())) ((JavaMailSenderImpl) sender).setPassword(settings.getPassword()); ((JavaMailSenderImpl) sender).setProtocol(hostnameURI.getScheme()); if (StringUtils.isEmpty(settings.getUsername()) && StringUtils.isEmpty(settings.getPassword())) ((JavaMailSenderImpl) sender).getJavaMailProperties() .setProperty("mail." + hostnameURI.getScheme() + ".auth", "true"); fromAddress = settings.getSender(); } catch (URISyntaxException e) { logger.error("Could not set the given mail settings."); } }
From source file:io.seldon.api.interceptor.GenericScopedInterceptor.java
private String referrerDomain(String referrer) { Pattern topLevelDomain = Pattern.compile(".*?([^.]+\\.[^.]+)"); Pattern ipAddress = Pattern.compile("^\\d+\\.\\d+\\.\\d+\\.\\d+"); if (StringUtils.isBlank(referrer)) { return ""; }/* www . j a v a 2 s . c o m*/ try { final URI referrerUri = new URI(referrer); final String host = referrerUri.getHost(); if (StringUtils.isBlank(host)) { return ""; } final Matcher ipMatcher = ipAddress.matcher(host); if (ipMatcher.matches()) { return host; } final Matcher tldMatcher = topLevelDomain.matcher(host); if (tldMatcher.matches()) { return tldMatcher.group(1); } return host; } catch (URISyntaxException e) { return referrer; } }
From source file:at.bitfire.davdroid.mirakel.syncadapter.EnterCredentialsFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { boolean ok = editUserName.getText().length() > 0 && editPassword.getText().length() > 0; if (ok) {/* ww w . ja va2 s.c o m*/ // check host name try { URI uri = new URI(URIUtils.sanitize(protocol + editBaseURL.getText().toString())); if (StringUtils.isBlank(uri.getHost())) ok = false; } catch (URISyntaxException e) { ok = false; } } MenuItem item = menu.findItem(R.id.next); item.setEnabled(ok); }
From source file:de.dfki.asr.compass.business.PrefabImporter.java
private String retrieveHierachyAsJSON(final String assetURL) { //Clear fragment, just in case something is still in there URI url = UriBuilder.fromUri(assetURL).path(ATLAS_ASSET_REST_PATH).path(assetName).fragment("").build(); if (url.getHost() == null) { return ""; }//from w w w . j ava2 s . co m Client client = ClientBuilder.newClient(); WebTarget target = client.target(url); Response response = target.request().accept(MediaType.APPLICATION_JSON).get(); if (isErrorResponse(response)) { log.errorv("Error while trying to retrieve the asset hierarchy as json: {0} - {1}", response.getStatus(), response.readEntity(String.class)); return ""; } String json = response.readEntity(String.class); response.close(); return json; }
From source file:com.github.sardine.AuthenticationTest.java
@Test public void testDigestAuthWithBasicPreemptive() throws Exception { Sardine sardine = SardineFactory.begin(properties.getProperty("username"), properties.getProperty("password")); URI url = URI.create("http://sudo.ch/dav/digest/"); sardine.enablePreemptiveAuthentication(url.getHost()); try {/*from w w w . jav a 2 s .c o m*/ sardine.list(url.toString()); fail("Expected authentication to fail"); } catch (SardineException e) { // Preemptive basic authentication is expected to fail when no basic // method is returned in Authentication response header } }
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 w w w. ja v a2 s. c o m */ 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:org.apache.hadoop.gateway.dispatch.AppCookieManager.java
/** * Fetches hadoop.auth cookie from hadoop service authenticating using SpNego * /*from ww w . ja va 2 s. co m*/ * @param outboundRequest * out going request * @param refresh * flag indicating whether to refresh the cached cookie * @return hadoop.auth cookie from hadoop service authenticating using SpNego * @throws IOException * in case of errors */ public String getAppCookie(HttpUriRequest outboundRequest, boolean refresh) throws IOException { URI uri = outboundRequest.getURI(); String scheme = uri.getScheme(); String host = uri.getHost(); int port = uri.getPort(); if (!refresh) { if (appCookie != null) { return appCookie; } } DefaultHttpClient client = new DefaultHttpClient(); SPNegoSchemeFactory spNegoSF = new SPNegoSchemeFactory(/* stripPort */true); // spNegoSF.setSpengoGenerator(new BouncySpnegoTokenGenerator()); client.getAuthSchemes().register(AuthPolicy.SPNEGO, spNegoSF); client.getCredentialsProvider().setCredentials(new AuthScope(/* host */null, /* port */-1, /* realm */null), EMPTY_JAAS_CREDENTIALS); clearAppCookie(); String hadoopAuthCookie = null; HttpResponse httpResponse = null; try { HttpHost httpHost = new HttpHost(host, port, scheme); HttpRequest httpRequest = createKerberosAuthenticationRequest(outboundRequest); httpResponse = client.execute(httpHost, httpRequest); Header[] headers = httpResponse.getHeaders(SET_COOKIE); hadoopAuthCookie = getHadoopAuthCookieValue(headers); EntityUtils.consume(httpResponse.getEntity()); if (hadoopAuthCookie == null) { LOG.failedSPNegoAuthn(uri.toString()); auditor.audit(Action.AUTHENTICATION, uri.toString(), ResourceType.URI, ActionOutcome.FAILURE); throw new IOException("SPNego authn failed, can not get hadoop.auth cookie"); } } finally { if (httpResponse != null) { HttpEntity entity = httpResponse.getEntity(); if (entity != null) { entity.getContent().close(); } } } LOG.successfulSPNegoAuthn(uri.toString()); auditor.audit(Action.AUTHENTICATION, uri.toString(), ResourceType.URI, ActionOutcome.SUCCESS); hadoopAuthCookie = HADOOP_AUTH_EQ + quote(hadoopAuthCookie); setAppCookie(hadoopAuthCookie); return appCookie; }