gt: 		return restPost(url, null, data, requestFlavor, 15000);
context: package com.dotcms.osgi.restClient.viewtool;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.URLEncoder;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.io.IOException;
  
  import org.apache.velocity.tools.view.ImportSupport;
  import org.apache.velocity.tools.view.tools.ViewTool;
  
  import com.dotcms.repackage.org.apache.commons.codec.binary.Base64;
  import com.dotcms.repackage.org.apache.http.HttpResponse;
  import com.dotcms.repackage.org.apache.http.NameValuePair;
  import com.dotcms.repackage.org.apache.http.client.HttpClient;
  import com.dotcms.repackage.org.apache.http.client.entity.UrlEncodedFormEntity;
  import com.dotcms.repackage.org.apache.http.entity.StringEntity;
  import com.dotcms.repackage.org.apache.http.client.utils.URIBuilder;
  import com.dotcms.repackage.org.apache.http.client.methods.HttpGet;
  import com.dotcms.repackage.org.apache.http.client.methods.HttpPost;
  import com.dotcms.repackage.org.apache.http.client.methods.HttpPut;
  import com.dotcms.repackage.org.apache.http.client.methods.HttpPatch;
  import com.dotcms.repackage.org.apache.http.impl.client.DefaultHttpClient;
  import com.dotcms.repackage.org.apache.http.message.BasicNameValuePair;
  import com.dotcms.repackage.org.apache.http.params.BasicHttpParams;
  import com.dotcms.repackage.org.apache.http.params.HttpConnectionParams;
  import com.dotcms.repackage.org.apache.http.params.HttpParams;
  import com.dotmarketing.util.Logger;
  import com.dotmarketing.util.json.JSONObject;
  
  
  public class rest2Json extends ImportSupport implements ViewTool {
  
  	public void init(Object obj) {
  
  	}
  
  	private JSONObject restGet(String url, Map<String, String> basicAuth, Map<String, String> data, int timeout) throws Exception {
  
  		final HttpParams httpParams = new BasicHttpParams();
  		HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
  		HttpClient client = new DefaultHttpClient(httpParams);
  
  		URIBuilder uri = new URIBuilder(url);
  		
  		if(data != null && !data.isEmpty()) { 
  			for (String key : data.keySet()) {
  				if(key != null && !key.isEmpty() && data.get(key) != null && !data.get(key).isEmpty()) {
  					uri.setParameter(key, data.get(key));
  				}
  			}
  		}
  		
  		HttpGet req = new HttpGet(uri.toString());
  
  		if(basicAuth != null && !basicAuth.isEmpty()) { 
  			String cred = basicAuth.get("username") + ":" + basicAuth.get("password");
  			cred = Base64.encodeBase64String(cred.getBytes());
  			req.addHeader("Authorization", "Basic " + cred);
  		}
  
  		HttpResponse response = client.execute(req);
  
  		try {
  			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  
  			StringBuffer result = new StringBuffer();
  			String line = "";
  			while ((line = rd.readLine()) != null) {
  				result.append(line);
  			}
  			return new JSONObject(result.toString());
  		} catch (IOException e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		} catch (Exception e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		}
  		return null;
  
  	}
  
  	private JSONObject restPost(String url, Map<String, String> basicAuth, Map<String, String> data, String requestFlavor, int timeout) throws Exception {
  
  		final HttpParams httpParams = new BasicHttpParams();
  		HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
  		HttpClient client = new DefaultHttpClient(httpParams);
  
  		HttpPost req = new HttpPost(url);
  
  		if(basicAuth != null && !basicAuth.isEmpty()) { 
  			String cred = basicAuth.get("username") + ":" + basicAuth.get("password");
  			cred = Base64.encodeBase64String(cred.getBytes());
  			req.addHeader("Authorization", "Basic " + cred);
  		}
  
  
  		if(data != null && !data.isEmpty()) {
  			switch(requestFlavor) {
  				case "formdata":
  					List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
  					for (String key : data.keySet()) {
  						urlParameters.add(new BasicNameValuePair(key, data.get(key)));
  					}
  					req.setEntity(new UrlEncodedFormEntity(urlParameters));
  					break;
  
  				case "raw":
  					if(data.get("httpContentType") != null && !data.get("httpContentType").isEmpty()) {
  						req.addHeader("Content-Type", data.get("httpContentType"));
  					}
  
  					if(data.get("payload") != null && !data.get("payload").isEmpty()) {
  						req.setEntity(new StringEntity(data.get("payload")));
  					}
  					break;
  			}
  		}
  
  		HttpResponse response = client.execute(req);
  
  		try {
  			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  
  			StringBuffer result = new StringBuffer();
  			String line = "";
  			while ((line = rd.readLine()) != null) {
  				result.append(line);
  			}
  			return new JSONObject(result.toString());
  		} catch (IOException e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		} catch (Exception e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		}
  		return null;
  
  	}
  
  	private JSONObject restPut(String url, Map<String, String> basicAuth, Map<String, String> data, String requestFlavor, int timeout) throws Exception {
  
  		final HttpParams httpParams = new BasicHttpParams();
  		HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
  		HttpClient client = new DefaultHttpClient(httpParams);
  
  		HttpPut req = new HttpPut(url);
  
  		if(basicAuth != null && !basicAuth.isEmpty()) { 
  			String cred = basicAuth.get("username") + ":" + basicAuth.get("password");
  			cred = Base64.encodeBase64String(cred.getBytes());
  			req.addHeader("Authorization", "Basic " + cred);
  		}
  
  
  		if(data != null && !data.isEmpty()) {
  			switch(requestFlavor) {
  				case "formdata":
  					List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
  					for (String key : data.keySet()) {
  						urlParameters.add(new BasicNameValuePair(key, data.get(key)));
  					}
  					req.setEntity(new UrlEncodedFormEntity(urlParameters));
  					break;
  
  				case "raw":
  					if(data.get("httpContentType") != null && !data.get("httpContentType").isEmpty()) {
  						req.addHeader("Content-Type", data.get("httpContentType"));
  					}
  					if(data.get("payload") != null && !data.get("payload").isEmpty()) {
  						req.setEntity(new StringEntity(data.get("payload")));
  					}
  					break;
  			}
  		}
  
  		HttpResponse response = client.execute(req);
  
  		try {
  			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  
  			StringBuffer result = new StringBuffer();
  			String line = "";
  			while ((line = rd.readLine()) != null) {
  				result.append(line);
  			}
  			return new JSONObject(result.toString());
  		} catch (IOException e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		} catch (Exception e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		}
  		return null;
  
  	}
  
  	private JSONObject restPatch(String url, Map<String, String> basicAuth, Map<String, String> data, String requestFlavor, int timeout) throws Exception {
  
  		final HttpParams httpParams = new BasicHttpParams();
  		HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
  		HttpClient client = new DefaultHttpClient(httpParams);
  
  		HttpPatch req = new HttpPatch(url);
  
  		if(basicAuth != null && !basicAuth.isEmpty()) { 
  			String cred = basicAuth.get("username") + ":" + basicAuth.get("password");
  			cred = Base64.encodeBase64String(cred.getBytes());
  			req.addHeader("Authorization", "Basic " + cred);
  		}
  
  
  		if(data != null && !data.isEmpty()) {
  			switch(requestFlavor) {
  				case "formdata":
  					List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
  					for (String key : data.keySet()) {
  						urlParameters.add(new BasicNameValuePair(key, data.get(key)));
  					}
  					req.setEntity(new UrlEncodedFormEntity(urlParameters));
  					break;
  
  				case "raw":
  					if(data.get("httpContentType") != null && !data.get("httpContentType").isEmpty()) {
  						req.addHeader("Content-Type", data.get("httpContentType"));
  					}
  					if(data.get("payload") != null && !data.get("payload").isEmpty()) {
  						req.setEntity(new StringEntity(data.get("payload")));
  					}
  					break;
  			}
  		}
  
  		HttpResponse response = client.execute(req);
  
  		try {
  			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  
  			StringBuffer result = new StringBuffer();
  			String line = "";
  			while ((line = rd.readLine()) != null) {
  				result.append(line);
  			}
  			return new JSONObject(result.toString());
  		} catch (IOException e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		} catch (Exception e) {
  			Logger.error(JSONObject.class, e.getMessage(), e);
  		}
  		return null;
  
  	}
  
  
  	public JSONObject getAuth(String url, Map<String, String> basicAuth) throws Exception {
  		return restGet(url, basicAuth, null, 15000);
  	}
  
  	public JSONObject getAuth(String url, Map<String, String> basicAuth, int timeout) throws Exception {
  		return restGet(url, basicAuth, null, timeout);
  	}
  
  	public JSONObject getAuth(String url, Map<String, String> basicAuth, Map<String, String> data) throws Exception {
  		return restGet(url, basicAuth, data, 15000);
  	}
  
  	public JSONObject getAuth(String url, Map<String, String> basicAuth, Map<String, String> data, int timeout) throws Exception {
  		return restGet(url, basicAuth, data, timeout);
  	}
  
  	public JSONObject get(String url, Map<String, String> data) throws Exception {
  		return restGet(url, null, data, 15000);
  	}
  
  	public JSONObject get(String url, Map<String, String> data, int timeout) throws Exception {
  		return restGet(url, null, data, timeout);
  	}
  
  
  	public JSONObject postAuth(String url, Map<String, String> basicAuth, Map<String, String> data, String requestFlavor) throws Exception {
  		return restPost(url, basicAuth, data, requestFlavor, 15000);
  	}
  
  	public JSONObject postAuth(String url, Map<String, String> basicAuth, Map<String, String> data, String requestFlavor, int timeout) throws Exception {
  		return restPost(url, basicAuth,  data, requestFlavor, timeout);
  	}
  
  	public JSONObject post(String url, Map<String, String> data, String requestFlavor) throws Exception {
  