Source:
private JSONObject createProcessInstance(String processDefId, String username, String password) throws JSONException, IOException { HttpPost httpPost = null; String line = ""; StringEntity stringEntity; JSONObject rsltObj; JSONObject rtrnObj = new JSONObject(); try (CloseableHttpResponse response = null; BufferedReader rd = null) { httpPost = new HttpPost( baseUrl + "/bpmn/runtime/process-instances"); httpPost.addHeader(BPMNExplorerServiceConstants.CONTENT_TYPE, BPMNExplorerServiceConstants.JSON_CONTENT_TYPE); String authString = username + ":" + password; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); httpPost.addHeader(BPMNExplorerServiceConstants.AUTHORIZATION, BPMNExplorerServiceConstants.BASIC_AUTHORIZATION + new String(authEncBytes)); JSONObject bodyObj = new JSONObject(); bodyObj.put("processDefinitionId", processDefId); stringEntity = new StringEntity(bodyObj.toString()); httpPost.setEntity(stringEntity); response = client.execute(httpPost); rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), Charset.defaultCharset())); StringBuffer result = new StringBuffer(); while ((line = rd.readLine()) != null) { result.append(line); } rsltObj = new JSONObject(result.toString()); if (rsltObj.has("id")) { JSONObject processInstanceObj = new JSONObject(); processInstanceObj.put("process-def-id", rsltObj.get("processDefinitionId")); processInstanceObj.put("process-instance-id", rsltObj.get("id")); rtrnObj.put("processInstanceData", processInstanceObj); } else if (rsltObj.has("errorMessage")) { rtrnObj.put("error-message", rsltObj.get("errorMessage")); } } catch (ClientProtocolException | IOException e) { log.error("Exception : ", e); } finally { if (httpPost != null) { httpPost.releaseConnection(); } } return rtrnObj; }

Target:
private JSONObject createProcessInstance(String processDefId, String username, String password) throws JSONException, IOException { HttpPost httpPost = null; String line = ""; StringEntity stringEntity; JSONObject rsltObj; JSONObject rtrnObj = new JSONObject(); try (CloseableHttpResponse response = null; BufferedReader rd = null) { httpPost = new HttpPost( baseUrl + "/bpmn/runtime/process-instances"); httpPost.addHeader(Constants.CONTENT_TYPE, Constants.JSON_CONTENT_TYPE); String authString = username + ":" + password; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); httpPost.addHeader(Constants.AUTHORIZATION, Constants.BASIC_AUTHORIZATION + new String(authEncBytes)); JSONObject bodyObj = new JSONObject(); bodyObj.put(Constants.PROC_DEFINITION_ID, processDefId); stringEntity = new StringEntity(bodyObj.toString()); httpPost.setEntity(stringEntity); response = client.execute(httpPost); rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), Charset.defaultCharset())); StringBuffer result = new StringBuffer(); while ((line = rd.readLine()) != null) { result.append(line); } rsltObj = new JSONObject(result.toString()); if (rsltObj.has(Constants.ID)) { JSONObject processInstanceObj = new JSONObject(); processInstanceObj.put(Constants.PROCESS_DEF_ID, rsltObj.get(Constants.PROC_DEFINITION_ID)); processInstanceObj.put(Constants.PROCESS_INSTANCE_ID, rsltObj.get(Constants.ID)); rtrnObj.put(Constants.PROC_INSTANCE_DATA, processInstanceObj); } else if (rsltObj.has(Constants.ERROR_MSG)) { rtrnObj.put(Constants.ERROR_MESSAGE, rsltObj.get(Constants.ERROR_MSG)); } } catch (ClientProtocolException e) { log.error(Constants.CLIENT_PROTOCOL_EX, e); } finally { if (httpPost != null) { httpPost.releaseConnection(); } } return rtrnObj; }