Add more validations
package org.wso2.micro.integrator.management.apis;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPBody;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
@@ -123,7 +124,9 @@ public class CarbonAppResource extends APIResource {
Utils.setJsonPayLoad(axisMsgCtx, response);
return;
}
- OMElement messageBody = axisMsgCtx.getEnvelope().getBody().getFirstElement();
+ SOAPBody soapBody = axisMsgCtx.getEnvelope().getBody();
+ if (null != soapBody) {
+ OMElement messageBody = soapBody.getFirstElement();
Iterator iterator = messageBody.getChildElements();
if (iterator.hasNext()) {
OMElement fileElement = (OMElement) iterator.next();
@@ -159,6 +162,11 @@ public class CarbonAppResource extends APIResource {
axisMsgCtx, BAD_REQUEST);
Utils.setJsonPayLoad(axisMsgCtx, jsonResponse);
}
+ } else {
+ jsonResponse = Utils.createJsonError("No valid message body found. ",
+ axisMsgCtx, BAD_REQUEST);
+ Utils.setJsonPayLoad(axisMsgCtx, jsonResponse);
+ }
}
private void handleDelete(MessageContext messageContext, org.apache.axis2.context.MessageContext axisMsgCtx) {
@@ -188,6 +196,7 @@ public class CarbonAppResource extends APIResource {
} else {
jsonResponse = Utils.createJsonError("Carbon Application name " +
cAppName + "' does not exist", axisMsgCtx, NOT_FOUND);
+ Utils.setJsonPayLoad(axisMsgCtx, jsonResponse);
}
} catch (IOException e) {
String message = "Error when undeploying the Carbon Application " + cAppName + ".car";
@@ -197,9 +206,9 @@ public class CarbonAppResource extends APIResource {
} else {
jsonResponse = Utils.createJsonError("Missing required " + CAPP_NAME
+ " parameter in the path", axisMsgCtx, BAD_REQUEST);
- }
Utils.setJsonPayLoad(axisMsgCtx, jsonResponse);
}
+ }
private void populateCarbonAppList(MessageContext messageContext) {
