import java.util.ArrayList;
import java.util.List;
public class SQSRestBasedHandler extends AbstractHandler {
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
MultipleEntryHashMap multipleEntryHashMap =
(MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP);
if (multipleEntryHashMap != null) {
Object accessKeyIdProperty = multipleEntryHashMap.get(MessageBoxConstants.AWSACCESS_KEY_ID);
Object actionNameProperty = multipleEntryHashMap.get(MessageBoxConstants.ACTION);
Object messageBodyProperty = multipleEntryHashMap.get("MessageBody");
Object maxNumberOfMessagesProperty = multipleEntryHashMap.get("MaxNumberOfMessages");
Object visibilityTimeoutProperty = multipleEntryHashMap.get("VisibilityTimeout");
Object receiptHandleProperty = multipleEntryHashMap.get("ReceiptHandle");
Object queueNamePrefixProperty = multipleEntryHashMap.get("QueueNamePrefix");
Object permissionLabelProperty = multipleEntryHashMap.get("Label");
Object queueNameProperty = multipleEntryHashMap.get("QueueName");
// AWSAccountId.n ActionName.n AttributeName.n Attribute.Name Attribute.Value
List<Object> aWSAccountIdList = new ArrayList<Object>();
List<Object> actionNameList = new ArrayList<Object>();
List<Object> attributeNameList = new ArrayList<Object>();
List<Object> setQueueAttributeNameList = new ArrayList<Object>();
List<Object> setQueueAttributeValueList = new ArrayList<Object>();
getParametersFromHashMap(multipleEntryHashMap, aWSAccountIdList, actionNameList,
attributeNameList, setQueueAttributeNameList,
setQueueAttributeValueList);
if (actionNameProperty != null) {
String actionName = actionNameProperty.toString();
emptyMultipleHashMap(multipleEntryHashMap);
if (actionName.equalsIgnoreCase("CreateQueue") ||
actionName.equalsIgnoreCase("DeleteQueue")) {
multipleEntryHashMap.put("QueueName", queueNameProperty);
} else if (actionName.equalsIgnoreCase("SendMessage")) {
try {
String messageBody = URLDecoder.decode(messageBodyProperty.toString(),
MessageBoxConstants.URL_ENCODING);
multipleEntryHashMap.put("MessageBody", messageBody);
} catch (UnsupportedEncodingException e) {
throw new AxisFault("Failed to decode message body " +
messageBodyProperty.toString(), e);
}
} else if (actionName.equalsIgnoreCase("ReceiveMessage")) {
setReceiveMessageParameters(multipleEntryHashMap, maxNumberOfMessagesProperty,
visibilityTimeoutProperty, attributeNameList);
} else if (actionName.equalsIgnoreCase("DeleteMessage")) {
multipleEntryHashMap.put("ReceiptHandle", receiptHandleProperty);
} else if (actionName.equalsIgnoreCase("ListQueues")) {
multipleEntryHashMap.put("QueueNamePrefix", queueNamePrefixProperty);
} else if (actionName.equalsIgnoreCase("ChangeMessageVisibility")) {
multipleEntryHashMap.put("ReceiptHandle", receiptHandleProperty);
multipleEntryHashMap.put("VisibilityTimeout", visibilityTimeoutProperty);
} else if (actionName.equalsIgnoreCase("GetQueueAttributes")) {
for (Object attributeNameProperty : attributeNameList) {
multipleEntryHashMap.put("AttributeName", attributeNameProperty);
}
} else if (actionName.equalsIgnoreCase("SetQueueAttributes")) {
setSetQueueAttributeParameters(multipleEntryHashMap, setQueueAttributeNameList,
setQueueAttributeValueList);
} else if (actionName.equalsIgnoreCase("AddPermission")) {
setAddPermissionParameters(multipleEntryHashMap, accessKeyIdProperty,
permissionLabelProperty, aWSAccountIdList,
actionNameList);
} else if (actionName.equalsIgnoreCase("RemovePermission")) {
multipleEntryHashMap.put("AWSAccountId", accessKeyIdProperty);
multipleEntryHashMap.put("Label", permissionLabelProperty);
}
org.apache.axiom.soap.SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
messageContext.setEnvelope(BuilderUtil.buildsoapMessage(messageContext,