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