@SuppressWarnings("unchecked") Request populate(Request toPopulate) { for (Map.Entry<String, String> header : headers.entrySet()) { toPopulate.addHeader(header.getKey(), header.getValue()); } if (content == null) return toPopulate; if (contentClass.equals(byte[].class)) { toPopulate.bodyByteArray((byte[]) content); } else if (contentClass.equals(String.class)) { toPopulate.bodyString((String) content, contentType); } else if (Map.class.isAssignableFrom(contentClass)) { List<NameValuePair> formContent = Lists.newArrayList(); for (Map.Entry<String, String> val : ((Map<String, String>) content).entrySet()) { formContent.add(new BasicNameValuePair(val.getKey(), val.getValue())); } toPopulate.bodyForm(formContent); } else if (contentClass.equals(File.class)) { toPopulate.bodyFile((File) content, contentType); } else if (InputStream.class.isAssignableFrom(contentClass)) { toPopulate.bodyStream((InputStream) content); } else { throw new IllegalArgumentException( String.format( "Unknown content class %s. Only byte[], String, Map, File and InputStream are accepted", contentClass)); } return toPopulate; }