-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP - SO\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.openecomp.mso.bpmn.common.scripts\r
-\r
-import static org.apache.commons.lang3.StringUtils.*\r
-\r
-import org.apache.commons.lang3.*\r
-import org.camunda.bpm.engine.delegate.BpmnError\r
-import org.camunda.bpm.engine.runtime.Execution\r
-import org.openecomp.mso.bpmn.core.WorkflowException\r
-\r
-/**\r
- * @version 1.0\r
- */\r
-class ExceptionUtil extends AbstractServiceTaskProcessor {\r
-\r
-\r
- /**\r
- * This error handling method maps an AAI Exception response to a\r
- * WorkflowException Object. It then sets the WorkflowException Object\r
- * on the execution as "WorkflowException".\r
- *\r
- * This method formats the exception from AAI into the WorkflowException's\r
- * errorMessage that CCD expects.\r
- *\r
- * @param execution the execution\r
- * @param response the aai exception\r
- */\r
- WorkflowException MapAAIExceptionToWorkflowException(String response, Execution execution)\r
- {\r
- def utils=new MsoUtils()\r
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
- def prefix=execution.getVariable("prefix")\r
- def errorMsg = execution.getVariable(prefix+"ErrorResponse")\r
- utils.log("DEBUG","=========== Begin MapAAIExceptionToWorkflowException ===========",isDebugEnabled)\r
- String text = null\r
- def variables\r
- String errorCode = '5000'\r
- WorkflowException wfex\r
- utils.log("DEBUG","response: " + response, isDebugEnabled)\r
- try{\r
- try {\r
- //String msg = utils.getNodeXml(response, "Fault")\r
- variables = utils.getMultNodes(response, "variable")\r
- text = utils.getNodeText1(response, "text")\r
- } catch (Exception ex) {\r
- //Ignore the exception - cases include non xml payload\r
- utils.log("DEBUG","error mapping error, ignoring: " + ex,isDebugEnabled)\r
- }\r
-\r
- if(text != null) {\r
- if(variables.size()>=4){\r
- text = text.replaceFirst("%1", variables[0])\r
- text = text.replaceFirst("%2", variables[1])\r
- text = text.replaceFirst("%3", variables[2])\r
- text = text.replaceFirst("%4", variables[3])\r
- }\r
- String modifiedErrorMessage = 'Received error from A&AI (' + text +')'\r
- utils.log("DEBUG", "ModifiedErrorMessage " + modifiedErrorMessage, isDebugEnabled)\r
- // let $ModifiedErrorMessage := concat( 'Received error from A',$exceptionaai:ampersand,'AI (' ,functx:replace-multi($ErrorMessage,$from,$Variables ),')')\r
- buildWorkflowException(execution, 5000, modifiedErrorMessage)\r
-\r
- wfex = execution.getVariable("WorkflowException")\r
- utils.log("ERROR","Fault:"+ wfex)\r
- return wfex\r
- } else {\r
- try {\r
- errorCode = MapErrorCode(errorMsg)\r
- String mappedErrorMessage = MapErrorMessage(errorMsg, errorCode)\r
-\r
- int errorCodeInt = Integer.parseInt(errorCode)\r
- buildWorkflowException(execution, errorCodeInt, mappedErrorMessage)\r
-\r
- utils.log("DEBUG", "mappedErrorMessage " + mappedErrorMessage, isDebugEnabled)\r
- wfex = execution.getVariable("WorkflowException")\r
- utils.log("ERROR","Fault:"+ wfex, isDebugEnabled)\r
- return wfex\r
- } catch(Exception ex) {\r
- utils.log("DEBUG","error mapping error, return null: " + ex, isDebugEnabled)\r
- return null\r
-\r
- }\r
- }\r
- }catch(Exception e){\r
- utils.log("DEBUG", "Exception occured during MapAAIExceptionToWorkflowException: " + e, isDebugEnabled)\r
- buildWorkflowException(execution, 5000, "Error mapping AAI Response to WorkflowException")\r
- }\r
- }\r
-\r
- /**\r
- * This error handling method maps an AAI Exception response to a\r
- * WorkflowException Object. It then sets the WorkflowException Object\r
- * on the execution as "WorkflowException".\r
- *\r
- * This method takes the exact exception inside the <Fault> tags from AAI Response\r
- * and puts it into the WorkflowException's errorMessage.\r
- *\r
- * @param execution the execution\r
- * @param response the aai exception\r
- */\r
- WorkflowException MapAAIExceptionToWorkflowExceptionGeneric(Execution execution, String response, int resCode){\r
- def utils=new MsoUtils()\r
- def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")\r
- utils.log("DEBUG", "Start MapAAIExceptionToWorkflowExceptionGeneric Process", isDebugLogEnabled)\r
-\r
- WorkflowException wfex\r
- try {\r
- if(utils.nodeExists(response, "Fault")){\r
- String fault = utils.getNodeXml(response, "Fault")\r
- fault = utils.removeXmlPreamble(fault)\r
- fault = fault.replace("<Fault>", "").replace("</Fault>", "")\r
- fault = fault.replaceAll("\\s+\\s+", "") // Removes extra white spaces\r
- buildWorkflowException(execution, resCode, fault)\r
- }else if(utils.nodeExists(response, "RESTFault")){\r
- String rFault = utils.getNodeXml(response, "RESTFault")\r
- buildWorkflowException(execution, resCode, rFault)\r
- }else{\r
- buildWorkflowException(execution, resCode, "Received a bad response from AAI")\r
- }\r
- } catch (Exception ex) {\r
- utils.log("DEBUG", "Exception Occured during MapAAIExceptionToWorkflowExceptionGeneric: " + ex, isDebugLogEnabled)\r
- buildWorkflowException(execution, resCode, "Internal Error - Occured in MapAAIExceptionToWorkflowExceptionGeneric")\r
-\r
- }\r
- utils.log("DEBUG", "Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugLogEnabled)\r
- utils.log("DEBUG", "Completed MapAAIExceptionToWorkflowExceptionGeneric Process", isDebugLogEnabled)\r
- }\r
-\r
- /**\r
- * This method takes a WorkflowException Object and builds\r
- * WorkflowException Xml. This method should only be used\r
- * for the purpose of sending a sync error response or for\r
- * creating a FalloutHandler request.\r
- *\r
- *@param - WorkflowException Object\r
- *\r
- *@return - String WorkflowException Xml\r
- *\r
- *\r
- */\r
- String buildErrorResponseXml(WorkflowException wfex) {\r
- String xml\r
- if(wfex != null){\r
- String mes = wfex.getErrorMessage()\r
- int code = wfex.getErrorCode()\r
- xml =\r
- """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
- <aetgt:ErrorMessage>${mes}</aetgt:ErrorMessage>\r
- <aetgt:ErrorCode>${code}</aetgt:ErrorCode>\r
- </aetgt:WorkflowException>"""\r
-\r
- }else{\r
- xml =\r
- """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
- <aetgt:ErrorMessage>Internal Error</aetgt:ErrorMessage>\r
- <aetgt:ErrorCode>2500</aetgt:ErrorCode>\r
- </aetgt:WorkflowException>"""\r
- }\r
- return xml\r
- }\r
-\r
- /*\r
- 5000 Received error from A&AI ($A&AI_ERROR) Asynchronous During orchestration of the recipe, A&AI returned an error. The error returned by A&AI is passed through in $A&AI_ERROR.\r
- 5010 Could not communicate with A&AI Asynchronous During orchestration of the recipe, a connection with A&AI could not be established.\r
- 5020 No response from A&AI Asynchronous During orchestration of the recipe, communication was established with A&AI, but no response was received within the configured timeout.\r
- */\r
- /**\r
- *\r
- * Utility Method for MapAAIExceptionToWorkflowException\r
- *\r
- *@param - String ErrorMessage\r
- *\r
- *@return - String ErrorCode\r
- *\r
- */\r
- private String MapErrorCode(String errorMessage)\r
- {\r
- if(errorMessage==null){\r
- return '5000'\r
- }\r
- errorMessage = errorMessage.toLowerCase();\r
- if(errorMessage.contains('timed out') || errorMessage.contains('timeout'))\r
- return '5020'\r
- else if (errorMessage.contains('connection'))\r
- return '5010'\r
- else\r
- return '5000'\r
- }\r
-\r
- /**\r
- *\r
- * Utility Method for MapAAIExceptionToWorkflowException\r
- *\r
- *@param - String ErrorMessage\r
- *@param - String ErrorCode\r
- *\r
- *@return - String ErrorMessage\r
- *\r
- */\r
- private String MapErrorMessage(String errorMessage, String errorCode)\r
- {\r
- if(errorMessage == null){\r
- errorMessage=""\r
- }\r
- if( errorCode.equals('5010')){\r
- return 'Could not communicate with A&AI'\r
- }else if (errorCode.equals('5020')){\r
- return 'No response from A&AI'\r
- }else{\r
- errorMessage = errorMessage.replace("&", "&").replace("<", "<").replace(">", ">")\r
- return 'Received error from A&AI (' +errorMessage +')'\r
- }\r
- }\r
-\r
- /**\r
- *\r
- * Utility Method for Mapping SDNC\r
- * Adapter Response Codes\r
- *\r
- *@param - String sdncResponseCode\r
- *\r
- *@return - String code\r
- *\r
- */\r
- String MapSDNCResponseCodeToErrorCode(String sdncResponseCode)\r
- {\r
- if (sdncResponseCode == '500') {\r
- return '5310'\r
- } else if ( sdncResponseCode == '408') {\r
- return '5320'\r
- } else if ( sdncResponseCode == '60010') {\r
- return '5350'\r
- } else {\r
- return '5300'\r
- }\r
- }\r
-\r
- /**\r
- * This error handling method builds a WorkflowException Object. It sets it on\r
- * the execution as "WorkflowException".\r
- *\r
- * @param execution the execution\r
- * @param errorCode the error code\r
- * @param errorMessage the error message\r
- */\r
- public void buildWorkflowException(Execution execution, int errorCode, String errorMessage) {\r
- MsoUtils utils = new MsoUtils()\r
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
- String processKey = getProcessKey(execution);\r
- utils.log("DEBUG", "Building a WorkflowException for " + processKey, isDebugLogEnabled)\r
-\r
- WorkflowException exception = new WorkflowException(processKey, errorCode, errorMessage);\r
- execution.setVariable("WorkflowException", exception);\r
- utils.log("DEBUG", "Outgoing WorkflowException is " + exception, isDebugLogEnabled)\r
- }\r
-\r
- /**\r
- * This error handling method builds a WorkflowException Object and throws a\r
- * MSOWorkflowException. It throws a "MSOWorkflowException" BpmnError after\r
- * setting the WorkflowException Object on the execution as "WorkflowException".\r
- *\r
- * @param execution the execution\r
- * @param errorCode the error code\r
- * @param errorMessage the error message\r
- */\r
- public void buildAndThrowWorkflowException(Execution execution, int errorCode, String errorMessage) {\r
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
- String processKey = getProcessKey(execution);\r
- utils.log("Building a WorkflowException for Subflow " + processKey, isDebugLogEnabled)\r
-\r
- WorkflowException exception = new WorkflowException(processKey, errorCode, errorMessage);\r
- execution.setVariable("WorkflowException", exception);\r
- utils.log("DEBUG", "Outgoing WorkflowException is " + exception, isDebugLogEnabled)\r
- utils.log("DEBUG", "Throwing MSOWorkflowException", isDebugLogEnabled)\r
- throw new BpmnError("MSOWorkflowException")\r
- }\r
-\r
- /**\r
- * This method is executed after an MSOWorkflowException is caught by a\r
- * subflow (during subflows "Error Handling Sub Process").\r
- * It ensures the WorkflowException variable is populated before ending the\r
- * subflow and also logs the subflows outgoing WorkflowException Variable.\r
- *\r
- * @param - execution\r
- *\r
- */\r
- public void processSubflowsBPMNException(Execution execution){\r
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
- String processKey = getProcessKey(execution)\r
- try{\r
- utils.log("DEBUG", "Started ProcessSubflowsBPMNException Method", isDebugEnabled)\r
- if(execution.getVariable("WorkflowException") == null){\r
- buildWorkflowException(execution, 2500, "Internal Error - Occured During " + processKey)\r
- }\r
-\r
- utils.log("DEBUG", processKey + " Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugEnabled)\r
- }catch(Exception e){\r
- utils.log("DEBUG", "Caught Exception during ProcessSubflowsBPMNException Method: " + e, isDebugEnabled)\r
- }\r
- utils.log("DEBUG", "Completed ProcessSubflowsBPMNException Method", isDebugEnabled)\r
- }\r
-\r
- /**\r
- * This method is executed after an MSOWorkflowException is caught by a\r
- * Mainflow. It builds and returns a FalloutHandler Request. It also\r
- * verifies the WorkflowException variable is populated.\r
- *\r
- * @param - execution\r
- * @param - requestInfo\r
- *\r
- * @return - falloutHandlerRequest\r
- *\r
- */\r
- public String processMainflowsBPMNException(Execution execution, String requestInfo){\r
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
- String processKey = getProcessKey(execution)\r
- try{\r
- utils.log("DEBUG", "Started ProcessMainflowBPMNException Method", isDebugEnabled)\r
- if(execution.getVariable("WorkflowException") == null || isBlank(requestInfo)){\r
- buildWorkflowException(execution, 2500, "Internal Error - WorkflowException Object and/or RequestInfo is null! " + processKey)\r
- }\r
- requestInfo = utils.removeXmlPreamble(requestInfo)\r
- WorkflowException wfex = execution.getVariable("WorkflowException")\r
- String errorMessage = wfex.getErrorMessage()\r
- int errorCode = wfex.getErrorCode()\r
-\r
- String falloutHandlerRequest =\r
- """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
- xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
- xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">\r
- ${requestInfo}\r
- <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
- <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>\r
- <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>\r
- </aetgt:WorkflowException>\r
- </aetgt:FalloutHandlerRequest>"""\r
-\r
- utils.log("DEBUG", processKey + " Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugEnabled)\r
- utils.log("DEBUG", processKey + " Outgoing FalloutHandler Request is: " + falloutHandlerRequest, isDebugEnabled)\r
-\r
- return falloutHandlerRequest\r
-\r
- }catch(Exception e){\r
- utils.log("DEBUG", "Caught Exception during ProcessMainflowBPMNException Method: " + e, isDebugEnabled)\r
- return null\r
- }\r
- utils.log("DEBUG", "Completed ProcessMainflowBPMNException Method", isDebugEnabled)\r
- }\r
-\r
- /**\r
- *\r
- * This method is executed after an Java Exception is caught\r
- * It sets the WorkflowException variable. The method can be used in either mainflow or subflows.\r
- *\r
- * @param - execution\r
- *\r
- */\r
- public void processJavaException(Execution execution){\r
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
- String processKey = getProcessKey(execution)\r
- try{\r
- utils.log("DEBUG", "Caught a Java Exception in " + processKey, isDebugEnabled)\r
- utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)\r
- buildWorkflowException(execution, 2500, "Catch a Java Lang Exception in " + processKey)\r
-\r
- }catch(BpmnError b){\r
- throw b\r
- }catch(Exception e){\r
- utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)\r
- buildWorkflowException(execution, 2500, "Internal Error - During Process Java Exception")\r
- }\r
- utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)\r
- }\r
-\r
-\r
- public void preProcessRequest(Execution execution) {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-}\r
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.bpmn.common.scripts
+
+import static org.apache.commons.lang3.StringUtils.*
+
+import com.google.common.xml.XmlEscapers
+
+import org.apache.commons.lang3.*
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.openecomp.mso.bpmn.core.WorkflowException
+
+/**
+ * @version 1.0
+ */
+class ExceptionUtil extends AbstractServiceTaskProcessor {
+
+
+ /**
+ * This error handling method maps an AAI Exception response to a
+ * WorkflowException Object. It then sets the WorkflowException Object
+ * on the execution as "WorkflowException".
+ *
+ * This method formats the exception from AAI into the WorkflowException's
+ * errorMessage that CCD expects.
+ *
+ * @param execution the execution
+ * @param response the aai exception
+ */
+ WorkflowException MapAAIExceptionToWorkflowException(String response, DelegateExecution execution)
+ {
+ def utils=new MsoUtils()
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ def prefix=execution.getVariable("prefix")
+ def errorMsg = execution.getVariable(prefix+"ErrorResponse")
+ utils.log("DEBUG","=========== Begin MapAAIExceptionToWorkflowException ===========",isDebugEnabled)
+ String text = null
+ def variables
+ String errorCode = '5000'
+ WorkflowException wfex
+ utils.log("DEBUG","response: " + response, isDebugEnabled)
+ try{
+ try {
+ //String msg = utils.getNodeXml(response, "Fault")
+ variables = utils.getMultNodes(response, "variable")
+ text = utils.getNodeText1(response, "text")
+ } catch (Exception ex) {
+ //Ignore the exception - cases include non xml payload
+ utils.log("DEBUG","error mapping error, ignoring: " + ex,isDebugEnabled)
+ }
+
+ if(text != null) {
+ if(variables.size()>=4){
+ text = text.replaceFirst("%1", variables[0])
+ text = text.replaceFirst("%2", variables[1])
+ text = text.replaceFirst("%3", variables[2])
+ text = text.replaceFirst("%4", variables[3])
+ }
+ String modifiedErrorMessage = 'Received error from A&AI (' + text +')'
+ utils.log("DEBUG", "ModifiedErrorMessage " + modifiedErrorMessage, isDebugEnabled)
+ // let $ModifiedErrorMessage := concat( 'Received error from A',$exceptionaai:ampersand,'AI (' ,functx:replace-multi($ErrorMessage,$from,$Variables ),')')
+ buildWorkflowException(execution, 5000, modifiedErrorMessage)
+
+ wfex = execution.getVariable("WorkflowException")
+ utils.log("ERROR","Fault:"+ wfex)
+ return wfex
+ } else {
+ try {
+ errorCode = MapErrorCode(errorMsg)
+ String mappedErrorMessage = MapErrorMessage(errorMsg, errorCode)
+
+ int errorCodeInt = Integer.parseInt(errorCode)
+ buildWorkflowException(execution, errorCodeInt, mappedErrorMessage)
+
+ utils.log("DEBUG", "mappedErrorMessage " + mappedErrorMessage, isDebugEnabled)
+ wfex = execution.getVariable("WorkflowException")
+ utils.log("ERROR","Fault:"+ wfex, isDebugEnabled)
+ return wfex
+ } catch(Exception ex) {
+ utils.log("DEBUG","error mapping error, return null: " + ex, isDebugEnabled)
+ return null
+
+ }
+ }
+ }catch(Exception e){
+ utils.log("DEBUG", "Exception occured during MapAAIExceptionToWorkflowException: " + e, isDebugEnabled)
+ buildWorkflowException(execution, 5000, "Error mapping AAI Response to WorkflowException")
+ }
+ }
+
+ /**
+ * This error handling method maps an AAI Exception response to a
+ * WorkflowException Object. It then sets the WorkflowException Object
+ * on the execution as "WorkflowException".
+ *
+ * This method takes the exact exception inside the <Fault> tags from AAI Response
+ * and puts it into the WorkflowException's errorMessage.
+ *
+ * @param execution the execution
+ * @param response the aai exception
+ */
+ WorkflowException MapAAIExceptionToWorkflowExceptionGeneric(DelegateExecution execution, String response, int resCode){
+ def utils=new MsoUtils()
+ def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", "Start MapAAIExceptionToWorkflowExceptionGeneric Process", isDebugLogEnabled)
+
+ WorkflowException wfex
+ try {
+ if(utils.nodeExists(response, "Fault")){
+ String fault = utils.getNodeXml(response, "Fault")
+ fault = utils.removeXmlPreamble(fault)
+ fault = fault.replace("<Fault>", "").replace("</Fault>", "")
+ fault = fault.replaceAll("\\s+\\s+", "") // Removes extra white spaces
+ buildWorkflowException(execution, resCode, fault)
+ }else if(utils.nodeExists(response, "RESTFault")){
+ String rFault = utils.getNodeXml(response, "RESTFault")
+ buildWorkflowException(execution, resCode, rFault)
+ }else{
+ buildWorkflowException(execution, resCode, "Received a bad response from AAI")
+ }
+ } catch (Exception ex) {
+ utils.log("DEBUG", "Exception Occured during MapAAIExceptionToWorkflowExceptionGeneric: " + ex, isDebugLogEnabled)
+ buildWorkflowException(execution, resCode, "Internal Error - Occured in MapAAIExceptionToWorkflowExceptionGeneric")
+
+ }
+ utils.log("DEBUG", "Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugLogEnabled)
+ utils.log("DEBUG", "Completed MapAAIExceptionToWorkflowExceptionGeneric Process", isDebugLogEnabled)
+ }
+
+ /**
+ * This method takes a WorkflowException Object and builds
+ * WorkflowException Xml. This method should only be used
+ * for the purpose of sending a sync error response or for
+ * creating a FalloutHandler request.
+ *
+ *@param - WorkflowException Object
+ *
+ *@return - String WorkflowException Xml
+ *
+ *
+ */
+ String buildErrorResponseXml(WorkflowException wfex) {
+ String xml
+ if(wfex != null){
+ String mes = XmlEscapers.xmlContentEscaper().escape(wfex.getErrorMessage())
+ int code = wfex.getErrorCode()
+ xml =
+ """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
+ <aetgt:ErrorMessage>${mes}</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>${code}</aetgt:ErrorCode>
+ </aetgt:WorkflowException>"""
+
+ }else{
+ xml =
+ """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
+ <aetgt:ErrorMessage>Internal Error</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>2500</aetgt:ErrorCode>
+ </aetgt:WorkflowException>"""
+ }
+ return xml
+ }
+
+ /*
+ 5000 Received error from A&AI ($A&AI_ERROR) Asynchronous During orchestration of the recipe, A&AI returned an error. The error returned by A&AI is passed through in $A&AI_ERROR.
+ 5010 Could not communicate with A&AI Asynchronous During orchestration of the recipe, a connection with A&AI could not be established.
+ 5020 No response from A&AI Asynchronous During orchestration of the recipe, communication was established with A&AI, but no response was received within the configured timeout.
+ */
+ /**
+ *
+ * Utility Method for MapAAIExceptionToWorkflowException
+ *
+ *@param - String ErrorMessage
+ *
+ *@return - String ErrorCode
+ *
+ */
+ private String MapErrorCode(String errorMessage)
+ {
+ if(errorMessage==null){
+ return '5000'
+ }
+ errorMessage = errorMessage.toLowerCase();
+ if(errorMessage.contains('timed out') || errorMessage.contains('timeout'))
+ return '5020'
+ else if (errorMessage.contains('connection'))
+ return '5010'
+ else
+ return '5000'
+ }
+
+ /**
+ *
+ * Utility Method for MapAAIExceptionToWorkflowException
+ *
+ *@param - String ErrorMessage
+ *@param - String ErrorCode
+ *
+ *@return - String ErrorMessage
+ *
+ */
+ private String MapErrorMessage(String errorMessage, String errorCode)
+ {
+ if(errorMessage == null){
+ errorMessage=""
+ }
+ if( errorCode.equals('5010')){
+ return 'Could not communicate with A&AI'
+ }else if (errorCode.equals('5020')){
+ return 'No response from A&AI'
+ }else{
+ return 'Received error from A&AI (' +errorMessage +')'
+ }
+ }
+
+ /**
+ *
+ * Utility Method for Mapping SDNC
+ * Adapter Response Codes
+ *
+ *@param - String sdncResponseCode
+ *
+ *@return - String code
+ *
+ */
+ String MapSDNCResponseCodeToErrorCode(String sdncResponseCode)
+ {
+ if (sdncResponseCode == '500') {
+ return '5310'
+ } else if ( sdncResponseCode == '408') {
+ return '5320'
+ } else if ( sdncResponseCode == '60010') {
+ return '5350'
+ } else {
+ return '5300'
+ }
+ }
+
+ /**
+ * This error handling method builds a WorkflowException Object. It sets it on
+ * the execution as "WorkflowException".
+ *
+ * @param execution the execution
+ * @param errorCode the error code
+ * @param errorMessage the error message
+ */
+ public void buildWorkflowException(DelegateExecution execution, int errorCode, String errorMessage) {
+ MsoUtils utils = new MsoUtils()
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ String processKey = getProcessKey(execution);
+ utils.log("DEBUG", "Building a WorkflowException for " + processKey, isDebugLogEnabled)
+
+ WorkflowException exception = new WorkflowException(processKey, errorCode, errorMessage);
+ execution.setVariable("WorkflowException", exception);
+ utils.log("DEBUG", "Outgoing WorkflowException is " + exception, isDebugLogEnabled)
+ }
+
+ /**
+ * This error handling method builds a WorkflowException Object and throws a
+ * MSOWorkflowException. It throws a "MSOWorkflowException" BpmnError after
+ * setting the WorkflowException Object on the execution as "WorkflowException".
+ *
+ * @param execution the execution
+ * @param errorCode the error code
+ * @param errorMessage the error message
+ */
+ public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, String errorMessage) {
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ String processKey = getProcessKey(execution);
+ utils.log("Building a WorkflowException for Subflow " + processKey, isDebugLogEnabled)
+
+ WorkflowException exception = new WorkflowException(processKey, errorCode, errorMessage);
+ execution.setVariable("WorkflowException", exception);
+ utils.log("DEBUG", "Outgoing WorkflowException is " + exception, isDebugLogEnabled)
+ utils.log("DEBUG", "Throwing MSOWorkflowException", isDebugLogEnabled)
+ throw new BpmnError("MSOWorkflowException")
+ }
+
+ /**
+ * This method is executed after an MSOWorkflowException is caught by a
+ * subflow (during subflows "Error Handling Sub Process").
+ * It ensures the WorkflowException variable is populated before ending the
+ * subflow and also logs the subflows outgoing WorkflowException Variable.
+ *
+ * @param - execution
+ *
+ */
+ public void processSubflowsBPMNException(DelegateExecution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ String processKey = getProcessKey(execution)
+ try{
+ utils.log("DEBUG", "Started ProcessSubflowsBPMNException Method", isDebugEnabled)
+ if(execution.getVariable("WorkflowException") == null){
+ buildWorkflowException(execution, 2500, "Internal Error - Occured During " + processKey)
+ }
+
+ utils.log("DEBUG", processKey + " Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugEnabled)
+ }catch(Exception e){
+ utils.log("DEBUG", "Caught Exception during ProcessSubflowsBPMNException Method: " + e, isDebugEnabled)
+ }
+ utils.log("DEBUG", "Completed ProcessSubflowsBPMNException Method", isDebugEnabled)
+ }
+
+ /**
+ * This method is executed after an MSOWorkflowException is caught by a
+ * Mainflow. It builds and returns a FalloutHandler Request. It also
+ * verifies the WorkflowException variable is populated.
+ *
+ * @param - execution
+ * @param - requestInfo
+ *
+ * @return - falloutHandlerRequest
+ *
+ */
+ public String processMainflowsBPMNException(DelegateExecution execution, String requestInfo){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ String processKey = getProcessKey(execution)
+ try{
+ utils.log("DEBUG", "Started ProcessMainflowBPMNException Method", isDebugEnabled)
+ if(execution.getVariable("WorkflowException") == null || isBlank(requestInfo)){
+ buildWorkflowException(execution, 2500, "Internal Error - WorkflowException Object and/or RequestInfo is null! " + processKey)
+ }
+ requestInfo = utils.removeXmlPreamble(requestInfo)
+ WorkflowException wfex = execution.getVariable("WorkflowException")
+ String errorMessage = XmlEscapers.xmlContentEscaper().escape(wfex.getErrorMessage())
+ int errorCode = wfex.getErrorCode()
+
+ String falloutHandlerRequest =
+ """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
+ xmlns:ns="http://org.openecomp/mso/request/types/v1"
+ xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
+ ${requestInfo}
+ <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
+ <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
+ </aetgt:WorkflowException>
+ </aetgt:FalloutHandlerRequest>"""
+
+ utils.log("DEBUG", processKey + " Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugEnabled)
+ utils.log("DEBUG", processKey + " Outgoing FalloutHandler Request is: " + falloutHandlerRequest, isDebugEnabled)
+ return falloutHandlerRequest
+
+ }catch(Exception e){
+ utils.log("DEBUG", "Caught Exception during ProcessMainflowBPMNException Method: " + e, isDebugEnabled)
+ return null
+ }
+ utils.log("DEBUG", "Completed ProcessMainflowBPMNException Method", isDebugEnabled)
+ }
+
+ /**
+ *
+ * This method is executed after an Java Exception is caught
+ * It sets the WorkflowException variable. The method can be used in either mainflow or subflows.
+ *
+ * @param - execution
+ *
+ */
+ public void processJavaException(DelegateExecution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ String processKey = getProcessKey(execution)
+ try{
+ utils.log("DEBUG", "Caught a Java Exception in " + processKey, isDebugEnabled)
+ utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
+ buildWorkflowException(execution, 2500, "Catch a Java Lang Exception in " + processKey)
+
+ }catch(BpmnError b){
+ throw b
+ }catch(Exception e){
+ utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
+ buildWorkflowException(execution, 2500, "Internal Error - During Process Java Exception")
+ }
+ utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
+ }
+
+
+ public void preProcessRequest(DelegateExecution execution) {
+ // TODO Auto-generated method stub
+
+ }
+}