List of usage examples for java.net URI getHost
public String getHost()
From source file:org.aludratest.cloud.selenium.impl.SeleniumHttpProxy.java
public static SeleniumHttpProxy create(int id, SeleniumResourceImpl resource, String prefix, long timeout, long maxIdleTime, String accessUrl, ScheduledExecutorService healthCheckExecutor) { URI oUri = URI.create(resource.getOriginalUrl()); SeleniumHttpProxy proxy = new SeleniumHttpProxy(oUri.getScheme(), prefix, oUri.getHost(), oUri.getPort(), oUri.getPath());//from w w w . ja va 2 s. co m proxy.id = id; proxy.resource = resource; proxy.timeout = timeout; proxy.accessUrl = accessUrl; proxy.maxIdleTime = maxIdleTime; proxy.healthCheckClient = createHealthCheckHttpClient(); proxy.healthCheckExecutor = healthCheckExecutor; // set resource to DISCONNECTED first resource.setState(ResourceState.DISCONNECTED); proxy.nextHealthCheck = healthCheckExecutor.schedule(proxy.checkStatusRunnable, 2000, TimeUnit.MILLISECONDS); return proxy; }
From source file:com.gamesalutes.utils.WebUtils.java
/** * Adds the query parameters to the uri <code>path</code>. * /*from w w w .jav a 2 s .c om*/ * @param path the uri * @param parameters the query parameters to set for the uri * @return <code>path</code> with the query parameters added */ public static URI setQueryParameters(URI path, Map<String, String> parameters) { try { return new URI(path.getScheme(), path.getRawUserInfo(), path.getHost(), path.getPort(), path.getRawPath(), urlEncode(parameters, false), path.getRawFragment()); } catch (URISyntaxException e) { // shouldn't happen throw new AssertionError(e); } }
From source file:org.bibalex.gallery.storage.BAGStorage.java
public static boolean putFile(String remoteUrlStr, File localFile, String contentType, int timeout) throws BAGException { HttpPut httpput = null;//from w w w. j av a2 s. com DefaultHttpClient httpclient = null; try { BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, timeout); httpclient = new DefaultHttpClient(httpParams); URI remoteUrl = new URI(remoteUrlStr); String userInfo = remoteUrl.getUserInfo(); if ((userInfo != null) && !userInfo.isEmpty()) { int colonIx = userInfo.indexOf(':'); httpclient.getCredentialsProvider().setCredentials( new AuthScope(remoteUrl.getHost(), remoteUrl.getPort()), new UsernamePasswordCredentials( userInfo.substring(0, colonIx), userInfo.substring(colonIx + 1))); } if ((contentType == null) || contentType.isEmpty()) { contentType = "text/plain; charset=\"UTF-8\""; } FileEntity entity = new FileEntity(localFile, contentType); httpput = new HttpPut(remoteUrlStr); httpput.setEntity(entity); HttpResponse response = httpclient.execute(httpput); return response.getStatusLine().getStatusCode() - 200 < 100; } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw new BAGException(ex); } catch (RuntimeException ex) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection and release it back to the connection manager. httpput.abort(); throw ex; } catch (URISyntaxException e) { // will be still null: httpput.abort(); throw new BAGException(e); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:de.fuberlin.agcsw.heraclitus.svont.client.core.ChangeLog.java
public static void updateChangeLog(OntologyStore os, SVoNtProject sp, String user, String pwd) { //load the change log from server try {/* ww w .j a va2 s .com*/ //1. fetch Changelog URI URI u = sp.getChangelogURI(); //2. search for change log owl files DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials( new AuthScope(u.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(user, pwd)); HttpGet httpget = new HttpGet(u); System.out.println("executing request" + httpget.getRequestLine()); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = client.execute(httpget, responseHandler); System.out.println(response); List<String> files = ChangeLog.extractChangeLogFiles(response); ArrayList<ChangeLogElement> changelog = sp.getChangelog(); changelog.clear(); //4. sort the revisions for (int i = 0; i < files.size(); i++) { String fileName = files.get(i); System.out.println("rev sort: " + fileName); int rev = Integer.parseInt(fileName.split("\\.")[0]); changelog.add(new ChangeLogElement(URI.create(u + fileName), rev)); } Collections.sort(changelog, new SortChangeLogsElementsByRev()); //show sorted changelog System.out.print("["); for (ChangeLogElement cle : changelog) { System.out.print(cle.getRev() + ","); } System.out.println("]"); //5. map revision with SVN revisionInformations mapRevisionInformation(os, sp, changelog); //6. load change log files System.out.println("Load Changelog Files"); for (String s : files) { System.out.println(s); String req = u + s; httpget = new HttpGet(req); response = client.execute(httpget, responseHandler); // System.out.println(response); // save the changelog File persistent IFolder chlFold = sp.getChangeLogFolder(); IFile chlFile = chlFold.getFile(s); if (!chlFile.exists()) { chlFile.create(new ByteArrayInputStream(response.getBytes()), true, null); } os.getOntologyManager().loadOntology(new ReaderInputSource(new StringReader(response))); } System.out.println("Changelog Ontology successfully loaded"); //Show loaded onts Set<OWLOntology> onts = os.getOntologyManager().getOntologies(); for (OWLOntology o : onts) { System.out.println("loaded ont: " + o.getURI()); } //7 refresh possibly modified Mainontology os.getOntologyManager().reloadOntology(os.getMainOntologyLocalURI()); //8. recalculate Revision Information of the concept of this ontology sp.setRevisionMap(createConceptRevisionMap(os, sp)); sp.saveRevisionMap(); sp.saveRevisionInformationMap(); //9. show MetaInfos on ConceptTree ConceptTree.refreshConceptTree(os, os.getMainOntologyURI()); OntologyInformation.refreshOntologyInformation(os, os.getMainOntologyURI()); //shutdown http connection client.getConnectionManager().shutdown(); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (OWLReasonerException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SVNException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SVNClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.hawk.service.api.utils.APIUtils.java
@SuppressWarnings({ "deprecation", "restriction" }) public static <T extends TServiceClient> T connectTo(Class<T> clazz, String url, ThriftProtocol thriftProtocol, final Credentials credentials) throws TTransportException, URISyntaxException { try {//from w ww. ja va 2 s . c o m final URI parsed = new URI(url); TTransport transport; if (parsed.getScheme().startsWith("http")) { final DefaultHttpClient httpClient = APIUtils.createGZipAwareHttpClient(); if (credentials != null) { httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), credentials); } transport = new THttpClient(url, httpClient); } else { transport = new TZlibTransport(new TSocket(parsed.getHost(), parsed.getPort())); transport.open(); } Constructor<T> constructor = clazz.getDeclaredConstructor(org.apache.thrift.protocol.TProtocol.class); return constructor.newInstance(thriftProtocol.getProtocolFactory().getProtocol(transport)); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new TTransportException(e); } }
From source file:com.offbytwo.jenkins.client.JenkinsHttpClient.java
protected static HttpClientBuilder addAuthentication(HttpClientBuilder builder, URI uri, String username, String password) {//from www .jav a2 s . co m if (isNotBlank(username)) { CredentialsProvider provider = new BasicCredentialsProvider(); AuthScope scope = new AuthScope(uri.getHost(), uri.getPort(), "realm"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(scope, credentials); builder.setDefaultCredentialsProvider(provider); builder.addInterceptorFirst(new PreemptiveAuth()); } return builder; }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static String getHttpsGitUrlFromSshUrl(final String sshGitRemoteUrl) { if (isSshGitRemoteUrl(sshGitRemoteUrl)) { final URI sshUrl; if (!StringUtils.startsWithIgnoreCase(sshGitRemoteUrl, "ssh://")) { sshUrl = UrlHelper.createUri("ssh://" + sshGitRemoteUrl); } else {//w w w . j a v a2 s. com sshUrl = UrlHelper.createUri(sshGitRemoteUrl); } final String host = sshUrl.getHost(); final String path = sshUrl.getPath(); final URI httpsUrl = UrlHelper.createUri("https://" + host + path); return httpsUrl.toString(); } return null; }
From source file:password.pwm.http.servlet.OAuthConsumerServlet.java
public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) { final HttpServletRequest req = pwmRequest.getHttpServletRequest(); final String redirect_uri; try {/*from ww w . j a va 2 s .com*/ final URI requestUri = new URI(req.getRequestURL().toString()); redirect_uri = requestUri.getScheme() + "://" + requestUri.getHost() + (requestUri.getPort() > 0 ? ":" + requestUri.getPort() : "") + PwmServletDefinition.OAuthConsumer.servletUrl(); } catch (URISyntaxException e) { throw new IllegalStateException( "unable to parse inbound request uri while generating oauth redirect: " + e.getMessage()); } return redirect_uri; }
From source file:com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration.java
/** * Fix a serverUrl./* w ww . ja v a2 s. c o m*/ * * @param serverUrl the server URL. * @return the normalized server URL. */ @NonNull public static String normalizeServerUrl(@CheckForNull String serverUrl) { serverUrl = StringUtils.defaultIfBlank(serverUrl, BitbucketCloudEndpoint.SERVER_URL); try { URI uri = new URI(serverUrl).normalize(); String scheme = uri.getScheme(); if ("http".equals(scheme) || "https".equals(scheme)) { // we only expect http / https, but also these are the only ones where we know the authority // is server based, i.e. [userinfo@]server[:port] // DNS names must be US-ASCII and are case insensitive, so we force all to lowercase String host = uri.getHost() == null ? null : uri.getHost().toLowerCase(Locale.ENGLISH); int port = uri.getPort(); if ("http".equals(scheme) && port == 80) { port = -1; } else if ("https".equals(scheme) && port == 443) { port = -1; } serverUrl = new URI(scheme, uri.getUserInfo(), host, port, uri.getPath(), uri.getQuery(), uri.getFragment()).toASCIIString(); } } catch (URISyntaxException e) { // ignore, this was a best effort tidy-up } return serverUrl.replaceAll("/$", ""); }
From source file:annis.libgui.Helper.java
public static String generateClassicCitation(String aql, List<String> corpora, int contextLeft, int contextRight) { StringBuilder sb = new StringBuilder(); URI appURI = UI.getCurrent().getPage().getLocation(); sb.append(getContext());//from w w w .ja v a2 s . c om sb.append("/Cite/AQL("); sb.append(aql); sb.append("),CIDS("); sb.append(StringUtils.join(corpora, ",")); sb.append("),CLEFT("); sb.append(contextLeft); sb.append("),CRIGHT("); sb.append(contextRight); sb.append(")"); try { return new URI(appURI.getScheme(), null, appURI.getHost(), appURI.getPort(), sb.toString(), null, null) .toASCIIString(); } catch (URISyntaxException ex) { log.error(null, ex); } return "ERROR"; }