List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.UserImpl.java
/** * this method lists all user in salesforce.com and returns a list of all user details. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap /*from w ww . jav a 2 s . c om*/ */ private Map<String, String> list() { Map<String, String> outMap = new HashMap<String, String>(); final String SALESFORCE_LIST_USER_URL = args.get(INSTANCE_URL) + "/services/data/v25.0/query/?q=SELECT+Username+FROM+User"; Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); TransportTools tst = new TransportTools(SALESFORCE_LIST_USER_URL, null, header); try { String responseBody = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, responseBody); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return outMap; }
From source file:es.eucm.eadventure.editor.plugin.vignette.ServerProxy.java
public String getJson() { String json = null;/*from w w w. j a v a2 s . co m*/ try { HttpClient httpclient = getProxiedHttpClient(); String url = serviceURL + "/load.php?" + "m=" + getMac() + "&f=" + userPath; HttpGet hg = new HttpGet(url); HttpResponse response; response = httpclient.execute(hg); if (Integer.toString(response.getStatusLine().getStatusCode()).startsWith("2")) { HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); StringWriter strWriter = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { strWriter.write(buffer, 0, n); } } finally { instream.close(); } json = strWriter.toString(); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return json; }
From source file:net.dataninja.oracle.client.DataNinjaHttpClient.java
public String fetchSmartSentimentRdf(String text, String url, int maxSize) { String output = ""; try {//w ww . j av a 2s . co m HttpClient client = getHttpClient(); HttpPost postRequest = new HttpPost(config.getApiUrl() + "/smartsentiment/tagentityrdf"); DataNinjaInput dataNinjaInput = new DataNinjaInput(); dataNinjaInput.setText(text); dataNinjaInput.setUrl(url); dataNinjaInput.setMax_size(maxSize); System.out.println(dataNinjaInput.toJsonString()); StringEntity entity = new StringEntity(dataNinjaInput.toJsonString()); entity.setContentType("application/json"); postRequest.setEntity(entity); // Add additional header to postRequest which accepts application/json data postRequest.addHeader("accept", "application/json"); postRequest.addHeader("X-Mashape-Key", config.getMashapeKey()); System.out.println(postRequest.toString()); // Execute the POST request and catch response HttpResponse response = client.execute(postRequest); // Check for HTTP response code: 200 = success if (response.getStatusLine().getStatusCode() != 200) { System.out.printf(response.toString()); throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } // Get-Capture Complete the RDF body response BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); StringBuffer sb = new StringBuffer(); String line; // Simply iterate through RDF response and show on console. while ((line = br.readLine()) != null) { sb.append(line).append("\n"); // System.out.println(line); } output = sb.toString(); } catch (ClientProtocolException e) { System.out.println("Problem fetching RDF content"); e.printStackTrace(); } catch (IOException e) { System.out.println("Problem fetching RDF content"); e.printStackTrace(); } catch (UnrecoverableKeyException e) { System.out.println("Problem fetching RDF content"); e.printStackTrace(); } catch (NoSuchAlgorithmException e) { System.out.println("Problem fetching RDF content"); e.printStackTrace(); } catch (KeyStoreException e) { System.out.println("Problem fetching RDF content"); e.printStackTrace(); } catch (KeyManagementException e) { System.out.println("Problem fetching RDF content"); e.printStackTrace(); } return output; }
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.ProductImpl.java
/** * this method creates an protuct in salesforce.com and returns that product id. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap /*from w w w .j ava 2s .c om*/ */ private Map<String, String> create() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CREATE_PRODUCT_URL = args.get(INSTANCE_URL) + SALESFORCE_PRODUCT_URL; Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); Map<String, Object> userAttrMap = new HashMap<String, Object>(); userAttrMap.put("Name", args.get(NAME)); userAttrMap.put("ProductCode", args.get(PRODUCT_CODE)); userAttrMap.put("Description", args.get(DESCRIPTION)); TransportTools tst = new TransportTools(SALESFORCE_CREATE_PRODUCT_URL, null, header); Gson obj = new GsonBuilder().setPrettyPrinting().create(); tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap)); String responseBody = null; TransportResponse response = null; try { response = TransportMachinery.post(tst); responseBody = response.entityToString(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } outMap.put(OUTPUT, responseBody); return outMap; }
From source file:com.nagazuka.mobile.android.goedkooptanken.service.impl.ZukaService.java
public String upload(PlacesParams params) throws NetworkException { String response = ""; try {//from www . ja v a 2 s. c o m HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(constructURL(params)); //Log.d(TAG, "<< HTTP Request: " + request.toString()); ResponseHandler<String> handler = new BasicResponseHandler(); response = httpClient.execute(request, handler); //Log.d(TAG, "<< HTTP Response: " + response); httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException c) { c.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return response; }
From source file:com.liato.bankdroid.banking.banks.TestBank.java
@Override public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException { super.updateTransactions(account, urlopen); //No transaction history for loans, funds and credit cards. int accType = account.getType(); if (accType == Account.LOANS || accType == Account.FUNDS || accType == Account.CCARD) return;//from w w w . j a v a2 s .co m String response = null; Matcher matcher; try { response = urlopen.open( "http://www.nullbyte.eu/bankdroid/tests/testbank/transactions_" + account.getId() + ".htm"); matcher = reTransactions.matcher(response); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); while (matcher.find()) { transactions.add(new Transaction(Html.fromHtml(matcher.group(1)).toString().trim(), Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3)))); } account.setTransactions(transactions); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.liato.bankdroid.banking.banks.Avanza.java
@Override public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException { super.updateTransactions(account, urlopen); String response = null;//from www.j av a 2 s . c om Matcher matcher; try { response = urlopen.open("https://www.avanza.se/aza/depa/depa.jsp?depotnr=" + account.getId()); matcher = reTransactions.matcher(response); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); String strDate = null; Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); strDate = sdf.format(cal.getTime()); while (matcher.find()) { transactions.add(new Transaction(strDate, Html.fromHtml(matcher.group(1)).toString().trim(), Helpers.parseBalance(matcher.group(2)))); } account.setTransactions(transactions); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:es.curso.android.arduino.Main.java
private String doPetition(String url) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response;/* ww w .j ava 2 s . co m*/ try { response = httpclient.execute(new HttpGet(url)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); String responseString = out.toString(); Log.d("Main", responseString); return responseString; } else { //Closes the connection. response.getEntity().getContent().close(); return null; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:fr.forexperts.service.DataService.java
public String[] findStockName(String query) { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); try {//from w ww . jav a 2 s. c o m HttpGet httpGet = new HttpGet( "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=" + URLEncoder.encode(query, "UTF-8") + "®ion=US&lang=en-US&callback=" + "YAHOO.util.ScriptNodeDataSource.callbacks"); HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return parseJson(builder.toString()); }
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.EventImpl.java
/** * this method creates an event in salesforce.com and returns that event id. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap //from www. j a va 2 s.c om */ private Map<String, String> create() { final String SALESFORCE_CREATE_EVENT_URL = args.get(INSTANCE_URL) + SALESFORCE_EVENT_URL; Map<String, String> outMap = new HashMap<>(); Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); Map<String, Object> userAttrMap = new HashMap<String, Object>(); userAttrMap.put(S_SUBJECT, args.get(SUBJECT)); userAttrMap.put(S_STARTDATETIME, datetime.parse(args.get(START_DATE))); userAttrMap.put(S_ENDDATETIME, datetime.parse(args.get(END_DATE))); GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter()); Gson obj = gson.setPrettyPrinting().create(); TransportTools tst = new TransportTools(SALESFORCE_CREATE_EVENT_URL, null, header); tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap)); TransportResponse response = null; try { String responseBody = TransportMachinery.post(tst).entityToString(); outMap.put(OUTPUT, responseBody); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }