List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:revServTest.IoTTestForPOST.java
public String testPost(StringEntity input) { // String result; HttpResponse response = null;/*from ww w . j av a2 s . com*/ try { DefaultHttpClient httpClient = new DefaultHttpClient(); // HttpPost postRequest = new // HttpPost("http://pc-drotondi7:8080/REVOCATIONSERVICETEST/revocation"); HttpPost postRequest = new HttpPost("http://localhost:2222/revocation"); // StringEntity input = new StringEntity( // readFileAsString("C:/Users/andrisani/Desktop/firstRevocation.xml")); // StringEntity input = new // StringEntity(readFileAsString("C:/Users/andrisani/Desktop/secondRevocation.xml")); // StringEntity input = new // StringEntity(readFileAsString("C:/Users/andrisani/Desktop/secondRevocation.xml")); // StringEntity input = new // StringEntity(readFileAsString("C:/Users/andrisani/Desktop/pendingRevocation.xml")); input.setContentType("application/xml"); postRequest.setEntity(input); response = httpClient.execute(postRequest); if (response.getStatusLine().getStatusCode() != 409 && response.getStatusLine().getStatusCode() != 201 && response.getStatusLine().getStatusCode() != 400 && response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 404 && response.getStatusLine().getStatusCode() != 500) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // if (response.getStatusLine().getStatusCode() == 409 || response.getStatusLine().getStatusCode() == 201 || response.getStatusLine().getStatusCode() == 400 // || response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 404 || response.getStatusLine().getStatusCode() == 500) { // // result = RevocationOutCome.code; // // } else { // String res = Integer.toString(response.getStatusLine().getStatusCode()); // result = res; // } // return result; return RevocationOutComePost.code; }
From source file:com.google.android.panoramio.BitmapUtilsTask.java
/** * The system calls this to perform work in a worker thread and delivers * it the parameters given to AsyncTask.execute() *//* w w w .j a v a2s.c o m*/ @Override protected Bitmap doInBackground(Object... item) { try { if (item[1].toString().equals("thumb")) return loadThumbnail(item[0].toString()); else if (item[1].toString().equals("load")) { loadBitmap(item[0].toString(), item[2]); return null; } else return getBitmap(item[0].toString(), item[2]); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:requestToApi.java
public String send(StringEntity Input, String URL) { String output2 = ""; try {/* w ww. jav a2s .c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(URL); StringEntity input = Input; input.setContentType("application/json"); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { output2 = output; System.out.println(output); } httpClient.getConnectionManager().shutdown(); return output2; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return output2; }
From source file:jp.aegif.nemaki.cmis.aspect.query.solr.SolrUtil.java
public String getSolrUrl() { String protocol = propertyManager.readValue(PropertyKey.SOLR_PROTOCOL); String host = propertyManager.readValue(PropertyKey.SOLR_HOST); int port = Integer.valueOf(propertyManager.readValue(PropertyKey.SOLR_PORT)); String context = propertyManager.readValue(PropertyKey.SOLR_CONTEXT); String url = null;/*from w w w . j a v a2 s. co m*/ try { URL _url = new URL(protocol, host, port, ""); url = _url.toString() + "/" + context + "/"; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } log.info("Solr URL:" + url); return url; }
From source file:ca.etsmtl.applets.etsmobile.api.SignetBackgroundThread.java
@SuppressWarnings("unchecked") public T fetchObject() { T object = null;// w w w.ja v a 2 s .c o m try { final StringBuilder sb = new StringBuilder(); sb.append(urlStr); sb.append("/"); sb.append(action); final Gson gson = new Gson(); final String bodyParamsString = gson.toJson(bodyParams); final URL url = new URL(sb.toString()); final URLConnection conn = url.openConnection(); conn.addRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setDoOutput(true); final OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(bodyParamsString); wr.flush(); final StringWriter writer = new StringWriter(); final InputStream in = conn.getInputStream(); IOUtils.copy(in, writer); in.close(); wr.close(); final String jsonString = writer.toString(); JSONObject jsonObject; jsonObject = new JSONObject(jsonString); JSONObject jsonRootArray; jsonRootArray = jsonObject.getJSONObject("d"); object = (T) gson.fromJson(jsonRootArray.toString(), typeOfClass); android.util.Log.d("JSON", jsonRootArray.toString()); } catch (final MalformedURLException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final JSONException e) { e.printStackTrace(); } return object; }
From source file:cm.aptoide.pt.util.NetworkUtils.java
public int checkServerConnection(final String string, final String username, final String password) { try {//w ww . j a v a 2 s .c o m HttpURLConnection client = (HttpURLConnection) new URL(string + "info.xml").openConnection(); if (username != null && password != null) { String basicAuth = "Basic " + new String(Base64.encode((username + ":" + password).getBytes(), Base64.NO_WRAP)); client.setRequestProperty("Authorization", basicAuth); } client.setConnectTimeout(TIME_OUT); client.setReadTimeout(TIME_OUT); if (ApplicationAptoide.DEBUG_MODE) Log.i("Aptoide-NetworkUtils-checkServerConnection", "Checking on: " + client.getURL().toString()); if (client.getContentType().equals("application/xml")) { return 0; } else { return client.getResponseCode(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return -1; }
From source file:com.sabre.hack.travelachievementgame.DSCommHandler.java
public String getAuthToken(String apiEndPoint, String encodedCliAndSecret) { //receives : apiEndPoint (https://api.test.sabre.com) //encodedCliAndSecret : base64Encode( base64Encode(V1:[user]:[group]:[domain]) + ":" + base64Encode([secret]) ) String strRet = null;/*from w w w .j a v a2 s.c o m*/ try { URL urlConn = new URL(apiEndPoint + "/v1/auth/token"); URLConnection conn = urlConn.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Authorization", "Basic " + encodedCliAndSecret); conn.setRequestProperty("Accept", "application/json"); //send request DataOutputStream dataOut = new DataOutputStream(conn.getOutputStream()); dataOut.writeBytes("grant_type=client_credentials"); dataOut.flush(); dataOut.close(); //get response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String strChunk = ""; StringBuilder sb = new StringBuilder(); while (null != ((strChunk = rd.readLine()))) sb.append(strChunk); //parse the token JSONObject respParser = new JSONObject(sb.toString()); strRet = respParser.getString("access_token"); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return strRet; }
From source file:gov.nih.nci.nbia.StandaloneDMV1.java
protected List<SeriesData> getSeriesInfo() { List<String> seriesInfo = null; try {/*from w w w .j av a2 s.c om*/ seriesInfo = connectAndReadFromURL(new URL(serverUrl), fileLoc + basketId); } catch (MalformedURLException e1) { e1.printStackTrace(); } String[] strResult = new String[seriesInfo.size()]; seriesInfo.toArray(strResult); return JnlpArgumentsParser.parse(strResult); }
From source file:edu.ucsb.nceas.metacat.lsid.LSIDDataLookup.java
public InputStream lsidData(LSID lsid) throws LSIDServerException { String ns = lsid.getNamespace(); String id = lsid.getObject(); String ver = lsid.getRevision(); InputStream docStream = null; // example metacat query // http://metacat.nceas.ucsb.edu/knb/metacat?action=read&qformat=xml&docid=knb-lter-gce.109.6 ///* w w w . j a v a 2s .c o m*/ ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid"); String theServer = rb.getString("metacatserver"); logger.debug("the server is " + theServer); String url = theServer + "?action=read&qformat=xml&docid="; url = url + ns + "." + id + "." + ver; try { URL theDoc = new URL(url); docStream = theDoc.openStream(); } catch (MalformedURLException mue) { logger.error("MalformedURLException in LSIDDataLookup: " + mue); mue.printStackTrace(); } catch (IOException ioe) { logger.error("IOException in LSIDDataLookup: " + ioe); ioe.printStackTrace(); } return docStream; }
From source file:icevaluation.GetWikiURL.java
public String getWikiResults(String searchText, String bingAPIKey) { String search_results = null; //update key use by incrementing key use Integer n = keyMap.get(bingAPIKey); if (n == null) { n = 1;//from w ww. ja v a 2s.co m } else { n = n + 1; } keyMap.put(bingAPIKey, n); searchText = searchText.replaceAll(" ", "%20"); String accountKey = bingAPIKey; byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes()); String accountKeyEnc = new String(accountKeyBytes); URL url; try { url = new URL("https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27Web%27&Query=%27" + searchText + "%27&$format=JSON"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Basic " + accountKeyEnc); //conn.addRequestProperty(accountKeyEnc, "Mozilla/4.76"); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String output = null; //System.out.println("Output from Server .... \n"); //write json to string sb if ((output = br.readLine()) != null) { search_results = output; } conn.disconnect(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return search_results; }