public static Response jsonRestCall( final String url ) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doGet(url, null, APPLICATION_JSON, null); return extractResponseObject(connection); } }); }
public static Response postBodyTextWithContentTypeReturnResponse(final String url, final String contentType, final String body) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doPost(url, null, contentType, null, body); return extractResponseObject(connection); } }); }
public static Response putBodyTextWithContentTypeReturnResponse(final String url, final String contentType, final String body) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doPut(url, null, contentType, null, body); return extractResponseObject(connection); } }); }
public static String putBodyTextWithContentType( final String url, final String contentType, final String body) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPost(url, null, contentType, null, body); return extractResponseString(connection); } }); }
public static String postForm(final String url, final Map<String, ?> headers, final Map<String, Object> formData ) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPostFormData(url, headers, formData); return extractResponseString(connection); } }); }
public static String getWithCharSet( final String url, final Map<String, ?> headers, final String contentType, final String charSet) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, contentType, charSet); return extractResponseString(connection); } }); }
public static String getJSON( final String url, final Map<String, ?> headers ) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, APPLICATION_JSON, null); return extractResponseString(connection); } }); }
public static Response jsonRestCallWithHeaders( final String url, final Map<String, ?> headers ) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, APPLICATION_JSON, null); return extractResponseObject(connection); } }); }
public static String getJSONWithParams( final String url, final Map<String, ?> headers, final Map<String, ?> params ) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, APPLICATION_JSON, null, params); return extractResponseString(connection); } }); }
public static String postBodyTextWithContentType( final String url, final String contentType, final String body) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPost(url, null, contentType, null, body); return extractResponseString(connection); } }); }
public static String postWithHeaders( final String url, final Map<String, ?> headers, final String body) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPost(url, headers, "text/plain", null, body); return extractResponseString(connection); } }); }
public static String postWithContentType( final String url, final Map<String, ?> headers, final String contentType, final String body) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPost(url, headers, contentType, null, body); return extractResponseString(connection); } }); }
public static Response deleteResponse( final String url) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; final Map<String, String> accept = Maps.map( "Accept", "text/html,application/xhtml+xml,application/xml,application/json,text/plain;" ); connection = doDelete(url, accept, null, null); return extractResponseObject(connection); } } ); }
public static String postWithCharset( final String url, final Map<String, ?> headers, final String contentType, final String charSet, final String body) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPost(url, headers, contentType, charSet, body); return extractResponseString(connection); } }); }
/** * GET that expects contents back as a byte array. * * @param url url * @param contentType contentType * @return bytes from location */ public static byte[] getBytes( final String url, final String contentType) { return Exceptions.tryIt(byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet(url, null, contentType, null, true); return extractResponseBytes(connection); } }); }
/** * GET that expects contents back as a byte array and allows you to pass headers. * * @param url url * @param contentType contentType * @param headers to pass. * @return bytes from location */ public static byte[] getBytesUsingHeaders( final String url, final String contentType, final Map<String, ?> headers) { return Exceptions.tryIt(byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, contentType, null, true); return extractResponseBytes(connection); } }); }
/** * GET that expects contents back as a byte array and allows you to pass headers. * * @param url url * @param headers to pass. * @return string from location */ public static String getWithHeaders( final String url, final Map<String, ?> headers) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, null, null); return extractResponseString(connection); } }); }
/** * Does a simple HTTP get * * @param url pass the URL you want to get. * @return contents as UTF-8 string */ public static String get( final String url) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; final Map<String, String> accept = Maps.map( "Accept", "text/html,application/xhtml+xml,application/xml,application/json,text/plain;" ); connection = doGet(url, accept, null, null); return extractResponseString(connection); } }); }
/** * Does a get but you get a Response object * * @param url url * @return Response object */ public static Response getResponse( final String url) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; final Map<String, String> accept = Maps.map( "Accept", "text/html,application/xhtml+xml,application/xml,application/json,text/plain;" ); connection = doGet(url, accept, null, null); return extractResponseObject(connection); } } ); }
/** * GET that expects contents back as a string and allows you to pass headers and content type. * * @param url url * @param headers to pass. * @param contentType contentType * @return UTF-8 string from location */ public static String getWithContentTypeHeaders( final String url, final Map<String, ?> headers, final String contentType) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doGet(url, headers, contentType, null); return extractResponseString(connection); } }); }