List of usage examples for java.net URISyntaxException printStackTrace
public void printStackTrace()
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String deleteSensor(Uri uri, Sensor sensor) throws RequestErrorException { URI target;/*from ww w.j a v a 2 s. c o m*/ try { target = new URI(uri.toString() + SENSOR_PATH + "/" + sensor.getName()); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestErrorException(e.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpDelete request = new HttpDelete(target); request.setHeader("Content-type", "application/json"); String response = null; try { response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } return response; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static boolean isSensorRegistered(Sensor sensor) throws RequestErrorException { URI target;//from w w w . j a va2s . co m try { target = new URI(sensor.getUri().toString() + SENSOR_PATH + "/" + sensor.getName()); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestErrorException(e.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(target); StatusLine status; try { status = client.execute(request).getStatusLine(); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (status.getStatusCode() == 200) { return true; } return false; }
From source file:org.epop.dataprovider.googlescholar.GoogleScholarGetterFromId.java
static List<Literature> getFromId(String userId) { // http://scholar.google.it/citations?user=q21xxm4AAAAJ&pagesize=100 List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("user", userId)); qparams.add(new BasicNameValuePair("pagesize", "100")); URI uri;// w w w . ja v a 2 s.com String responseBody = null; try { uri = URIUtils.createURI("http", GOOGLE_SCHOLAR, -1, "", URLEncodedUtils.format(qparams, "UTF-8"), null); uri = new URI(uri.toString().replace("citations/?", "citations?")); HttpGet httpget = new HttpGet(uri); System.out.println(httpget.getURI()); HttpClient httpclient = new DefaultHttpClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); responseBody = httpclient.execute(httpget, responseHandler); //System.out.println(responseBody); int counter = 1; String newResponseBody = responseBody; while (newResponseBody.contains("class=\"cit-dark-link\">Next ></a>")) { URI newUri = new URI(uri.toString() + "&cstart=" + counter * 100); httpget = new HttpGet(newUri); System.out.println(httpget.getURI()); httpclient = new DefaultHttpClient(); newResponseBody = httpclient.execute(httpget, responseHandler); //System.out.println(newResponseBody); responseBody = responseBody + newResponseBody; counter++; } } 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 the result as string return parsePage(new StringReader(responseBody)); }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static boolean isCompositeRegistered(Composite composite) throws RequestErrorException { URI target;//from www.jav a 2 s. c o m try { target = new URI(composite.getUri().toString() + COMPOSITE_PATH + "/" + composite.getName()); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(target); StatusLine status; try { status = client.execute(request).getStatusLine(); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (status.getStatusCode() == 200) { return true; } return false; }
From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java
/** * ?GET??//from w w w.j av a2s . c o m * * @param url * @return */ public static HttpGet getGetMethod(String url) { URI uri = null; try { URL _url = new URL(url); uri = new URI(_url.getProtocol(), _url.getHost(), _url.getPath(), _url.getQuery(), null); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpGet pmethod = new HttpGet(uri); // ?? pmethod.addHeader("Connection", "keep-alive"); pmethod.addHeader("Cache-Control", "max-age=0"); pmethod.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); pmethod.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/;q=0.8"); return pmethod; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String postComposite(Composite composite) throws RequestErrorException { String content = JsonPrinter.compositeToJson(composite); URI target;//w w w . j av a2 s. c o m try { target = new URI(composite.getUri().toString() + COMPOSITE_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(content); seContent.setContentType("text/json"); request.setEntity(seContent); response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } return response; }
From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java
/** * ?post??//from w w w.j a v a 2s. c om * * @param url * @return */ public static HttpPost getPostMethod(String url) { URI uri = null; try { URL _url = new URL(url); uri = new URI(_url.getProtocol(), _url.getHost(), _url.getPath(), _url.getQuery(), null); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpPost pmethod = new HttpPost(uri); // ?? pmethod.addHeader("Connection", "keep-alive"); pmethod.addHeader("Accept", "*/*"); pmethod.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); pmethod.addHeader("Host", "mp.weixin.qq.com"); pmethod.addHeader("X-Requested-With", "XMLHttpRequest"); pmethod.addHeader("Cache-Control", "max-age=0"); pmethod.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); return pmethod; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String putData(Uri uri, String data) throws RequestErrorException { URI target;/*from w w w .j ava 2 s . c om*/ try { target = new URI(uri.toString() + DISPATCHER_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPut request = new HttpPut(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(data); seContent.setContentType("text/json"); request.setEntity(seContent); response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (response.trim().length() > 2) { throw new RequestErrorException("Sensor not registred: " + response); } return response; }
From source file:org.kalypsodeegree_impl.model.feature.FeatureLinkUtils.java
public static String findLinkPath(final Feature toLink, final GMLWorkspace sourceWorkspace) { final String id = toLink.getId(); final GMLWorkspace linkedWorkspace = toLink.getWorkspace(); /* Internal link, no uri */ if (linkedWorkspace == sourceWorkspace) return id; final URL targetContext = linkedWorkspace.getContext(); final URL sourceContext = sourceWorkspace.getContext(); String path = null;//from w w w. j ava 2 s.com try { final URI targetURI = targetContext.toURI(); final URI sourceURI = sourceContext.toURI(); final URI relativeURI = URIUtil.makeRelative(targetURI, sourceURI); path = relativeURI.toString(); } catch (final URISyntaxException e) { // TODO: do we need this fallback? e.printStackTrace(); path = targetContext.toString(); } final StringBuilder s = new StringBuilder(path.length() + id.length() + 1); s.append(path); s.append('#'); s.append(id); return s.toString(); }
From source file:eu.planets_project.tb.gui.backing.data.DigitalObjectInspector.java
/** * There are some characters that are allowed in URLs and should not be escaped as %xx * e.g. blanks. These are not allowed in URIs. * This method uses the URI constructor to fix those escapings. * @param uri//from w ww. ja v a 2 s .c o m * @return */ public static URI uriEncoder(String uri) { if (uri == null || uri.length() == 0) return null; try { URI nuri = new URI("planets", uri.replaceFirst("planets:", ""), null); return nuri; } catch (URISyntaxException e) { e.printStackTrace(); return null; } }