From 86c09b9e23e7f41019eb4b70a0f95e6f7dbeb7bb Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 8 Apr 2019 09:55:48 -0400 Subject: SDNHandler callback correlation issue. SDNHandler callback correlation issue. Should not go back to waiting for callback when final_indicator=Y is receibed in callback. Raise an error when responseCode in callback mesage is not 200. Change-Id: Ia55ab5a9bafdfe877a1221b67d5f3258039a3900 Issue-ID: SO-1761 Signed-off-by: Benjamin, Max (mb388a) --- .../subprocess/BuildingBlock/SDNCHandler.bpmn | 70 +++++++++++----------- .../exceptions/SDNCErrorResponseException.java | 13 ++++ .../sdnc/tasks/SDNCRequestTasks.java | 33 +++++++++- .../sdnc/tasks/SDNCRequestTasksTest.java | 25 +++++++- .../test/resources/__files/SDNC_Async_Request2.xml | 11 ++++ 5 files changed, 115 insertions(+), 37 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/exceptions/SDNCErrorResponseException.java create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Async_Request2.xml (limited to 'bpmn') diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/SDNCHandler.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/SDNCHandler.bpmn index 0be7c55596..7339b23802 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/SDNCHandler.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/SDNCHandler.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1n0j3hz @@ -38,7 +38,7 @@ SequenceFlow_1yifu46 - + ${execution.getVariable("sdncTimeout")} @@ -48,7 +48,7 @@ SequenceFlow_0i4u8g4 - + ${execution.getVariable("isCallbackCompleted") == false} @@ -62,7 +62,7 @@ - + ${execution.getVariable("isSDNCCompleted")} SequenceFlow_1n0j3hz @@ -72,7 +72,7 @@ SequenceFlow_1yifu46 - + @@ -118,23 +118,23 @@ - - + + - - + + - - - + + + @@ -146,23 +146,23 @@ - - - + + + - - + + - - + + @@ -174,47 +174,47 @@ - - - - - + + + + + - - + + - - + + - - + + - - - + + + - - + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/exceptions/SDNCErrorResponseException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/exceptions/SDNCErrorResponseException.java new file mode 100644 index 0000000000..e0f88a20a5 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/exceptions/SDNCErrorResponseException.java @@ -0,0 +1,13 @@ +package org.onap.so.bpmn.infrastructure.sdnc.exceptions; + +public class SDNCErrorResponseException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 7807799223298140702L; + + public SDNCErrorResponseException(String message) { + super(message); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java index a4ef28496e..24f642ae72 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java @@ -20,7 +20,15 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.sdnc.exceptions.SDNCErrorResponseException; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.exception.MapperException; @@ -31,6 +39,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.PathNotFoundException; @@ -44,6 +54,7 @@ public class SDNCRequestTasks { private static final String MESSAGE = "_MESSAGE"; private static final String CORRELATOR = "_CORRELATOR"; protected static final String IS_CALLBACK_COMPLETED = "isCallbackCompleted"; + protected static final String SDNC_SUCCESS = "200"; @Autowired private ExceptionBuilder exceptionBuilder; @@ -82,9 +93,24 @@ public class SDNCRequestTasks { try { SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST); String asyncRequest = (String) execution.getVariable(request.getCorrelationName()+MESSAGE); - String finalMessageIndicator = JsonPath.read(asyncRequest, "$.input.ack-final-indicator"); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance (); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new InputSource(new StringReader(asyncRequest))); + + String finalMessageIndicator = getXmlElement(doc, "/input/ack-final-indicator"); boolean isCallbackCompleted = convertIndicatorToBoolean(finalMessageIndicator); execution.setVariable(IS_CALLBACK_COMPLETED, isCallbackCompleted); + if(isCallbackCompleted) { + String responseCode = getXmlElement(doc, "/input/response-code"); + String responseMessage = getXmlElement(doc, "/input/response-message"); + if(!SDNC_SUCCESS.equalsIgnoreCase(responseCode)) { + throw new SDNCErrorResponseException(responseMessage); + } + } + } catch (SDNCErrorResponseException e) { + logger.error("SDNC error response - " + e.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage()); } catch (Exception e) { logger.error("Error procesing SDNC callback", e); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error procesing SDNC callback"); @@ -99,4 +125,9 @@ public class SDNCRequestTasks { return "Y".equals(finalMessageIndicator); } + protected String getXmlElement(Document doc, String exp) throws Exception { + XPath xPath = XPathFactory.newInstance().newXPath(); + return xPath.evaluate(exp, doc); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java index f1779cf119..043aad43b1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java @@ -27,9 +27,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.IOException; +import java.io.StringReader; import java.nio.file.Files; import java.nio.file.Paths; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -51,6 +55,8 @@ import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCRequest; import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -131,12 +137,29 @@ public class SDNCRequestTasksTest extends SDNCRequestTasks{ @Test public void processCallBack_Final_Test() throws MapperException, BadResponseException, IOException{ - final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_ASYNC_Request.json"))); + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_Async_Request2.xml"))); delegateExecution.setVariable("correlationName_MESSAGE", sdncResponse); sndcRequestTasks.processCallback(delegateExecution); assertEquals(true,delegateExecution.getVariable(IS_CALLBACK_COMPLETED)); } + @Test + public void getXmlElementTest() throws Exception { + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_Async_Request2.xml"))); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance (); + DocumentBuilder db; + db = dbf.newDocumentBuilder (); + Document doc = db.parse (new InputSource(new StringReader(sdncResponse))); + + String finalMessageIndicator = getXmlElement(doc, "/input/ack-final-indicator"); + String responseCode = getXmlElement(doc, "/input/response-code"); + String responseMessage = getXmlElement(doc, "/input/response-message"); + + assertEquals("Y", finalMessageIndicator); + assertEquals("200", responseCode); + assertEquals("Success", responseMessage); + } + public SDNCRequest createSDNCRequest(){ SDNCRequest request = new SDNCRequest(); request.setCorrelationName("correlationName"); diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Async_Request2.xml b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Async_Request2.xml new file mode 100644 index 0000000000..aa69dba803 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Async_Request2.xml @@ -0,0 +1,11 @@ + + + + MY-SERVICE-TYPE + b8308928-de76-4ce6-9e58-ec6033ff43b3 + + aa243891-4575-4040-bceb-25d5b7bc8c61 + 200 + Success + Y + -- cgit 1.2.3-korg