1 package org.kuali.ole.loaders.common;
2
3 import com.sun.jersey.api.client.Client;
4 import com.sun.jersey.api.client.ClientResponse;
5 import com.sun.jersey.api.client.WebResource;
6 import org.apache.http.HttpResponse;
7 import org.apache.http.client.methods.HttpGet;
8 import org.apache.http.client.methods.HttpPost;
9 import org.apache.http.impl.client.DefaultHttpClient;
10
11 import java.io.BufferedReader;
12 import java.io.InputStreamReader;
13
14
15
16
17 public class RestClient {
18
19 public static String jerseryClientGet(String url){
20 try {
21 Client client = Client.create();
22 WebResource webResource = client
23 .resource(url);
24 ClientResponse response = webResource.accept("application/json")
25 .get(ClientResponse.class);
26 String output = response.getEntity(String.class);
27 return output;
28
29 } catch (Exception e) {
30 e.printStackTrace();
31 }
32 return null;
33 }
34
35 public static String jerseryClientPost(String url, String requestContent) {
36 try {
37 Client client = Client.create();
38 WebResource webResource = client
39 .resource(url);
40 ClientResponse response = webResource.type("application/json")
41 .post(ClientResponse.class, requestContent);
42 String output = response.getEntity(String.class);
43 return output;
44
45 } catch (Exception e) {
46 e.printStackTrace();
47 }
48 return null;
49 }
50
51 public static String jerseryClientPut(String url, String requestContent) {
52 try {
53 Client client = Client.create();
54 WebResource webResource = client
55 .resource(url);
56 ClientResponse response = webResource.type("application/json")
57 .put(ClientResponse.class, requestContent);
58 String output = response.getEntity(String.class);
59 return output;
60
61 } catch (Exception e) {
62 e.printStackTrace();
63 }
64 return null;
65 }
66
67 }