Quotes

Wednesday, October 19, 2016

Common Error Hanlding



BROKER SCHEMA gen

--CREATE PROCEDURE getUserDefinedPropertyValue(in prop char) RETURNS CHARACTER
--LANGUAGE JAVA
--EXTERNAL NAME "com.thomsonreuters.IIB.Utils.getProperty";



CREATE COMPUTE MODULE CommonWebServiceErrorHandler_CreateFAULTMessage
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
LOG EVENT SEVERITY 3 VALUES ('******** IIB Debug Entry *********',
                            'Consumerid = ' || InputRoot.HTTPInputHeader.Consumerid,
                            'Contextid = ' || InputRoot.HTTPInputHeader.Contextid,
                            'Firmid = ' || InputRoot.HTTPInputHeader.Firmid,
                            'Internalreferencid = ' || InputRoot.HTTPInputHeader.Internalreferenceid);

SET Environment.Variables.ErrorProcessFlag = 'Y';

DECLARE exceptionNumber INT;
DECLARE errorText CHARACTER;
DECLARE ns NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
SET OutputRoot.Properties = InputRoot.Properties;
SET OutputLocalEnvironment = InputLocalEnvironment;
CALL getLastExceptionDetail(InputExceptionList, exceptionNumber, errorText);

SET OutputRoot.MQMD.Format = MQFMT_STRING;

DECLARE lastChildName, HTMLHeader CHARACTER;

SET lastChildName = FIELDNAME(InputRoot.*[<]);
SET HTMLHeader    = FIELDNAME(InputRoot.XMLNSC.*[<]);

--DECLARE REF_InnerException REFERENCE TO InputExceptionList.*[1];
DECLARE CH_ExceptionType CHARACTER FIELDNAME(InputExceptionList.RecoverableException.*[12]);
--SET CH_ExceptionType = FIELDNAME(InputExceptionList.*[1]);

IF lastChildName = 'SOAP' THEN
  IF exceptionNumber <> '5025' THEN
IF InputRoot.SOAP.Body.*[>].*:Header.*[>] IS NOT NULL THEN
SET OutputLocalEnvironment.Variables.Header = InputRoot.SOAP.Body.*[>].*:Header;
ELSE
IF EXISTS(InputRoot.SOAP.Header.*[]) THEN
SET OutputLocalEnvironment.Variables.Header = InputRoot.SOAP.Header;
ELSE
        SET OutputLocalEnvironment.Variables.Header = 'No Header Specified';
END IF;
END IF;
  ELSE
    SET OutputLocalEnvironment.Variables.Header = 'No Header Specified';
  END IF;

ELSE
IF lastChildName = 'JSON' THEN
IF EXISTS(InputRoot.JSON.Data.Header.*[]) THEN
SET OutputLocalEnvironment.Variables.Header = InputRoot.JSON.Data.Header;
ELSE
SET OutputLocalEnvironment.Variables.Header = 'No Header Specified';
END IF;
ELSE
IF lastChildName = 'XMLNSC' THEN
IF HTMLHeader ='html' THEN
RETURN FALSE;
END IF;
IF InputRoot.XMLNSC.*[>].*:Header.*[>] IS NOT NULL THEN
SET OutputLocalEnvironment.Variables.Header = InputRoot.XMLNSC.*[>].*:Header;
ELSE
IF InputLocalEnvironment.SOAP.Input.Message IS NULL OR
        InputLocalEnvironment.SOAP.Input.Message.Header IS NULL OR
        InputLocalEnvironment.SOAP.Input.Message.Header.*[>] IS NULL THEN
SET OutputLocalEnvironment.Variables.Header = 'No Header Specified';
ELSE
SET OutputLocalEnvironment.Variables.Header = InputLocalEnvironment.SOAP.Input.Message.Header;
END IF;
END IF;
END IF;
END IF;
END IF;

-- save for use after Propogate to MQ (OUT1 terminal)
SET Environment.Variables.ErrorNumber                  = exceptionNumber;

SET OutputRoot.XMLNSC.ErrorDetails.InputHeader         = OutputLocalEnvironment.Variables.Header;
IF exceptionNumber = '5025' THEN
SET OutputRoot.XMLNSC.ErrorDetails.InputBody       = 'No Message body created due to the parsing exception';
ELSE
SET OutputRoot.XMLNSC.ErrorDetails.InputBody       = GetMessageAsCharacters(InputRoot);
END IF;
SET OutputRoot.XMLNSC.ErrorDetails.FirmId              = InputRoot.HTTPInputHeader.Firmid;
SET OutputRoot.XMLNSC.ErrorDetails.InternalReferenceId = InputRoot.HTTPInputHeader.Internalreferenceid;
SET OutputRoot.XMLNSC.ErrorDetails.ErrorNumber         = exceptionNumber;
SET OutputRoot.XMLNSC.ErrorDetails.ErrorText           = errorText;
SET OutputRoot.XMLNSC.ErrorDetails.MessageDomain       = lastChildName;
SET OutputRoot.XMLNSC.ErrorDetails.ExceptionList       = InputExceptionList;


-- send the soap envelope along with error details to MQ (OUT1 terminal)
Propagate TO TERMINAL 'out1';

-- Send the soap fault to OUT terminal
SET OutputRoot.MQMD = NULL;
SET OutputRoot.XMLNSC = NULL;
SET OutputRoot.HTTPInputHeader    = InputRoot.HTTPInputHeader;
SET OutputRoot.HTTPResponseHeader = InputRoot.HTTPInputHeader;
SET OutputExceptionList           = InputExceptionList;

-- Accessing the informaton in exception text to form the SOAP fault message.
IF lastChildName = 'SOAP' OR lastChildName = 'XMLNSC' THEN
SET OutputRoot.SOAP.Context.Namespace.(SOAP.NamespaceDecl)xmlns:soapenv = ns;
SET OutputRoot.SOAP.Body.ns:Fault.faultcode            = CAST(Environment.Variables.ErrorNumber AS CHARACTER);
SET OutputRoot.SOAP.Body.ns:Fault.faultstring          = 'Problem encountered while processing message.  Please contact Customer Service';
SET OutputRoot.SOAP.Body.ns:Fault.faultactor           = 'Error';
SET OutputRoot.SOAP.Body.ns:Fault.detail               = '';

    IF InputRoot.HTTPInputHeader.Debugflag = 'True' OR
  Environment.Variables.HTTPInputHeader.Debugflag = 'True' THEN
SET OutputRoot.SOAP.Body.ns:Fault.detail           = InputExceptionList;
ELSE
         IF InputRoot.HTTPInputHeader.Debugflag = 'False' OR
      Environment.Variables.HTTPInputHeader.Debugflag = 'False' THEN
   SET OutputRoot.SOAP.Body.ns:Fault.detail       = '';
ELSE  
   --  IF getUserDefinedPropertyValue('DebugFlag') = 'true' THEN
   SET OutputRoot.SOAP.Body.ns:Fault.detail   = InputExceptionList;
  -- ELSE
   -- SET OutputRoot.SOAP.Body.ns:Fault.detail   = '';
    -- END IF;
   END IF;
   END IF;
   END IF;

-- Accessing the informaton in exception text to form the JSON fault message
IF lastChildName = 'JSON' THEN
SET OutputRoot.JSON.Data.Message.Code                  = CAST(Environment.Variables.ErrorNumber AS CHARACTER);
        SET OutputRoot.JSON.Data.Message.Description       = 'Problem encountered while processing message.  Please contact Customer Service';
SET OutputRoot.JSON.Data.Message.SeverityLevel         = 'Error';

    IF InputRoot.HTTPInputHeader.Debugflag = 'True' OR
  Environment.Variables.HTTPInputHeader.Debugflag = 'True' THEN
SET OutputRoot.JSON.Data.Message.Fields            = InputExceptionList;
ELSE
         IF InputRoot.HTTPInputHeader.Debugflag = 'False' OR
      Environment.Variables.HTTPInputHeader.Debugflag = 'False' THEN
   SET OutputRoot.JSON.Data.Message.Fields        = '';
ELSE  
  --    IF getUserDefinedPropertyValue('DebugFlag') = 'true' THEN
   SET OutputRoot.JSON.Data.Message.Fields    = InputExceptionList;
--   ELSE
 --      SET OutputRoot.JSON.Data.Message.Fields    = '';
   --  END IF;
   END IF;
END IF;
END IF;
RETURN TRUE;
END;

END MODULE;

No comments:

Post a Comment