List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:com.switchfly.inputvalidation.sanitizer.UrlStripHtmlSanitizer.java
@Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; }/*w ww . ja v a 2 s . c o m*/ URI uri; try { uri = new URI(content); } catch (URISyntaxException e) { throw new RuntimeException(e); } List<NameValuePair> cleanedPairs = parse(uri); String queryString = cleanedPairs.isEmpty() ? null : URLEncodedUtils.format(cleanedPairs, ENCODING); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryString, uri.getFragment()).toString(); } catch (URISyntaxException e) { throw new RuntimeException(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()); }
From source file:com.googlecode.vfsjfilechooser2.utils.DefaultFileObjectConverter.java
/** * Converts the {@link FileObject} object into a Java file object. * /*from www . j a v a 2 s . co m*/ * @param file the object to convert * @return the generated object, or null if failed to convert */ @Override public File convertFileObject(FileObject file) { if (file == null) return null; try { return new File(new URI(file.getName().getURI().replace(" ", "%20"))); } catch (Exception e) { System.err.println("Failed to convert '" + file + "' into file!"); e.printStackTrace(); return null; } }
From source file:org.chaplib.TestHttpResourceFactory.java
@Test public void equivalentURIsResultInSameHttpResource() throws Exception { URI uri2 = new URI("http://www.example.com"); assertSame(impl.get(uri), impl.get(uri2)); }
From source file:com.rusticisoftware.tincan.Verb.java
public Verb(String id, String display) throws URISyntaxException { this(new URI(id), display); }
From source file:vazkii.psi.client.core.helper.SharingHelper.java
public static void uploadAndShare(String title, String export) { String url = uploadImage(title, export); try {//from w w w .j ava 2s . c o m String contents = "## " + title + " \n" + "### [Image + Code](" + url + ")\n" + "(to get the code click the link, RES won't show it)\n" + "\n" + "---" + "\n" + "*REPLACE THIS WITH A DESCRIPTION OF YOUR SPELL \n" + "Make sure you read the rules before posting. Look on the sidebar: https://www.reddit.com/r/psispellcompendium/ \n" + "Delete this part before you submit.*"; String encodedContents = URLEncoder.encode(contents, "UTF-8"); String encodedTitle = URLEncoder.encode(title, "UTF-8"); String redditUrl = "https://www.reddit.com/r/psispellcompendium/submit?title=" + encodedTitle + "&text=" + encodedContents; if (Desktop.isDesktopSupported()) Desktop.getDesktop().browse(new URI(redditUrl)); } catch (Exception e) { e.printStackTrace(); } }
From source file:lh.api.showcase.server.lh.api.referencedata.ReferenceDataRequestFactoryImplTest.java
@Test public void shouldConstructCountriesRequestUri() { ReferenceDataRequestFactoryImpl reqFact = new ReferenceDataRequestFactoryImpl(); try {/*from w w w . j a v a2s .c o m*/ URI constructedUri = reqFact.getRequestUri((NameValuePair) new BasicNameValuePair("countries", "DK"), null, Arrays.asList((NameValuePair) new BasicNameValuePair("lang", "EN"))); URI referenceUri = new URI("https://api.lufthansa.com/v1/references/countries/DK?lang=EN"); logger.log(Level.INFO, "constructed: " + constructedUri.toString()); logger.log(Level.INFO, "reference: " + referenceUri.toString()); assertTrue(referenceUri.equals(constructedUri)); } catch (URISyntaxException e) { assertTrue(false); } }
From source file:com.microsoft.gittf.core.util.URIUtil.java
/** * Converts the specified string into a valid server URI. The method will * update the URI if needed when connecting to the hosted service, to make * sure that the connection is HTTPS and is to the default collection * /*from w ww . java 2 s . c o m*/ * @param serverURIString * the uri string to convert * @return * @throws Exception */ public static URI getServerURI(final String serverURIString) throws Exception { try { URI uri = new URI(serverURIString); if (!uri.isAbsolute() || uri.isOpaque()) { uri = null; } if (uri != null) { uri = updateIfNeededForHostedService(uri); } if (uri == null) { throw new Exception(Messages.formatString("URIUtil.InvalidURIFormat", serverURIString)); //$NON-NLS-1$ } return uri; } catch (Exception e) { log.warn("Could not parse URI", e); //$NON-NLS-1$ } throw new Exception(Messages.formatString("URIUtil.InvalidURIFormat", serverURIString)); //$NON-NLS-1$ }
From source file:org.springframework.cloud.stream.binder.rabbit.admin.RabbitManagementUtils.java
public static RestTemplate buildRestTemplate(String adminUri, String user, String password) { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); // Set up pre-emptive basic Auth because the rabbit plugin doesn't currently support challenge/response for PUT // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local; from the apache docs... // auth cache BasicScheme basicAuth = new BasicScheme(); URI uri;// ww w.ja v a 2s. com try { uri = new URI(adminUri); } catch (URISyntaxException e) { throw new RabbitAdminException("Invalid URI", e); } authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); // Add AuthCache to the execution context final HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient) { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return localContext; } }); restTemplate.setMessageConverters( Collections.<HttpMessageConverter<?>>singletonList(new MappingJackson2HttpMessageConverter())); return restTemplate; }
From source file:com.spotify.docker.client.UnixConnectionSocketFactoryTest.java
@Before public void setup() throws Exception { sut = new UnixConnectionSocketFactory(new URI("unix://localhost")); }