List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:com.orange.cepheus.broker.Util.java
static public NotifyContext createNotifyContextTempSensor(float randomValue) throws URISyntaxException { NotifyContext notifyContext = new NotifyContext("1", new URI("http://iotAgent")); ContextElementResponse contextElementResponse = new ContextElementResponse(); contextElementResponse.setContextElement(createTemperatureContextElement(randomValue)); contextElementResponse.setStatusCode(new StatusCode(CODE_200)); notifyContext.setContextElementResponseList(Collections.singletonList(contextElementResponse)); return notifyContext; }
From source file:UriUtils.java
/** * Resolves the specified URI, and returns the file represented by the URI. * * @param uri The URI for which to return an absolute path. * @return The {@link File} instance represented by the specified URI. * @throws IllegalArgumentException <ul><li>The URI cannot be null.</li><li>Wrong URI scheme for path resolution; * only file:// URIs are supported.</li></ul> *//* w w w. j a v a 2 s .c o m*/ public static File getFile(URI uri) throws IllegalArgumentException { if (uri == null) throw new IllegalArgumentException("The URI cannot be null."); if (!"file".equals(uri.getScheme())) throw new IllegalArgumentException("Wrong URI scheme for path resolution, expected \"file\" " + "and got \"" + uri.getScheme() + "\""); // Workaround for the following bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147 // Remove (or add, take your pick...) extra slashes after the scheme part. if (uri.getAuthority() != null) try { uri = new URI(uri.toString().replace("file://", "file:/")); } catch (URISyntaxException e) { throw new IllegalArgumentException( "The specified URI contains an authority, but could not be " + "normalized.", e); } return new File(uri); }
From source file:com.almende.eve.transport.amqp.AmqpTransportConfig.java
/** * Gets the address./* w w w. j a va2 s.c o m*/ * * @return the address */ public URI getAddress() { if (this.has("address")) { try { return new URI(this.get("address").asText()); } catch (final URISyntaxException e) { LOG.warning("Couldn't parse URI from: " + this.get("address").asText()); } } return null; }
From source file:com.cazcade.billabong.image.impl.ImageMain.java
private static void sendRequest(ImageService service, String uriString) throws URISyntaxException { CacheResponse response = service.getCacheURI(new URI(uriString), ImageSize.CLIPPED_MEDIUM, uriString); System.out.println(response.getURI()); System.out.println(response.getRefreshIndicator()); }
From source file:in.rab.ordboken.CookieSerializer.java
public void loadFromString(String json) { try {/*from w w w . j a v a 2s. c o m*/ JSONObject obj = new JSONObject(json); JSONArray cookieStrings = obj.getJSONArray("cookies"); URI uri = new URI("http://" + mDomain); for (int i = 0; i < cookieStrings.length(); i++) { String cookieString = cookieStrings.getString(i); HttpCookie cookie = HttpCookie.parse(cookieString).get(0); cookie.setPath("/"); cookie.setDomain(mDomain); mCookieStore.add(uri, cookie); } } catch (Exception e) { // No big deal if this fails. } }
From source file:de.dan_nrw.web.tests.WebClientTestSuite.java
@Test @SuppressWarnings("unchecked") public void retrieving_data_from_valid_uri_should_not_throw_exception() throws Exception { WebClient webClient = new WebClient(); URI uri = new URI("http://www.google.com"); HttpResponseHandler<Void> responseHandler = mock(HttpResponseHandler.class); when(responseHandler.handleResponse(any(HttpResponse.class))).thenReturn(null); webClient.sendRequest(uri, responseHandler); }
From source file:com.qwazr.extractor.UriInfoImplTest.java
@Test public void allTests() throws URISyntaxException { Assert.assertEquals(new URI("http://localhost:9090/service/extractor/html"), uriInfo.getAbsolutePath()); Assert.assertEquals(new URI("http://localhost:9090/service/"), uriInfo.getBaseUri()); Assert.assertEquals(// w w w . ja v a 2 s . c o m new URI("http://localhost:9090/service/extractor/html?raw=valueA&raw=valueB&enc=valu%C3%A9"), uriInfo.getRequestUri()); Assert.assertEquals(new URI("http://localhost:9090/service/extractor/html"), uriInfo.getAbsolutePathBuilder().build()); Assert.assertEquals(new URI("http://localhost:9090/service/"), uriInfo.getBaseUriBuilder().build()); Assert.assertEquals( new URI("http://localhost:9090/service/extractor/html?raw=valueA&raw=valueB&enc=valu%C3%A9"), uriInfo.getRequestUriBuilder().build()); Assert.assertEquals("extractor/html", uriInfo.getPath()); Assert.assertEquals("extractor/html", uriInfo.getPath(false)); Assert.assertEquals("extractor/html", uriInfo.getPath(true)); Assert.assertArrayEquals(new String[] { "valueA", "valueB" }, uriInfo.getQueryParameters().get("raw").toArray()); Assert.assertArrayEquals(new String[] { "valueA", "valueB" }, uriInfo.getQueryParameters(false).get("raw").toArray()); Assert.assertArrayEquals(new String[] { "valueA", "valueB" }, uriInfo.getQueryParameters(true).get("raw").toArray()); Assert.assertEquals("valu", uriInfo.getQueryParameters().getFirst("enc")); Assert.assertEquals("valu", uriInfo.getQueryParameters(true).getFirst("enc")); Assert.assertEquals("valu%C3%A9", uriInfo.getQueryParameters(false).getFirst("enc")); Assert.assertEquals("extractor", uriInfo.getPathSegments().get(0).getPath()); Assert.assertEquals("extractor", uriInfo.getPathSegments(true).get(0).getPath()); Assert.assertEquals("extractor", uriInfo.getPathSegments(false).get(0).getPath()); Assert.assertEquals("html", uriInfo.getPathSegments().get(1).getPath()); Assert.assertEquals("html", uriInfo.getPathSegments(true).get(1).getPath()); Assert.assertEquals("html", uriInfo.getPathSegments(false).get(1).getPath()); Assert.assertEquals(new URI("relative"), uriInfo.relativize(new URI("http://localhost:9090/service/extractor/html/relative"))); Assert.assertEquals(new URI("http://localhost:9090/service/extractor/pdf"), uriInfo.resolve(new URI("extractor/pdf"))); final UriInfo noPathNoQueyUri = new UriInfoImpl("http://localhost", ""); Assert.assertEquals(0, noPathNoQueyUri.getQueryParameters().size()); Assert.assertEquals(0, noPathNoQueyUri.getPathSegments().size()); }
From source file:test.pl.chilldev.web.tags.page.PrintXmlnsTagTest.java
@Test public void doTag() throws URISyntaxException, IOException, JspTagException { MockPageContext context = new MockPageContext(); PrintXmlnsTag tag = new PrintXmlnsTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);//from w w w . j av a2s .c o m // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); URI namespace = new URI("http://chilldev.pl/"); String alias = "cdv"; page.setXmlNamespace(namespace, alias); // run the tag tag.doTag(); assertEquals("PrintXmlnsTag.doTag() should print XML namespace attributes.", page.generateXmlnsAttributes(), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.page.XmlPrefixTagTest.java
@Test public void doTag() throws URISyntaxException, IOException, JspTagException { MockPageContext context = new MockPageContext(); XmlPrefixTag tag = new XmlPrefixTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);//from www . ja v a2 s . c om // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); URI namespace = new URI("http://chilldev.pl/"); String alias = "cdv"; page.setXmlNamespace(namespace, alias); // run the tag tag.setNamespace(namespace); tag.doTag(); assertEquals("XmlPrefixTag.doTag() should print XML prefix for given namespace.", page.getXmlPrefix(namespace), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:architecture.ee.web.util.ServletUtils.java
public static String getDomainName(String url, boolean opt) { if (StringUtils.isNotEmpty(url)) { try {/*from w w w . jav a 2 s .c om*/ URI uri = new URI(url); String domain = uri.getHost(); if (opt) return domain.startsWith("www.") ? domain.substring(4) : domain; return domain; } catch (URISyntaxException e) { } } return null; }