List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:ws.salient.model.Repository.java
public Repository(String id, String url) { this.id = id; try {/* w w w. j av a 2s. co m*/ this.url = new URI(url); } catch (URISyntaxException ex) { throw new IllegalArgumentException(url, ex); } }
From source file:com.shafiq.mytwittle.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;/*ww w. j a v a 2s . c o 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:net.dian1.player.api.util.Caller.java
/** * Performs HTTP GET using Apache HTTP Client v 4 * /* w ww .ja va2s .c om*/ * @param url * @return * @throws WSError */ public static String doGet(String url) throws WSError { String data = null; if (requestCache != null) { data = requestCache.get(url); if (data != null) { Log.d(Dian1Application.TAG, "Caller.doGet [cached] " + url); return data; } } URI encodedUri = null; HttpGet httpGet = null; try { encodedUri = new URI(url); httpGet = new HttpGet(encodedUri); } catch (URISyntaxException e1) { // at least try to remove spaces String encodedUrl = url.replace(' ', '+'); httpGet = new HttpGet(encodedUrl); e1.printStackTrace(); } // initialize HTTP GET request objects HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; try { // execute request try { httpResponse = httpClient.execute(httpGet); } catch (UnknownHostException e) { throw new WSError("Unable to access " + e.getLocalizedMessage()); } catch (SocketException e) { throw new WSError(e.getLocalizedMessage()); } // request data HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { InputStream inputStream = httpEntity.getContent(); data = convertStreamToString(inputStream); // cache the result if (requestCache != null) { requestCache.put(url, data); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d(Dian1Application.TAG, "Caller.doGet " + url); return data; }
From source file:siir.es.adbWireless.AutoConnectTask.java
@Override protected Void doInBackground(Void... params) { try {//from w w w .j av a 2s . c om URI url = new URI(this.url); HttpClient httpClient = new DefaultHttpClient(); HttpGet method = new HttpGet(url); httpClient.execute(method); } catch (Exception e) { Debug.error("ERROR doInBackground()", e); } return null; }
From source file:net.eusashead.hateoas.header.impl.LocationHeaderImpl.java
public LocationHeaderImpl(String uri) { try {//from ww w. j av a2 s .co m this.value = new URI(uri); } catch (URISyntaxException e) { throw new IllegalArgumentException(String.format("URI %s has incorrect syntax.", uri)); } }
From source file:com.teleca.jamendo.api.util.Caller.java
/** * Performs HTTP GET using Apache HTTP Client v 4 * //from ww w . j a v a 2 s.c o m * @param url * @return * @throws WSError */ public static String doGet(String url) throws WSError { String data = null; if (requestCache != null) { data = requestCache.get(url); if (data != null) { Log.d(JamendoApplication.TAG, "Caller.doGet [cached] " + url); return data; } } URI encodedUri = null; HttpGet httpGet = null; try { encodedUri = new URI(url); httpGet = new HttpGet(encodedUri); } catch (URISyntaxException e1) { // at least try to remove spaces String encodedUrl = url.replace(' ', '+'); httpGet = new HttpGet(encodedUrl); e1.printStackTrace(); } // initialize HTTP GET request objects HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; try { // execute request try { httpResponse = httpClient.execute(httpGet); } catch (UnknownHostException e) { throw new WSError("Unable to access " + e.getLocalizedMessage()); } catch (SocketException e) { throw new WSError(e.getLocalizedMessage()); } // request data HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { InputStream inputStream = httpEntity.getContent(); data = convertStreamToString(inputStream); // cache the result if (requestCache != null) { requestCache.put(url, data); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d(JamendoApplication.TAG, "Caller.doGet " + url); return data; }
From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java
public static IInternalNameNode loadNameNodeFromConfig(Configuration config, String nameNodeTypeKey, String nameNodeLocationKey) throws ClassNotFoundException, ReflectiveOperationException { // retrieve name node type Class<? extends IInternalNameNode> nameNodeType; {/*from w w w.j a v a2 s. co m*/ String nameNodeTypeString = config.getString(nameNodeTypeKey); if (nameNodeTypeString == null) { throw new ConversionException("Config must contain key " + nameNodeTypeKey); } try { nameNodeType = NameNodeProvider.loadNameNodeType(nameNodeTypeString); } catch (ReflectiveOperationException e) { throw new ConversionException( "Config key " + nameNodeTypeKey + " has invalid format - " + e.getMessage()); } } // retrieve name node location URI nameNodeLocation; { String nameNodeLocationString = config.getString(nameNodeLocationKey); if (nameNodeLocationString == null) { throw new ConversionException("Config must contain key " + nameNodeLocationKey); } try { nameNodeLocation = new URI(nameNodeLocationString); } catch (URISyntaxException e) { throw new ConversionException( "Config key " + nameNodeLocationKey + " has invalid format - " + e.getMessage()); } } return loadNameNode(nameNodeType, nameNodeLocation); }
From source file:io.cloudslang.content.httpclient.build.RequestBuilderTest.java
@Test(expected = IllegalArgumentException.class) public void testNoMethod() throws URISyntaxException { new io.cloudslang.content.httpclient.build.RequestBuilder().setUri(new URI("/")).build(); }
From source file:com.tag.Hyperlink.java
public Hyperlink(String text, String uri) { super(text);/* w ww . java 2 s. c o m*/ try { setUri(new URI(uri)); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } init(); }
From source file:net.modelbased.proasense.storage.registry.RestRequest.java
public static boolean isSensorRegistered(Sensor sensor) { URI target = null;// ww w . j ava 2 s . co m try { target = new URI(sensor.getUri().toString() + SENSOR_PATH + "/" + sensor.getName()); } catch (URISyntaxException e) { e.printStackTrace(); } HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(target); StatusLine status = null; try { status = client.execute(request).getStatusLine(); } catch (Exception e) { } if (status.getStatusCode() == 200) { return true; } return false; }