示例#1
0
        private void InsertToBeForwardedInMessage(string pmodeId, MessageExchangePattern mep, AS4Message tobeForwarded)
        {
            foreach (MessageUnit m in tobeForwarded.MessageUnits)
            {
                string location =
                    Registry.Instance
                    .MessageBodyStore
                    .SaveAS4Message(
                        _as4Msh.GetConfiguration().InMessageStoreLocation,
                        tobeForwarded);

                var inMessage = new InMessage(m.MessageId)
                {
                    Intermediary = true,
                    Operation    =
                        m.MessageId == tobeForwarded.PrimaryMessageUnit.MessageId
                            ? Operation.ToBeForwarded
                            : Operation.NotApplicable,
                    MessageLocation = location,
                    MEP             = mep,
                    ContentType     = tobeForwarded.ContentType
                };

                ReceivingProcessingMode forwardPMode =
                    _as4Msh.GetConfiguration()
                    .GetReceivingPModes()
                    .First(p => p.Id == pmodeId);

                inMessage.SetPModeInformation(forwardPMode);
                inMessage.SetStatus(InStatus.Received);
                inMessage.AssignAS4Properties(m);
                _databaseSpy.InsertInMessage(inMessage);
            }
        }
        private void InsertUserMessage(string mpc, MessageExchangePattern pattern, Operation operation)
        {
            var sendingPMode = new SendingProcessingMode()
            {
                Id = "SomePModeId",
                MessagePackaging = { Mpc = mpc }
            };

            UserMessage userMessage = SendingPModeMap.CreateUserMessage(sendingPMode);
            AS4Message  as4Message  = AS4Message.Create(userMessage, sendingPMode);

            var om = new OutMessage(userMessage.MessageId)
            {
                MEP             = pattern,
                Mpc             = mpc,
                ContentType     = as4Message.ContentType,
                EbmsMessageType = MessageType.UserMessage,
                Operation       = operation,
                MessageLocation =
                    InMemoryMessageBodyStore.Default.SaveAS4Message(location: "some-location", message: as4Message)
            };

            om.SetPModeInformation(sendingPMode);
            GetDataStoreContext.InsertOutMessage(om);
        }
示例#3
0
        private void InsertUserMessages(
            AS4Message as4Message,
            MessageExchangePattern mep,
            string location,
            SendingProcessingMode pmode)
        {
            if (!as4Message.HasUserMessage)
            {
                Logger.Trace("No UserMessages present to be inserted");
                return;
            }

            IDictionary <string, bool> duplicateUserMessages =
                DetermineDuplicateUserMessageIds(as4Message.UserMessages.Select(m => m.MessageId));

            foreach (UserMessage userMessage in as4Message.UserMessages)
            {
                if (userMessage.IsTest)
                {
                    Logger.Trace($"Incoming UserMessage {userMessage.MessageId} is a 'Test Message'");
                }

                userMessage.IsDuplicate = IsUserMessageDuplicate(userMessage, duplicateUserMessages);

                try
                {
                    InMessage inMessage = InMessageBuilder
                                          .ForUserMessage(userMessage, as4Message, mep)
                                          .WithPMode(pmode)
                                          .OnLocation(location)
                                          .BuildAsToBeProcessed();

                    Logger.Debug(
                        $"Insert InMessage UserMessage {userMessage.MessageId} with {{"
                        + $"Operation={inMessage.Operation}, "
                        + $"Status={inMessage.Status}, "
                        + $"PModeId={pmode?.Id ?? "null"}, "
                        + $"IsTest={userMessage.IsTest}, "
                        + $"IsDuplicate={userMessage.IsDuplicate}}}");

                    _repository.InsertInMessage(inMessage);
                }
                catch (Exception ex)
                {
                    string description = $"Unable to insert UserMessage {userMessage.MessageId}";
                    Logger.Error(description);

                    throw new DataException(description, ex);
                }
            }
        }
示例#4
0
        private void InsertSignalMessages(
            AS4Message as4Message,
            MessageExchangePattern mep,
            string location,
            SendingProcessingMode pmode)
        {
            if (!as4Message.HasSignalMessage)
            {
                Logger.Trace("No SignalMessages present to be inserted");
                return;
            }

            IEnumerable <string> relatedUserMessageIds = as4Message.SignalMessages
                                                         .Select(m => m.RefToMessageId)
                                                         .Where(refToMessageId => !String.IsNullOrWhiteSpace(refToMessageId));

            IDictionary <string, bool> duplicateSignalMessages =
                DetermineDuplicateSignalMessageIds(relatedUserMessageIds);

            foreach (SignalMessage signalMessage in as4Message.SignalMessages.Where(s => !(s is PullRequest)))
            {
                signalMessage.IsDuplicate = IsSignalMessageDuplicate(signalMessage, duplicateSignalMessages);

                try
                {
                    InMessage inMessage = InMessageBuilder
                                          .ForSignalMessage(signalMessage, as4Message, mep)
                                          .WithPMode(pmode)
                                          .OnLocation(location)
                                          .BuildAsToBeProcessed();

                    Logger.Debug(
                        $"Insert InMessage {signalMessage.GetType().Name} {signalMessage.MessageId} with {{"
                        + $"Operation={inMessage.Operation}, "
                        + $"Status={inMessage.Status}, "
                        + $"PModeId={pmode?.Id}}}");

                    _repository.InsertInMessage(inMessage);
                }
                catch (Exception exception)
                {
                    string description = $"Unable to insert SignalMessage {signalMessage.MessageId}";
                    Logger.Error(description);

                    throw new DataException(description, exception);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Inserts a received Message in the DataStore.
        /// For each message-unit that exists in the AS4Message,an InMessage record is created.
        /// The AS4 Message Body is persisted as it has been received.
        /// </summary>
        /// <remarks>The received Message is parsed to an AS4 Message instance.</remarks>
        /// <param name="sendingPMode"></param>
        /// <param name="mep"></param>
        /// <param name="messageBodyStore"></param>
        /// <param name="as4Message"></param>
        /// <param name="originalMessage"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        /// <returns>A MessagingContext instance that contains the parsed AS4 Message.</returns>
        public async Task <AS4Message> InsertAS4MessageAsync(
            AS4Message as4Message,
            ReceivedMessage originalMessage,
            SendingProcessingMode sendingPMode,
            MessageExchangePattern mep,
            IAS4MessageBodyStore messageBodyStore)
        {
            if (as4Message == null)
            {
                throw new ArgumentNullException(nameof(as4Message));
            }

            if (originalMessage == null)
            {
                throw new InvalidOperationException("The MessagingContext must contain a ReceivedMessage");
            }

            if (messageBodyStore == null)
            {
                throw new ArgumentNullException(nameof(messageBodyStore));
            }

            // TODO: should we start the transaction here.
            string location =
                await messageBodyStore.SaveAS4MessageStreamAsync(
                    location : _configuration.InMessageStoreLocation,
                    as4MessageStream : originalMessage.UnderlyingStream).ConfigureAwait(false);

            StreamUtilities.MovePositionToStreamStart(originalMessage.UnderlyingStream);

            try
            {
                InsertUserMessages(as4Message, mep, location, sendingPMode);
                InsertSignalMessages(as4Message, mep, location, sendingPMode);

                return(as4Message);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);

                var service = new ExceptionService(_configuration, _repository, messageBodyStore);
                await service.InsertIncomingExceptionAsync(ex, new MemoryStream(Encoding.UTF8.GetBytes(location)));

                throw;
            }
        }
        public async Task Stores_SignalMessage_With_Expected_Operation_According_To_MEP_And_ReplyPattern(
            MessageExchangePattern mep,
            ReplyPattern reply,
            Operation op)
        {
            // Arrange
            string userMessageId = $"user-{Guid.NewGuid()}";

            GetDataStoreContext.InsertInMessage(
                new InMessage(userMessageId)
            {
                MEP = mep
            });

            var receipt = new Receipt($"receipt-{Guid.NewGuid()}", userMessageId);
            var context = new MessagingContext(
                AS4Message.Create(receipt),
                MessagingContextMode.Receive)
            {
                SendingPMode = new SendingProcessingMode {
                    Id = "shortcut-send-pmode-retrieval"
                },
                ReceivingPMode = new ReceivingProcessingMode
                {
                    ReplyHandling = { ReplyPattern = reply }
                }
            };

            // Act
            await ExerciseStoreSignalMessageAsync(context);

            // Assert
            GetDataStoreContext.AssertOutMessage(
                receipt.MessageId,
                m =>
            {
                Assert.NotNull(m);
                Assert.Equal(op, m.Operation);
            });
        }
示例#7
0
        /// <summary>
        /// Insert a DeadLettered AS4 Error refering a specified <paramref name="ebmsMessageId"/>
        /// for a specified <paramref name="mep"/> notifying only if the specified <paramref name="sendingPMode"/> is configured this way.
        /// </summary>
        /// <param name="ebmsMessageId"></param>
        /// <param name="mep"></param>
        /// <param name="sendingPMode"></param>
        /// <exception cref="ArgumentNullException"></exception>
        internal void InsertDeadLetteredErrorForAsync(
            string ebmsMessageId,
            MessageExchangePattern mep,
            SendingProcessingMode sendingPMode)
        {
            if (ebmsMessageId == null)
            {
                throw new ArgumentNullException(nameof(ebmsMessageId));
            }

            Error errorMessage =
                Error.FromErrorResult(
                    IdentifierFactory.Instance.Create(),
                    ebmsMessageId,
                    new ErrorResult("Missing Receipt", ErrorAlias.MissingReceipt));

            AS4Message as4Message = AS4Message.Create(errorMessage, sendingPMode);

            // We do not use the InMessageService to persist the incoming message here, since this is not really
            // an incoming message.  We create this InMessage in order to be able to notify the Message Producer
            // if he should be notified when a message cannot be sent.
            // (Maybe we should only create the InMessage when notification is enabled ?)
            string location =
                Registry.Instance
                .MessageBodyStore
                .SaveAS4Message(
                    location: Config.Instance.InMessageStoreLocation,
                    message: as4Message);

            InMessage inMessage = InMessageBuilder
                                  .ForSignalMessage(errorMessage, as4Message, mep)
                                  .WithPMode(sendingPMode)
                                  .OnLocation(location)
                                  .BuildAsDeadLetteredError();

            Logger.Debug($"Create Error for missed Receipt with {{Operation={inMessage.Operation}}}");
            _repository.InsertInMessage(inMessage);
        }
示例#8
0
        /// <summary>
        /// Creates a new InMessageBuilder instance that can instantiate an <see cref="InMessage"/> for the received <paramref name="signalMessage"/>
        /// </summary>
        /// <param name="signalMessage"></param>
        /// <param name="belongsToAS4Message"></param>
        /// <param name="mep"></param>
        /// <returns></returns>
        public static InMessageBuilder ForSignalMessage(SignalMessage signalMessage, AS4Message belongsToAS4Message, MessageExchangePattern mep)
        {
            if (signalMessage == null)
            {
                throw new ArgumentNullException(nameof(signalMessage));
            }

            if (belongsToAS4Message == null)
            {
                throw new ArgumentNullException(nameof(belongsToAS4Message));
            }

            return(new InMessageBuilder(signalMessage, belongsToAS4Message.ContentType, mep));
        }
示例#9
0
 private InMessageBuilder(MessageUnit messageUnit, string contentType, MessageExchangePattern mep)
 {
     _messageUnit = messageUnit;
     _contentType = contentType;
     _mep         = mep;
 }