Apache HttpClient POST (Multipart/Form-data)

Recently i was asked to test the webservices(REST) from J-unit  which accepts list of files((Multipart/Form-data)) and stores it in the server location..

I was going through list of api

1. HttpURLConnection

2. Apache Commons HttpClient-3.x(legacy-not in active developement)

3. Apache HttpClient-4.x.x

4. Apache cxf-client

5. Jersey-Client

6. RestEasy-Client

However i opted to go with apache httpcomponents api.

public void doProvision(Map<String, File> fileMap)
throws HttpException, IOException {

PostMethod multipartPostMethod = new PostMethod(getMR_URL() + "/admin/provisioning/provision");
//String part
String name = "{\"initialProvision\":\"";
String value = "true\"}";
StringPart stringPart = new StringPart(name, value);
stringPart.setCharSet("UTF-8");
stringPart.setContentType("application/json");
// 4 files to be uploaded.
FilePart systemPart = new FilePart("sourceSystem",fileMap.get("system"));
FilePart propertyPart = new FilePart("properties",fileMap.get("properties"));
FilePart componentPart = new FilePart("components",fileMap.get("component"));
FilePart zipPart = new FilePart("xsdZip", fileMap.get("zip"));
Part[] parts = { propertyPart, systemPart, componentPart, zipPart,stringPart };
MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, multipartPostMethod.getParams());
multipartPostMethod.setRequestEntity(requestEntity);
HttpClient client = new HttpClient();
multipartPostMethod.setRequestHeader("Cookie",mrHttpClient.getSessionCookie());
//Execute.
int status = client.executeMethod(multipartPostMethod);
String message = multipartPostMethod.getResponseBodyAsString();
}