List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:org.kuali.kfs.rest.AccountingPeriodCloseJob.java
public static void main(String[] args) { try {//from ww w . ja va 2s .c om DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost request = new HttpPost("http://localhost:8080/kfs-dev/coa/accounting_periods/close"); request.addHeader("accept", "application/json"); request.addHeader("content-type", "application/json"); request.addHeader("authorization", "NSA_this_is_for_you"); StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("\"description\":\"Document: The Next Generation\","); sb.append("\"universityFiscalYear\": 2016,"); sb.append("\"universityFiscalPeriodCode\": \"03\""); sb.append("}"); StringEntity data = new StringEntity(sb.toString()); request.setEntity(data); HttpResponse response = httpClient.execute(request); System.out.println("Status Code: " + response.getStatusLine().getStatusCode()); 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) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:AddBookmark.java
/** * @param args//from ww w . j a v a 2s . co m * @throws ParseException */ public static void main(final String[] args) throws ParseException { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI to add a bookmark on a particular post id final BookmarkResponse bookmarkResponse = api.addBookmark(314694); // print out the info returned by the Bookmarks API System.out.println("Result: " + bookmarkResponse.getResult()); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { e.printStackTrace(); } }
From source file:RemoveBookmark.java
/** * @param args/* www.ja v a2s. com*/ * @throws ParseException */ public static void main(final String[] args) throws ParseException { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI for to remove a bookmark on a particular post id final BookmarkResponse bookmarkResponse = api.removeBookmark(314694); // print out the info returned by the Bookmarks API System.out.println("Result: " + bookmarkResponse.getResult()); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { e.printStackTrace(); } }
From source file:GetAccountDetails.java
/** * @param args/* w ww .j a v a 2 s .c o m*/ */ public static void main(final String[] args) { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI for our user's account information final AccountDetailsResponse accountInfo = api.getAccountInfo(); // print out the info returned by the Account API System.out.println("User Name : " + accountInfo.getUserName()); System.out.println("User ID : " + accountInfo.getUserID()); System.out.println("api requests in last 24 hrs : " + accountInfo.getApiDailyRate()); System.out.println("nzb downloads in last 24 hrs : " + accountInfo.getApiDailyDownload()); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { e.printStackTrace(); } }
From source file:GetPostDetails.java
/** * @param args/* w w w . ja v a 2s.co m*/ * @throws ParseException */ public static void main(final String[] args) throws ParseException { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI for details about a particular post id final PostDetailsResponse postDetails = api.getPostDetails(314694); // print out some of the info returned by the Post Details API (see other methods attached to the postDetails object) System.out.println("Nzb Name : " + postDetails.getNzbName()); System.out.println("\tCategory : " + postDetails.getCategory()); System.out.println("\tRegion : " + postDetails.getRegionCode()); System.out.println("\tAge : " + postDetails.getAgeInDays()); System.out.println("\tIndex Date : " + postDetails.getDateIndexed()); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { e.printStackTrace(); } }
From source file:GetDirectDownload.java
/** * @param args/*from w w w . j a v a 2 s. co m*/ * @throws ParseException */ public static void main(final String[] args) throws ParseException { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI for a direct download of a particular post id final DirectDownloadResponse directDownload = api.getDirectDownload(314694); // save the nzb file to disk final String fileName = directDownload.getSuggestedFileName(); final BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); out.write(directDownload.getNzbFileContents()); out.close(); System.out.println("Nzb File Saved As: " + fileName); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { e.printStackTrace(); } }
From source file:com.anteam.demo.httpclient.PostDemo.java
public static void main(String[] args) { StringEntity stringEntity = new StringEntity("this is the log2.", ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost("http://127.0.0.1:9000"); post.setEntity(stringEntity);//from w w w . java2s . co m HttpClient httpclient = new DefaultHttpClient(); // Execute the request HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } httpclient.getConnectionManager().shutdown(); } }
From source file:com.anteam.demo.logback.PostDemo.java
public static void main(String[] args) { StringEntity stringEntity = new StringEntity("this is the log2.", ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost("http://10.16.0.207:9000"); post.setEntity(stringEntity);// ww w . ja v a 2 s.c om HttpClient httpclient = new DefaultHttpClient(); // Execute the request HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } httpclient.getConnectionManager().shutdown(); } }
From source file:nl.raja.niruraji.pa.PlayGround.java
public static void main(String[] args) { try {/*from w w w . j a va2 s . c om*/ // create HTTP Client HttpClient httpClient = HttpClientBuilder.create().build(); String url = "http://buienradar.nl/Json/GetTwentyFourHourForecast?geolocationid=2751773"; // Create new getRequest with below mentioned URL HttpGet getRequest = new HttpGet(url); // Add additional header to getRequest which accepts application/xml data //getRequest.addHeader("accept", "application/xml"); // Execute your request and catch response HttpResponse response = httpClient.execute(getRequest); // Check for HTTP response code: 200 = success if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } String result = EntityUtils.toString(response.getEntity()); JSONObject myObject = new JSONObject(result); // Get-Capture Complete application/xml body response BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("============Output:============"); // Simply iterate through XML response and show on console. while ((output = br.readLine()) != null) { System.out.println(output); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.openeclass.EclassMobile.java
public static void main(String[] args) { try {/* w w w . j a v a 2s .c om*/ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("https://myeclass/modules/mobile/mlogin.php"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("uname", mUsername)); nvps.add(new BasicNameValuePair("pass", mPassword)); httppost.setEntity(new UrlEncodedFormEntity(nvps)); System.out.println("twra tha kanei add"); System.out.println("prin to response"); HttpResponse response = httpclient.execute(httppost); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) System.out.println("Invalid response from server: " + status.toString()); System.out.println("meta to response"); Header[] head = response.getAllHeaders(); for (int i = 0; i < head.length; i++) System.out.println("to head exei " + head[i]); System.out.println("Login form get: " + response.getStatusLine()); HttpEntity entity = response.getEntity(); InputStream ips = entity.getContent(); BufferedReader buf = new BufferedReader(new InputStreamReader(ips, "UTF-8"), 1024); StringBuilder sb = new StringBuilder(); String s = ""; while ((s = buf.readLine()) != null) { sb.append(s); } System.out.println("to sb einai " + sb.toString()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }