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);
        }
Beispiel #2
0
        private static UserMessage CreateMultihopUserMessage(string receivePModeId, SendingProcessingMode pmode)
        {
            var collaboration =
                new Model.Core.CollaborationInfo(
                    new Model.Core.AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: receivePModeId),
                    service: new Model.Core.Service(
                        value: "Forward_Push_Service",
                        type: "eu:europa:services"),
                    action: "Forward_Push_Action",
                    conversationId: "eu:europe:conversation");

            IEnumerable <MessageProperty> properties =
                pmode.MessagePackaging?.MessageProperties?.Select(
                    p => new MessageProperty(p.Name, p.Value, p.Type)) ?? new MessageProperty[0];

            Party p1 = pmode.MessagePackaging?.PartyInfo.FromParty;
            Party p2 = pmode.MessagePackaging?.PartyInfo.ToParty;

            return(new UserMessage(
                       $"multihop-message-id-{Guid.NewGuid()}",
                       collaboration,
                       SendingPModeMap.ResolveSender(p1),
                       SendingPModeMap.ResolveSender(p2),
                       new Model.Core.PartInfo[0],
                       properties));
        }
Beispiel #3
0
        /// <summary>
        /// Start creating a <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));
            }

            if (messagingContext.AS4Message == null)
            {
                throw new InvalidOperationException(
                          $"{nameof(CreateDefaultAS4MessageStep)} requires an AS4Message to assign the default UserMessage to but no AS4Message is present in the MessagingContext");
            }

            SendingProcessingMode pmode = _config.GetSendingPMode(DefaultPmode);

            IEnumerable <PartInfo> parts =
                messagingContext.AS4Message.Attachments.Select(PartInfo.CreateFor);

            UserMessage userMessage =
                SendingPModeMap.CreateUserMessage(pmode, parts.ToArray());

            messagingContext.AS4Message.AddMessageUnit(userMessage);
            messagingContext.SendingPMode = pmode;

            Logger.Info($"{messagingContext.LogTag} Default AS4Message is created using SendingPMode {pmode.Id}");
            return(await StepResult.SuccessAsync(messagingContext));
        }
            public void ThenResolverGetsDefaultService()
            {
                // Arrange
                var pmode = new SendingProcessingMode();

                // Act
                AS4.Model.Core.Service service = SendingPModeMap.ResolveService(pmode);

                // Assert
                Assert.Equal(AS4.Model.Core.Service.TestService, service);
            }
            public void ThenResolverGetsDefaultAction()
            {
                // Arrange
                var pmode = new SendingProcessingMode();

                // Act
                string action = SendingPModeMap.ResolveAction(pmode);

                // Assert
                Assert.Equal(Constants.Namespaces.TestAction, action);
            }
            public void ThenResolverGetService()
            {
                // Arrange
                SendingProcessingMode pmode = CreateDefaultSendingPMode();

                // Act
                AS4.Model.Core.Service actual = SendingPModeMap.ResolveService(pmode);

                // Assert
                var expected = pmode.MessagePackaging.CollaborationInfo.Service;
                Assert.Equal(expected.Value, actual.Value);
                Assert.Equal(Maybe.Just(expected.Type), actual.Type);
            }
            public void ThenResolverGetsAgreementRefWithPModeId()
            {
                // Arrange
                SendingProcessingMode pmode = CreateSendingPMode(includePMode: true);

                // Act
                AS4.Model.Core.AgreementReference agreementRef = SendingPModeMap.ResolveAgreementReference(pmode).UnsafeGet;

                // Assert
                AgreementReference pmodeRef = pmode.MessagePackaging.CollaborationInfo.AgreementReference;

                Assert.Equal(pmodeRef.Value, agreementRef.Value);
                Assert.Equal(Maybe.Just(pmodeRef.Type), agreementRef.Type);
                Assert.Equal(Maybe.Just(pmode.Id), agreementRef.PModeId);
            }
        public Property Then_Receiver_Gets_Populated_When_Present(
            NonEmptyString role,
            NonEmptyString partyId)
        {
            return(Prop.ForAll(
                       ArbParty(role, partyId),
                       p =>
            {
                var actual = SendingPModeMap.ResolveReceiver(p);

                bool isDefault = actual.Equals(CoreParty.DefaultTo);
                bool isResolved = actual.Role == role.Get && actual.PrimaryPartyId == partyId.Get;

                return (isDefault == (p == null)).And(isResolved == (p != null));
            }));
        }
            public void ThenResolverGetsAction()
            {
                // Arrange
                var pmode = new SendingProcessingMode
                {
                    MessagePackaging = { CollaborationInfo = new AS4.Model.PMode.CollaborationInfo {
                                             Action        = "action"
                                         } }
                };

                // Act
                string action = SendingPModeMap.ResolveAction(pmode);

                // Assert
                Assert.Equal(pmode.MessagePackaging.CollaborationInfo.Action, action);
            }
Beispiel #10
0
        private static string ResolveAction(SubmitMessage submit, SendingProcessingMode sendingPMode)
        {
            string submitAction = submit?.Collaboration?.Action;
            string pmodeAction  = sendingPMode?.MessagePackaging?.CollaborationInfo?.Action;

            if (sendingPMode?.AllowOverride == false &&
                !String.IsNullOrEmpty(submitAction) &&
                !String.IsNullOrEmpty(pmodeAction) &&
                !StringComparer.OrdinalIgnoreCase.Equals(submitAction, pmodeAction))
            {
                throw new NotSupportedException(
                          $"SubmitMessage is not allowed by SendingPMode {sendingPMode.Id} to override Action");
            }

            if (!String.IsNullOrEmpty(submitAction))
            {
                return(submit.Collaboration.Action);
            }

            return(SendingPModeMap.ResolveAction(sendingPMode));
        }
Beispiel #11
0
        private static Service ResolveService(SubmitMessage submit, SendingProcessingMode sendingPMode)
        {
            var pmodeService  = sendingPMode?.MessagePackaging?.CollaborationInfo?.Service;
            var submitService = submit?.Collaboration?.Service;

            if (sendingPMode?.AllowOverride == false &&
                !String.IsNullOrEmpty(submitService?.Value) &&
                !String.IsNullOrEmpty(pmodeService?.Value) &&
                !StringComparer.OrdinalIgnoreCase.Equals(submitService.Value, pmodeService.Value))
            {
                throw new NotSupportedException(
                          $"SubmitMessage is not allowed by SendingPMode {sendingPMode.Id} to override CollaborationInfo.Service");
            }

            if (submitService?.Value != null)
            {
                return(new Service(submitService.Value, submitService.Type));
            }

            return(SendingPModeMap.ResolveService(sendingPMode));
        }
Beispiel #12
0
        private static Party ResolveSenderParty(SubmitMessage submit, SendingProcessingMode sendingPMode)
        {
            var pmodeParty  = sendingPMode?.MessagePackaging?.PartyInfo?.FromParty;
            var submitParty = submit?.PartyInfo?.FromParty;

            if (sendingPMode?.AllowOverride == false &&
                submitParty != null &&
                pmodeParty != null &&
                !submitParty.Equals(pmodeParty))
            {
                throw new NotSupportedException(
                          $"SubmitMessage is not allowed by SendingPMode {sendingPMode.Id} to override Sender Party");
            }

            if (submitParty != null)
            {
                var ids = submitParty.PartyIds ?? Enumerable.Empty <Model.Common.PartyId>();
                return(new Party(submitParty.Role, ids.Select(x => new PartyId(x.Id, x.Type)).ToArray()));
            }

            return(SendingPModeMap.ResolveSender(pmodeParty));
        }