List of usage examples for java.net URI getScheme
public String getScheme()
From source file:com.splunk.shuttl.archiver.model.Bucket.java
private static File getFileFromUri(URI uri) { if (uri != null && "file".equals(uri.getScheme())) return new File(uri); return null;/*from w w w . j a v a 2 s. c om*/ }
From source file:com.navnorth.learningregistry.LRClient.java
public static String executeHttpPost(String url, ArrayList postParameters) throws Exception { BufferedReader in = null;// w w w . j a v a 2 s . c o m try { URI uri = new URI(url); HttpClient client = getHttpClient(uri.getScheme()); HttpPost request = new HttpPost(uri); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters); request.setEntity(formEntity); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String result = sb.toString(); return result; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.navnorth.learningregistry.LRClient.java
public static HttpResponse executeJsonPost(String url, StringEntity se, String username, String password) throws Exception { BufferedReader in = null;//from ww w. j a v a 2 s .co m try { URI uri = new URI(url); HttpClient client = getHttpClient(uri.getScheme()); HttpPost post = new HttpPost(uri); post.setEntity(se); post.setHeader("Content-Type", "application/json"); if (username != null && password != null) { String userPass = username + ":" + password; byte[] encodedAuth = Base64.encodeBase64(userPass.getBytes()); String encodedAuthStr = new String(encodedAuth); post.addHeader("Authorization", "Basic " + encodedAuthStr); } HttpResponse response = client.execute(post); return response; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:org.onebusaway.io.client.test.UriAssert.java
/** * Check request for matching Uri.// w w w .j a va 2s .co m * * @param expectedUri The Uri the test should expect (query values are ignored, use * expectedQuery) * @param expectedQuery A Map of query key/values required to be in the Uri. * Use asterisk to require key, but ignore value. Order is irrelevant. * The list is not exhaustive, extra key/values are ignored. */ public static void assertUriMatch(URI expectedUri, Map<String, String> expectedQuery, URI actualUri) { assertEquals(expectedUri.getHost(), actualUri.getHost()); assertEquals(expectedUri.getScheme(), actualUri.getScheme()); assertEquals(expectedUri.getPath(), actualUri.getPath()); List<NameValuePair> actualParams = URLEncodedUtils.parse(actualUri, "UTF-8"); if (expectedQuery != null) { for (Map.Entry<String, String> entry : expectedQuery.entrySet()) { String expectedValue = entry.getValue(); String actualValue = null; // Find actual param for (NameValuePair pair : actualParams) { if (pair.getName().equalsIgnoreCase(entry.getKey())) { actualValue = pair.getValue(); } } if ("*".equals(expectedValue)) { assertNotNull("URI missing key \"" + entry.getKey() + "\"", actualValue); } else { assertEquals("URI mismatch on query key \"" + entry.getKey() + "\"", expectedValue, actualValue); } } } }
From source file:de.metas.procurement.webui.ui.view.PasswordResetView.java
public static final URI buildPasswordResetURI(final String passwordResetKey) { try {/*w w w . ja v a 2s. c om*/ final URI uri = Page.getCurrent().getLocation(); final String query = null; final String fragment = MFNavigator.createURIFragment(NAME, passwordResetKey); final URI resetURI = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), query, fragment); System.out.println(resetURI); return resetURI; } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:oracle.custom.ui.utils.ServerUtils.java
public static PublicKey getServerPublicKey(String domainName) throws Exception { HttpClient client = getClient(domainName); PublicKey key = null;/*from w w w . ja v a 2 s . co m*/ String url = getIDCSBaseURL(domainName) + "/admin/v1/SigningCert/jwk"; URI uri = new URI(url); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpGet httpGet = new HttpGet(uri); httpGet.addHeader("Authorization", "Bearer " + AccessTokenUtils.getAccessToken(domainName)); HttpResponse response = client.execute(host, httpGet); try { HttpEntity entity2 = response.getEntity(); String res = EntityUtils.toString(entity2); EntityUtils.consume(entity2); ObjectMapper mapper = new ObjectMapper(); System.out.println("result is " + res); SigningKeys signingKey = mapper.readValue(res, SigningKeys.class); String base64Cert = signingKey.getKeys().get(0).getX5c().get(0); byte encodedCert[] = Base64.getDecoder().decode(base64Cert); ByteArrayInputStream inputStream = new ByteArrayInputStream(encodedCert); CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certFactory.generateCertificate(inputStream); key = cert.getPublicKey(); } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } return key; }
From source file:org.apache.openmeetings.service.calendar.caldav.handler.EtagsHandler.java
/** * @param uri URI to provide the host and scheme * @param path Path to append to host//from w ww. j a va 2s . c om * @return Returns the full path, based on the URI as host and the path provided */ private static String getFullPath(URI uri, String path) { return uri.getScheme() + "://" + uri.getAuthority() + path; }
From source file:io.syndesis.credential.BaseCredentialProvider.java
protected static String callbackUrlFor(final URI baseUrl, final MultiValueMap<String, String> additionalParams) { final String path = baseUrl.getPath(); final String callbackPath = path + "credentials/callback"; try {/*from ww w . ja v a 2 s . c o m*/ final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath, null, null); return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString(); } catch (final URISyntaxException e) { throw new IllegalStateException("Unable to generate callback URI", e); } }
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 w w . j a va 2 s . c om 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:me.footlights.core.crypto.Fingerprint.java
public static Fingerprint decode(URI uri) throws FormatException, NoSuchAlgorithmException, URISyntaxException { if ((uri.getScheme() == null) || !uri.getScheme().equals("urn")) throw new FormatException("Fingerprint must start with 'urn:'"); // Recurse down into scheme-specific part, which is also a URI. URI data = new URI(uri.getSchemeSpecificPart()); return decode(data.getScheme(), data.getSchemeSpecificPart()); }