Beispiel #1
0
        private async Task <AS4Message> ParseStreamToAS4MessageAsync(
            Stream inputStream,
            string contentType,
            CancellationToken cancellationToken)
        {
            if (inputStream == null)
            {
                throw new ArgumentNullException(nameof(inputStream));
            }

            List <MimePart> bodyParts      = TryParseBodyParts(inputStream, cancellationToken);
            Stream          envelopeStream = bodyParts.First().ContentObject?.Open();

            AS4Message message = await _soapSerializer
                                 .DeserializeAsync(envelopeStream, contentType, cancellationToken).ConfigureAwait(false);

            foreach (var userMessage in message.UserMessages)
            {
                IEnumerable <PartInfo> referencedPartInfos =
                    userMessage.PayloadInfo ?? Enumerable.Empty <PartInfo>();

                IEnumerable <Attachment> attachments = BodyPartsAsAttachments(bodyParts, referencedPartInfos);
                message.AddAttachments(attachments);
            }

            return(message);
        }
Beispiel #2
0
        private DeliverMessageEnvelope CreateDeliverMessageEnvelope(AS4Message as4Message, bool includeAttachments)
        {
            UserMessage deliverMessage = CreateMinderDeliverMessage(as4Message);

            // The Minder Deliver Message should be an AS4-Message.
            AS4Message msg = AS4Message.Create(deliverMessage);

            if (includeAttachments)
            {
                msg.AddAttachments(as4Message.Attachments);
            }

            byte[] content = SerializeAS4Message(msg);

            return(new DeliverMessageEnvelope(
                       message: new DeliverMessage
            {
                MessageInfo = new MessageInfo
                {
                    MessageId = deliverMessage.MessageId,
                    RefToMessageId = deliverMessage.RefToMessageId
                },
                Payloads = msg.FirstUserMessage.PayloadInfo.Select(CreateDeliverPayload).ToArray()
            },
                       deliverMessage: content,
                       contentType: msg.ContentType,
                       attachments: as4Message.UserMessages.SelectMany(um => as4Message.Attachments.Where(a => a.MatchesAny(um.PayloadInfo)))));
        }
        public async Task Deliver_Bundled_UserMessage_As_Different_DeliverMessages()
        {
            // Arrange
            var attachmentPdf = new Attachment("pdf", new MemoryStream(pdf_document), "application/pdf");
            var userMessage1  = new UserMessage(
                $"user1-{Guid.NewGuid()}",
                new CollaborationInfo(
                    new AgreementReference("http://eu.europe.org/bundled")),
                Party.DefaultFrom,
                Party.DefaultTo,
                new [] { PartInfo.CreateFor(attachmentPdf) },
                Enumerable.Empty <MessageProperty>());

            var attachmentImage = new Attachment("earth", new MemoryStream(earth), "image/jpg");
            var userMessage2    = new UserMessage(
                $"user2-{Guid.NewGuid()}",
                new CollaborationInfo(
                    Maybe <AgreementReference> .Nothing,
                    new Service("http://eu.europe.org/service"),
                    "http://eu.europe.org/action",
                    conversationId: "7881"),
                Party.DefaultFrom,
                Party.DefaultTo,
                new [] { PartInfo.CreateFor(attachmentImage) },
                Enumerable.Empty <MessageProperty>());

            AS4Message as4Message = AS4Message.Create(new [] { userMessage1, userMessage2 });

            as4Message.AddAttachments(new[] { attachmentPdf, attachmentImage });

            FileSystemUtils.ClearDirectory(DeliveryRoot);

            // Act
            await InsertToBeDeliveredMessagesAsync(as4Message);

            // Assert
            await PollUntilPresent(
                () => Directory.GetFiles(DeliveryRoot, $"{userMessage1.MessageId}.xml").FirstOrDefault(),
                timeout : TimeSpan.FromSeconds(25));

            await PollUntilPresent(
                () => Directory.GetFiles(DeliveryRoot, $"{userMessage2.MessageId}.xml").FirstOrDefault(),
                timeout : TimeSpan.FromSeconds(25));
        }
        private static AS4Message TransformMinderSubmitToAS4Message(UserMessage submitMessage, IEnumerable <Attachment> attachments)
        {
            var userMessage = new UserMessage(
                messageId: GetPropertyValue(submitMessage.MessageProperties, "MessageId"),
                refToMessageId: GetPropertyValue(submitMessage.MessageProperties, "RefToMessageId"),
                mpc: submitMessage.Mpc,
                timestamp: DateTimeOffset.Now,
                collaboration: GetCollaborationFromProperties(submitMessage.MessageProperties),
                sender: GetSenderFromSender(submitMessage),
                receiver: GetReceiverFromProperties(submitMessage),
                partInfos: submitMessage.PayloadInfo,
                messageProperties: WhiteListedMessageProperties(submitMessage.MessageProperties));

            AS4Message result = AS4Message.Create(userMessage);

            result.AddAttachments(attachments);

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Start Mapping from a <see cref="SubmitMessage"/>
        /// to an <see cref="AS4Message"/>
        /// </summary>
        /// <param name="messagingContext"></param>
        /// <returns></returns>
        public async Task <StepResult> ExecuteAsync(MessagingContext messagingContext)
        {
            if (messagingContext == null)
            {
                throw new ArgumentNullException(nameof(messagingContext));
            }

            SubmitMessage submitMessage = messagingContext.SubmitMessage;

            if (submitMessage == null)
            {
                throw new InvalidOperationException(
                          $"{nameof(CreateAS4MessageStep)} requires a SubmitMessage to create an AS4Message from but no AS4Message is present in the MessagingContext");
            }

            if (messagingContext.SendingPMode == null)
            {
                Logger.Debug("No SendingPMode was found, only use information from SubmitMessage to create AS4 UserMessage");
            }

            ValidateSubmitMessage(submitMessage);

            Logger.Trace("Create UserMessage for SubmitMessage");
            UserMessage userMessage = SubmitMessageMap.CreateUserMessage(submitMessage, submitMessage.PMode);

            Logger.Info($"{messagingContext.LogTag} UserMessage with Id \"{userMessage.MessageId}\" created from SubmitMessage");
            AS4Message as4Message = AS4Message.Create(userMessage, messagingContext.SendingPMode);

            IEnumerable <Attachment> attachments =
                await RetrieveAttachmentsForAS4MessageAsync(submitMessage.Payloads)
                .ConfigureAwait(false);

            as4Message.AddAttachments(attachments);

            messagingContext.ModifyContext(as4Message);
            return(StepResult.Success(messagingContext));
        }