How to create the post method
public static void deleteDocumentForItemAccount(UserContext userContext, long itemAccountId) throws DocumentManagementException, Exception {
PermissionedUserContext pUserCtx = (PermissionedUserContext) userContext;
String storageServerURL = getStorageServerURL((TCobrandContext)userContext);
storageServerURL = storageServerURL + DocumentManagementConstants.DOCUMENT_STORAGE_DELETE_ITEMACCOUNTDATA_URL;
String itemAccIds ="&itemAccountIds="+itemAccountId;
PostMethod pm = new PostMethod(storageServerURL);
StringBuffer paramString = new StringBuffer("cobrandId=");
paramString.append(pUserCtx.getCobrandId());
paramString.append("&channelId=");
paramString.append(pUserCtx.getChannelId());
paramString.append("&appId=");
paramString.append(pUserCtx.getApplicationId());
paramString.append("&memId=");
paramString.append(pUserCtx.getMemId());
paramString.append(itemAccIds);
//String paramString = "cobrandId="+pUserCtx.getCobrandId()+"&appId="+pUserCtx.getApplicationId()+"&memId="+pUserCtx.getMemId()+itemAccIds;
String securityKey = encryptDataForAuthentication( pUserCtx, pUserCtx.getCobrandId()+""+pUserCtx.getMemId());
if(!StringUtils.isEmpty(securityKey)) {
paramString.append("&securityKey=");
paramString.append(securityKey);
}
MessageController.log(FQCN, 6666 ," DocumentManagementUtil.deleteDocumentForItemAccount : securityKey : " +securityKey , MessageController.DEBUG);
Map<String, String> responseMap = new HashMap<String, String>();
try {
MessageController.log(FQCN, 4065 ," DocumentManagementUtil.deleteDocumentForItem : BEFORE performServiceOperation :: storageServerURL : " +storageServerURL , MessageController.DEBUG);
pm.setRequestEntity(new StringRequestEntity(paramString.toString(), "application/x-www-form-urlencoded", "utf-8"));
responseMap = DocumentManagementUtil.performServiceOperation(pm);
MessageController.log(FQCN, 4066 ," DocumentManagementUtil.deleteDocumentForItem : AFTER performServiceOperation :: responseMap : " +responseMap , MessageController.DEBUG);
String responseCode = responseMap.get(DocumentManagementConstants.DOCUMENT_SERVICE_RESPONSE_CODE);
int rc = Integer.parseInt(responseCode);
String response = responseMap.get(DocumentManagementConstants.DOCUMENT_SERVICE_RESPONSE);
if(rc == HttpStatus.SC_OK) {
//Gson gson = new Gson();
Type type = new TypeToken<ArrayList<Map<String, Object>>>(){}.getType();
ArrayList<Map<String, Object>> list_map = gson.fromJson(response, type);
if(list_map != null) {
for (Map<String, Object> map : list_map) {
if(map.get("result") != null){
if(((String)map.get("result")).equalsIgnoreCase("false")){
throw new DocumentManagementException();
}
}
else{
MessageController.log(FQCN, 4067 ,"Saumya::: DocumentManagementUtil.deleteDocumentForItemAccount : exception : ", MessageController.FATAL);
throw new DocumentManagementException();
}
}
}
}
else{
throw new DocumentManagementException();
}
} catch (Exception e) {
// TODO Auto-generated catch block
MessageController.log(FQCN, 4068 ," DocumentManagementUtil.deleteDocumentForItemAccount : exception : "+e.getMessage(), MessageController.FATAL);
//e.printStackTrace()();
throw e;
}
}
public static Map<String,String> performServiceOperation(HttpMethod httpMethod) throws Exception {
Map<String,String> responseMap = new HashMap<String, String>();
String response = "";
try {
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostnameVerifier());
HttpClient hc = new HttpClient();
//As part of unique tracking id user story added below code to track the id accross components
addUniqueTrackingId(httpMethod);
int rc = hc.executeMethod(httpMethod);
responseMap.put(DocumentManagementConstants.DOCUMENT_SERVICE_RESPONSE_CODE, (String.valueOf(rc)));
response = httpMethod.getResponseBodyAsString();
responseMap.put(DocumentManagementConstants.DOCUMENT_SERVICE_RESPONSE, response);
} catch (Exception e) {
MessageController.log(FQCN, 7532 ," DocumentManagementUtil.performServiceRequest : exception : "+e.getMessage(), MessageController.FATAL);
throw e;
}
return responseMap;
}