private static void OnMessage(IMessage msg) { //var corId = FdrCommon.ByteArrayToString(msg.JMSCorrelationIDAsBytes); var message = string.Empty; try{ var textMsg = (ITextMessage)msg; message = textMsg.Text; try{ message = FdrCommon.FormatXml(message); } catch (Exception) { ; } var dataValidation = IsCbcValid(message); var header = FdrCommon.SelectNode(message, "soap12", "http://www.w3.org/2003/05/soap-envelope", "Header"); if (header != null) { var messageToSend = dataValidation.IsValid ? CreateXml(header.OuterXml) : FdrCommon.CreateFaultXml(header.OuterXml, dataValidation.ErrorXml); var queueInfo = new QueueInfo { Manager = CBCApplicationConfigurationdetails.ResponseManger, Channel = CBCApplicationConfigurationdetails.ResponseChannel, UseManagerName = false, Port = CBCApplicationConfigurationdetails.ResponsePort, HostName = CBCApplicationConfigurationdetails.ResponseHostName, QueueName = CBCApplicationConfigurationdetails.ResponseQueueName, CorrelationId = msg.JMSMessageID, Message = messageToSend }; FdrMessaging.SendMessageToQueue(queueInfo); if (!dataValidation.IsValid) { return; } } } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } try{ if (!string.IsNullOrEmpty(message)) { SaveIncomingCbcDeclaration(message); } } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } }
private static string CreateXml(string header, string message) { var applicationInformationStructure = new Sars.ESBSchema.ApplicationInformation.v000002.applicationInformation { applicationInformationResult = new Sars.ESBSchema.ApplicationInformation.v000002.applicationInformationApplicationInformationResult[1] }; applicationInformationStructure.applicationInformationResult[0] = new Sars.ESBSchema.ApplicationInformation.v000002.applicationInformationApplicationInformationResult { MessageType = Sars.ESBSchema.ApplicationInformation.v000002.MessageTypeEnum.Information, applicationInformationCode = "0000", applicationInformationDescription = "Processed", applicationInformationState = "OK" }; var applicationInformationStructureXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(applicationInformationStructure, "FDR", "http://www.sars.gov.za/services/esb/v000002/applicationInformation"); var xmlBuilder = new StringBuilder(); xmlBuilder.Append( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " + "<soap12:Envelope xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:esb=\"http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1\">" ); xmlBuilder.AppendFormat( "{0}" + " <soap12:Body>" + "{1}" + "{2}" + "</soap12:Body>" + "</soap12:Envelope>", header, applicationInformationStructureXml, message ); return(FdrCommon.FormatXml(xmlBuilder.ToString())); }
public void ValidateSchema() { if (SchemaList == null || !SchemaList.Any()) { return; } var settings = new XmlReaderSettings(); settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema; settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; SchemaList.ForEach( s => settings.Schemas.Add(s.TargetNamespace, XmlReader.Create(new StringReader(s.SchemaContent)))); settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += settings_ValidationEventHandler; var reader = XmlReader.Create(new StringReader(XmlToValidate), settings); while (reader.Read()) { } if (string.IsNullOrEmpty(ErrorXml)) { IsValid = true; } var errorBuilder = new StringBuilder(); if (_errors.Any()) { errorBuilder.Append("<errors>"); _errors.ForEach(e => errorBuilder.AppendFormat("<Error>{0}</Error>", e)); errorBuilder.Append("</errors>"); ErrorXml = FdrCommon.FormatXml(errorBuilder.ToString()); } IsValid = !_errors.Any(); }
public static string CreateFaultXml(string header, string errors) { var applicationInformationStructure = new Sars.ESBSchema.ApplicationInformation.v31.ApplicationInformationStructure { ApplicationInformationResult = new Sars.ESBSchema.ApplicationInformation.v31.ApplicationInformationStructureApplicationInformationResult[1] }; applicationInformationStructure.ApplicationInformationResult[0] = new Sars.ESBSchema.ApplicationInformation.v31.ApplicationInformationStructureApplicationInformationResult { Code = "9999", Description = errors, MessageType = Sars.ESBSchema.ApplicationInformation.v31.MessageTypeEnum.ERROR }; var applicationInformationStructureXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(applicationInformationStructure, "fdri", "http://www.egovernment.gov.za/GMD/ApplicationInformation/xml/schemas/version/3.1"); var xmlBuilder = new StringBuilder(); xmlBuilder.Append( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " + "<soap12:Envelope xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:esb=\"http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1\">" ); xmlBuilder.AppendFormat( "{0}" + " <soap12:Body>" + "{1}" + "</soap12:Body>" + "</soap12:Envelope>", header, applicationInformationStructureXml ); return(FdrCommon.FormatXml(xmlBuilder.ToString())); }
private static void OnFilesReceived(IMessage msg) { try { var textMsg = (ITextMessage)msg; FdrCommon.SaveMessage(textMsg.Text, @"\\ptadviis06\TaxDirectives\FDR\FILES\IN"); var message = textMsg.Text; var doc = new XmlDocument(); doc.LoadXml(message); var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("soap12", "http://www.w3.org/2003/05/soap-envelope"); ns.AddNamespace("ContMgt", "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8"); var header = doc.SelectSingleNode("//soap12:Header", ns); var request = doc.SelectSingleNode("//ContMgt:ContentManagementRequest", ns); if (header == null || request == null) { FdrCommon.LogEvent("header == null || request == null", EventLogEntryType.Warning); return; } var dataValidation = IsMasterLocalFileRequestValid(message); if (!dataValidation.IsValid) { var xml = FdrCommon.FormatXml(CreateFaultXml(header.OuterXml, dataValidation.ErrorXml)); RespondToDocumentNotify(xml, msg.JMSMessageID); return; } var supportingDocs = Sars.Systems.Serialization.XmlObjectSerializer.ConvertXmlToObject <SupportingDocumentManagementRequestStructure>(request.OuterXml); var xmlToSend = string.Empty; var deserialized = supportingDocs != null && supportingDocs.Contents != null && supportingDocs.Contents.Any(); if (deserialized) { var responseStructure = new SupportingDocumentManagementResponseStructure { Contents = supportingDocs.Contents }; xmlToSend = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(responseStructure, "ContMgt", "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8"); } if (!string.IsNullOrEmpty(xmlToSend)) { var messageToSend = CreateXml(header.OuterXml, xmlToSend); messageToSend = FdrCommon.RemoveEmptyElements(messageToSend); RespondToDocumentNotify(messageToSend, msg.JMSMessageID); } if (deserialized) { if (!supportingDocs.Contents[0].ContentLocation.ToUpper().EndsWith(AppConfig.SecondaryFileLocation)) { var submissionId = ContentManagementRequest(message); if (submissionId > 0) { SendNotification(submissionId); } } } } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } }