List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:com.tweetlanes.android.urlservice.tweetmarker.TweetMarkerAPI.java
public static HttpResponse getRequest(String url, String debugName) { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.addHeader("X-Auth-Service-Provider", TwitterApi.TWITTER_VERIFY_CREDENTIALS_JSON); request.addHeader("X-Verify-Credentials-Authorization", TwitterManager.get().generateTwitterVerifyCredentialsAuthorizationHeader()); HttpResponse response = null;//from w w w. ja va2 s .co m try { request.setURI(new URI(url)); //Log.d("tweetlanes url fetch", url); response = client.execute(request); //Log.d(TAG, debugName + " complete"); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; }
From source file:org.jtalks.tests.jcommune.mail.mailtrap.MailtrapClient.java
/** * Gets list of messages metadata//www . j a v a 2 s.c o m * * @return the list of messages metadata * @throws CouldNotGetMessagesException */ public static String getMessages() throws CouldNotGetMessagesException { RestTemplate client = new RestTemplate(); try { String data = client.getForObject( new URI(API_INBOXES_URL + JTALKS_AUTOTESTS_MESSAGES + API_TOKEN_PARAM), String.class); return data; } catch (Exception e) { throw new CouldNotGetMessagesException(e); } }
From source file:UriUtils.java
/** * Returns the parent of the specified URI. * <p/>/*from w ww. j a va 2 s . c om*/ * For example, applying this method to the URI "<tt>http://www.site.com/articles/article.html</tt>" will * return the URI for "<tt>http://www.site.com/articles/</tt>". * * @param uri The URI for which to return the parent. * @return The parent of the specified URI. * @throws IllegalArgumentException <ul> <li>The URI cannot be null></li> <li>Can't resolve parent for the specified * URI.</li> </ul> */ public static URI getParent(final URI uri) throws IllegalArgumentException { if (uri == null) throw new IllegalArgumentException("The URI cannot be null."); final String path = uri.toString(); final int finalSeparator = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')); final int extension = path.lastIndexOf('.'); if (extension > finalSeparator) try { // Extract all but final segment return new URI(path.substring(0, finalSeparator + 1)).normalize(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Can't resolve parent for the specified URI.", e); } else return uri.resolve(up); }
From source file:QuickTest.java
@Test public void testURI() throws URISyntaxException { final URI uri = new URI("/runrightfast.co/heartbeat/1/0"); log.log(Level.INFO, "uri: {0}", uri); assertThat(uri, is(new URI("/runrightfast.co/heartbeat//1/0").normalize())); assertThat(uri, is(not(new URI("/runrightfast.co/heartbeat/1/1")))); log.info(String.format("reolved URI : %s", new URI("/runrightfast.co/").resolve("event-logging-service/").resolve(new URI("1/0")))); }
From source file:Main.java
public static URI unredirect(URI uri) throws IOException { if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) { return uri; }//from w w w . j a va 2 s .c o m URL url = uri.toURL(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setInstanceFollowRedirects(false); connection.setDoInput(false); connection.setRequestMethod("HEAD"); connection.setRequestProperty("User-Agent", "ZXing (Android)"); try { connection.connect(); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_MULT_CHOICE: case HttpURLConnection.HTTP_MOVED_PERM: case HttpURLConnection.HTTP_MOVED_TEMP: case HttpURLConnection.HTTP_SEE_OTHER: case 307: // No constant for 307 Temporary Redirect ? String location = connection.getHeaderField("Location"); if (location != null) { try { return new URI(location); } catch (URISyntaxException e) { // nevermind } } } return uri; } finally { connection.disconnect(); } }
From source file:ca.sqlpower.dao.session.FileConverter.java
@Override public File convertToComplexType(String convertFrom) throws ConversionException { try {// w ww . java2s . com return new File(new URI(convertFrom)); } catch (URISyntaxException e) { throw new ConversionException(e); } }
From source file:at.tfr.securefs.client.TestWebSocket.java
@Ignore @Test/*from ww w.java2s. c o m*/ public void testSendFile() throws Exception { Path path = Paths.get(getClass().getResource("/test.txt").toURI()); Message m = new Message(MessageType.OPEN, "test.txt"); WebsocketHandler wh = new WebsocketHandler(new URI(localhost), m, path.getParent()); wh.connectBlocking(); synchronized (wh) { wh.wait(100000L); } }
From source file:net.javacrumbs.springws.test.MockWebServiceMessageSenderTest.java
@Test public void testCreateConnection() throws Exception { AbstractMockWebServiceMessageSender sender = new MockWebServiceMessageSender(); URI uri = new URI("http://example.org/"); assertTrue(sender.supports(uri));/*from w w w .j a v a2s . co m*/ List<EndpointInterceptor> interceptors = Arrays .<EndpointInterceptor>asList(new PayloadLoggingInterceptor()); sender.setInterceptors(interceptors); MockWebServiceConnection connection = (MockWebServiceConnection) sender.createConnection(uri); assertNotNull(connection); assertEquals(interceptors, connection.getInterceptors()); }
From source file:com.recursivechaos.clearent.controller.SaleControllerTest.java
@Test public void testPostSale() throws Exception { Sale saleRequest = TestUtil.createSaleRequest(); when(saleService.createSale(saleRequest)).thenReturn(saleRequest); URI uri = new URI("/sales/1"); when(responseService.getLocationUri(saleRequest)).thenReturn(uri); ResponseEntity<Void> responseEntity = saleController.postSale(saleRequest); assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); assertEquals("/sales/1", responseEntity.getHeaders().getLocation().getPath()); }
From source file:jp.go.nict.langrid.commons.jxpath.WSDLUtil.java
/** * // ww w . j av a2s .c o m * */ public static URI getTargetNamespace(InputStream body) throws IOException, SAXException, URISyntaxException { String value = (String) newWSDLContext(body, "_").getValue("_:definitions/@targetNamespace"); if (value == null) return null; return new URI(value); }