List of usage examples for java.net URI getHost
public String getHost()
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient4Connector.java
/** * Get the {@link AuthScope} for the {@link #server} * // w ww . ja v a 2 s . c o m * @return the {@link AuthScope} */ private AuthScope getAuthScope() { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; try { final URI hostUri = new URI(server.getHost()); host = hostUri.getHost(); if (hostUri.getPort() > -1) { port = hostUri.getPort(); } else if ("http".equalsIgnoreCase(hostUri.getScheme())) { port = 80; } else if ("https".equalsIgnoreCase(hostUri.getScheme())) { port = 443; } } catch (URISyntaxException e) { // Failed to parse the server host URI // Fall-back on preset defaults log.error("Failed to parse the Server host url to an URI", e); } return new AuthScope(host, port, "realm"); }
From source file:com.rinxor.cloud.cloudstack.api.CloudstackClient.java
public CloudstackResponse executeApiChangeJsonPostToGetRedirect(CloudstackRequest cloudstackRequest) { CloudstackResponse cloudstackResponse = new CloudstackResponse(); try {/* w w w. jav a 2 s .c o m*/ JSONObject obj = new JSONObject(cloudstackRequest.getUrlCommand()); String urlCommand = "response=json&"; Iterator itr = obj.keys(); while (itr.hasNext()) { Object element = itr.next(); String key = (String) element; urlCommand += key + "=" + (String) obj.get(key) + "&"; } System.out.println("request: " + urlCommand); HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet(CloudstackAPI.buildApiRequestURL(cfg.getApiUrl(), urlCommand)); 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())); if (response.getFirstHeader("Set-Cookie") != null) { cloudstackResponse.setSetCookie(response.getFirstHeader("Set-Cookie").getValue()); } } catch (JSONException 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 (URISyntaxException ex) { Logger.getLogger(CloudstackClient.class.getName()).log(Level.SEVERE, null, ex); } return cloudstackResponse; }
From source file:com.cognifide.actions.msg.push.active.PushClientRunnable.java
public PushClientRunnable(Set<PushReceiver> receivers, String serverUrl, String username, String password) throws URISyntaxException { this.receivers = receivers; this.serverUrl = serverUrl; final HttpConnectionManager connManager = new MultiThreadedHttpConnectionManager(); client = new HttpClient(connManager); client.getParams().setAuthenticationPreemptive(true); final Credentials defaultcreds = new UsernamePasswordCredentials(username, password); final URI serverUri = new URI(serverUrl); final int port = serverUri.getPort() == -1 ? 80 : serverUri.getPort(); client.getState().setCredentials(new AuthScope(serverUri.getHost(), port, AuthScope.ANY_REALM), defaultcreds);//from w ww. j a v a 2 s . co m }
From source file:io.druid.storage.google.GoogleDataSegmentPuller.java
@Override public String getVersion(URI uri) throws IOException { String path = uri.getPath();//from w ww . ja v a2 s . co m if (path.startsWith("/")) { path = path.substring(1); } return storage.version(uri.getHost(), path); }
From source file:com.linkedin.kafka.clients.utils.tests.EmbeddedBroker.java
private void parseConfigs(Map<Object, Object> config) { id = Integer.parseInt((String) config.get("broker.id")); logDir = new File((String) config.get("log.dir")); //bind addresses String listenersString = (String) config.get("listeners"); for (String protocolAddr : listenersString.split("\\s*,\\s*")) { try {/* w ww .j av a2 s . c o m*/ URI uri = new URI(protocolAddr.trim()); SecurityProtocol protocol = SecurityProtocol.forName(uri.getScheme()); hosts.put(protocol, uri.getHost()); ports.put(protocol, null); //we get the value after boot } catch (Exception e) { throw new IllegalStateException(e); } } }
From source file:com.googlecode.sardine.AuthenticationTest.java
@Test public void testBasicPreemptiveAuthHeader() throws Exception { final DefaultHttpClient client = new DefaultHttpClient(); client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest r, final HttpContext context) throws HttpException, IOException { assertNotNull(r.getHeaders(HttpHeaders.AUTHORIZATION)); assertEquals(1, r.getHeaders(HttpHeaders.AUTHORIZATION).length); client.removeRequestInterceptorByClass(this.getClass()); }//from www .jav a 2s . c o m }); Sardine sardine = new SardineImpl(client); sardine.setCredentials("anonymous", null); // mod_dav supports Range headers for PUT final URI url = URI.create("http://sardine.googlecode.com/svn/trunk/README.html"); sardine.enablePreemptiveAuthentication(url.getHost()); assertTrue(sardine.exists(url.toString())); }
From source file:com.comcast.cats.domain.configuration.CatsProperties.java
public String getServerHost() throws URISyntaxException { String host = null;/*ww w.j a v a 2 s. c o m*/ if (null != getServerUrl()) { URI uri = new URI(getServerUrl()); host = uri.getHost(); } return host; }
From source file:io.jmnarloch.spring.cloud.discovery.DiscoveryClientPropertySource.java
/** * Expands the service URI.// w ww . j ava 2s . com * * @param uri the input uri * @return the result uri */ private URI expandUri(String uri) { try { final URI inputUri = URI.create(uri); final ServiceInstance serviceInstance = findOneService(inputUri.getHost()); if (serviceInstance == null) { return null; } return new URI((serviceInstance.isSecure() ? "https" : "http"), inputUri.getUserInfo(), serviceInstance.getHost(), serviceInstance.getPort(), inputUri.getPath(), inputUri.getQuery(), inputUri.getFragment()); } catch (URISyntaxException e) { logger.error("Unexpected error occurred when expanding the property URI", e); throw new RuntimeException("Could not parse URI value: " + uri, e); } }
From source file:net.audumla.scheduler.camel.SchedulerComponent.java
private TriggerKey createTriggerKey(String uri, String remaining, DefaultSchedulerEndpoint endpoint) throws Exception { // Parse uri for trigger name and group URI u = new URI(uri); String path = ObjectHelper.after(u.getPath(), "/"); String host = u.getHost(); // host can be null if the uri did contain invalid host characters such as an underscore if (host == null) { host = ObjectHelper.before(remaining, "/"); if (host == null) { host = remaining;/*from w ww .j ava2 s . c o m*/ } } // Trigger group can be optional, if so set it to this context's unique name String name; String group; if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(host)) { group = host; name = path; } else { String camelContextName = getCamelContext().getManagementName(); group = camelContextName == null ? "Camel" : "Camel_" + camelContextName; name = host; } if (prefixJobNameWithEndpointId) { name = endpoint.getId() + "_" + name; } return new TriggerKey(name, group); }
From source file:net.sf.ufsc.ftp.FtpSession.java
/** * Constructs a new FtpSession./*from w ww.j a v a 2 s .c o m*/ * @param uri * @throws IOException */ public FtpSession(URI uri, FTPClient client) throws IOException { super(uri); this.client = client; UserInfo userInfo = new UserInfo(uri); String host = uri.getHost(); int port = uri.getPort(); if (port < 0) { this.client.connect(host); } else { this.client.connect(host, port); } String reply = this.client.getReplyString(); if (!FTPReply.isPositiveCompletion(this.client.getReplyCode())) { this.close(); throw new IOException(reply); } this.logger.info(reply); boolean loggedIn = this.client.login(userInfo.getUser(), userInfo.getPassword()); reply = this.client.getReplyString(); if (!loggedIn) { this.close(); throw new IOException(reply); } this.logger.info(reply); this.client.enterLocalPassiveMode(); }