001package org.kuali.ole.loaders.common; 002 003import com.sun.jersey.api.client.Client; 004import com.sun.jersey.api.client.ClientResponse; 005import com.sun.jersey.api.client.WebResource; 006import org.apache.http.HttpResponse; 007import org.apache.http.client.methods.HttpGet; 008import org.apache.http.client.methods.HttpPost; 009import org.apache.http.impl.client.DefaultHttpClient; 010 011import java.io.BufferedReader; 012import java.io.InputStreamReader; 013 014/** 015 * Created by sheiksalahudeenm on 3/5/15. 016 */ 017public class RestClient { 018 019 public static String jerseryClientGet(String url){ 020 try { 021 Client client = Client.create(); 022 WebResource webResource = client 023 .resource(url); 024 ClientResponse response = webResource.accept("application/json") 025 .get(ClientResponse.class); 026 String output = response.getEntity(String.class); 027 return output; 028 029 } catch (Exception e) { 030 e.printStackTrace(); 031 } 032 return null; 033 } 034 035 public static String jerseryClientPost(String url, String requestContent) { 036 try { 037 Client client = Client.create(); 038 WebResource webResource = client 039 .resource(url); 040 ClientResponse response = webResource.type("application/json") 041 .post(ClientResponse.class, requestContent); 042 String output = response.getEntity(String.class); 043 return output; 044 045 } catch (Exception e) { 046 e.printStackTrace(); 047 } 048 return null; 049 } 050 051 public static String jerseryClientPut(String url, String requestContent) { 052 try { 053 Client client = Client.create(); 054 WebResource webResource = client 055 .resource(url); 056 ClientResponse response = webResource.type("application/json") 057 .put(ClientResponse.class, requestContent); 058 String output = response.getEntity(String.class); 059 return output; 060 061 } catch (Exception e) { 062 e.printStackTrace(); 063 } 064 return null; 065 } 066 067}