List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManagerTests.java
@Test public void testAuthenticate() throws Exception { responseHeaders.setLocation(new URI("https://uaa.cloudfoundry.com/")); Map<String, String> response = new HashMap<String, String>(); response.put("username", "marissa"); @SuppressWarnings("rawtypes") ResponseEntity<Map> expectedResponse = new ResponseEntity<Map>(response, responseHeaders, HttpStatus.OK); when(restTemplate.exchange(endsWith("/authenticate"), eq(HttpMethod.POST), any(HttpEntity.class), eq(Map.class))).thenReturn(expectedResponse); Authentication result = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken("marissa", "foo")); assertEquals("marissa", result.getName()); assertTrue(result.isAuthenticated()); }
From source file:org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi.java
public IndyZabbixApi(String url) { try {/*from ww w .ja v a 2s .c o m*/ uri = new URI(url.trim()); } catch (URISyntaxException e) { logger.error("url invalid", e); } }
From source file:info.rmapproject.webapp.utils.WebappUtils.java
/** * Replace the namespace URL with something more readable. * * @param url the url//from ww w . j av a 2 s .c o m * @return the shortened term that uses the prefix. */ public static String replaceNamespace(String url) { try { URI uri = new URI(url); String path = null; String term = null; String newUrl = url; if (url.contains("#")) { term = uri.getFragment(); path = url.substring(0, url.lastIndexOf("#") + 1); } else if (url.contains("/") && path == null) { term = url.substring(url.lastIndexOf("/") + 1); path = url.substring(0, url.lastIndexOf("/") + 1); } if (term != null && path != null && term.length() > 0 && path.length() > 0) { String prefix = null; try { prefix = prefixes.getMessage(path, null, Locale.ENGLISH); } catch (NoSuchMessageException e) { // null prefix handled below } if (prefix != null && prefix.length() > 0) { newUrl = prefix + ":" + term; } else { newUrl = "x" + ":" + term; } } return newUrl; } catch (URISyntaxException e) { //it's not a uri... that's OK, send it back... return url; } }