コード例 #1
0
        private static async Task StoreToBeSentUserMessage(string mpc)
        {
            var submit = new SubmitMessage
            {
                MessageInfo   = new MessageInfo(messageId: null, mpc: mpc),
                Collaboration =
                {
                    AgreementRef =
                    {
                        PModeId  = "pullsendagent-pmode"
                    }
                }
            };

            await SubmitMessageToSubmitAgent(AS4XmlSerializer.ToString(submit));
        }
コード例 #2
0
        public async Task MultihopUserMessageStillContainsMultihopHeadersWhenSerializeDeserializedMessage()
        {
            // Arrange
            var          input       = new MemoryStream(as4_multihop_usermessage);
            const string contentType =
                "multipart/related; boundary=\"=-AAB+iUI3phXyeG3w4aGnFA==\";\ttype=\"application/soap+xml\"";

            ISerializer sut          = SerializerProvider.Default.Get(contentType);
            AS4Message  deserialized = await sut.DeserializeAsync(input, contentType);

            // Act
            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(deserialized, CancellationToken.None);

            // Assert
            AssertUserMessageMultihopHeaders(doc);
        }
コード例 #3
0
        public async Task ReceiptMessageForNonMultiHopMessageIsNotMultiHop()
        {
            AS4Message as4Message = await CreateReceivedAS4Message(CreateNonMultiHopPMode());

            var receipt = Receipt.CreateFor($"receipt-{Guid.NewGuid()}", as4Message.FirstUserMessage, as4Message.IsMultiHopMessage);

            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(receipt), CancellationToken.None);

            // No MultiHop related elements may be present:
            // - No Action element in the wsa namespace
            // - No UserElement in the multihop namespace.
            // - No RoutingInput node
            Assert.False(ContainsActionElement(doc));
            Assert.False(ContainsUserMessageElement(doc));
            Assert.Null(doc.UnsafeSelectEbmsNode("/s12:Envelope/s12:Header/mh:RoutingInput"));
        }
コード例 #4
0
            private async Task <MessagingContext> OnMessageReceived(
                ReceivedMessage receivedMessage,
                CancellationToken cancellationToken)
            {
                var actualPMode = await AS4XmlSerializer.FromStreamAsync <SendingProcessingMode>(receivedMessage.UnderlyingStream);

                Assert.Equal("01-pmode", actualPMode.Id);

                if (_seriewatch.TrackSerie(maxSerieCount: 3))
                {
                    Assert.True(_seriewatch.GetSerie(1) > _seriewatch.GetSerie(0));
                    _waitHandle.Set();
                }

                return(new EmptyMessagingContext());
            }
コード例 #5
0
        private static string CreateErrorInformationString(Error error)
        {
            if (error.ErrorLines == null || error.ErrorLines.Any() == false)
            {
                return(null);
            }

            XmlDocument soapEnv =
                AS4XmlSerializer.ToSoapEnvelopeDocument(
                    AS4Message.Create(error),
                    CancellationToken.None);

            XmlNode signalNode = soapEnv.SelectSingleNode("//*[local-name()='SignalMessage']");

            return(signalNode?.OuterXml);
        }
コード例 #6
0
            private static async Task <SendingProcessingMode> ExerciseSerializeDeserialize(SendingProcessingMode pmode)
            {
                using (Stream str = await AS4XmlSerializer.ToStreamAsync(pmode))
                    using (var memoryStream = new MemoryStream())
                    {
                        str.CopyTo(memoryStream);
                        memoryStream.Position = 0;

                        using (var streamReader = new StringReader(Encoding.UTF8.GetString(memoryStream.ToArray())))
                            using (XmlReader reader = XmlReader.Create(streamReader))
                            {
                                var xmlSerializer = new XmlSerializer(typeof(SendingProcessingMode));
                                return(xmlSerializer.Deserialize(reader) as SendingProcessingMode);
                            }
                    }
            }
コード例 #7
0
        public async Task OutMessageIsCreatedForPrimaryMessageUnitOfToBeForwardedAS4Message()
        {
            // Arrange
            const string primaryMessageId = "primary-message-id";
            const string secondMessageId  = "secondary-message-id";

            var primaryUserMessage   = CreateForwardPushUserMessage(primaryMessageId);
            var secondaryUserMessage = new UserMessage(secondMessageId);

            var as4Message = AS4Message.Create(primaryUserMessage);

            as4Message.AddMessageUnit(secondaryUserMessage);

            // Act
            InsertToBeForwardedInMessage(
                pmodeId: "Forward_Push",
                mep: MessageExchangePattern.Push,
                tobeForwarded: as4Message);

            // Assert: if an OutMessage is created with the correct status and operation.
            InMessage primaryInMessage = await PollUntilPresent(
                () => _databaseSpy.GetInMessageFor(
                    m => m.EbmsMessageId == primaryMessageId &&
                    m.Operation == Operation.Forwarded),
                TimeSpan.FromSeconds(20));

            Assert.NotNull(AS4XmlSerializer.FromString <ReceivingProcessingMode>(primaryInMessage.PMode));

            await PollUntilPresent(
                () => _databaseSpy.GetInMessageFor(m => m.EbmsMessageId == secondMessageId),
                timeout : TimeSpan.FromSeconds(20));

            Assert.Equal(Operation.Forwarded, primaryInMessage.Operation);
            Assert.NotNull(AS4XmlSerializer.FromString <ReceivingProcessingMode>(primaryInMessage.PMode));

            OutMessage primaryOutMessage = await PollUntilPresent(
                () => _databaseSpy.GetOutMessageFor(m => m.EbmsMessageId == primaryMessageId),
                timeout : TimeSpan.FromSeconds(5));

            Assert.Equal(Operation.ToBeProcessed, primaryOutMessage.Operation);
            Assert.NotNull(AS4XmlSerializer.FromString <SendingProcessingMode>(primaryOutMessage.PMode));

            OutMessage secondaryOutMessage = _databaseSpy.GetOutMessageFor(m => m.EbmsMessageId == secondMessageId);

            Assert.Null(secondaryOutMessage);
        }
コード例 #8
0
            public async Task ThenBuildInMessageSucceedsWithAS4MessageAndMessageUnit()
            {
                // Arrange
                AS4Message as4Message = AS4Message.Empty;
                Receipt    receipt    = CreateReceiptMessageUnit();

                // Act
                InMessage inMessage =
                    InMessageBuilder.ForSignalMessage(receipt, as4Message, MessageExchangePattern.Push)
                    .WithPMode(new SendingProcessingMode())
                    .BuildAsToBeProcessed();

                // Assert
                Assert.NotNull(inMessage);
                Assert.Equal(as4Message.ContentType, inMessage.ContentType);
                Assert.Equal(await AS4XmlSerializer.ToStringAsync(new SendingProcessingMode()), inMessage.PMode);
                Assert.Equal(MessageType.Receipt, inMessage.EbmsMessageType);
            }
コード例 #9
0
        public void Then_Parties_Are_Filled_When_Defined()
        {
            // Arrange
            var pmode = new PartyInfo {
                FromParty = CreateFilledParty(), ToParty = CreateFilledParty()
            };

            // Act
            string xml = AS4XmlSerializer.ToString(pmode);

            // Assert
            var doc = new XmlDocument();

            doc.LoadXml(xml);

            Assert.NotNull(doc.SelectSingleNode("/PartyInfo/FromParty"));
            Assert.NotNull(doc.SelectSingleNode("/PartyInfo/ToParty"));
        }
コード例 #10
0
        public async void ReceiptMessageForMultihopUserMessageIsMultihop()
        {
            AS4Message as4Message = await CreateReceivedAS4Message(CreateMultiHopPMode());

            var receipt = Receipt.CreateFor($"receipt-{Guid.NewGuid()}", as4Message.FirstUserMessage, as4Message.IsMultiHopMessage);

            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(receipt), CancellationToken.None);

            // Following elements should be present:
            // - To element in the wsa namespace
            // - Action element in the wsa namespace
            // - UserElement in the multihop namespace.
            AssertToElement(doc);
            Assert.True(ContainsActionElement(doc));
            Assert.True(ContainsUserMessageElement(doc));
            AssertUserMessageMessagingElement(as4Message, doc);

            AssertIfSenderAndReceiverAreReversed(as4Message, doc);
        }
コード例 #11
0
        private static void AssertIfSenderAndReceiverAreReversed(AS4Message expectedAS4Message, XmlNode doc)
        {
            XmlNode routingInputNode = doc.UnsafeSelectEbmsNode("/s12:Envelope/s12:Header/mh:RoutingInput");

            Assert.NotNull(routingInputNode);
            var routingInput = AS4XmlSerializer.FromString <RoutingInput>(routingInputNode.OuterXml);

            RoutingInputUserMessage actualUserMessage   = routingInput.UserMessage;
            UserMessage             expectedUserMessage = expectedAS4Message.FirstUserMessage;

            Assert.Equal(expectedUserMessage.Sender.Role, actualUserMessage.PartyInfo.To.Role);
            Assert.Equal(
                expectedUserMessage.Sender.PartyIds.First().Id,
                actualUserMessage.PartyInfo.To.PartyId.First().Value);
            Assert.Equal(expectedUserMessage.Receiver.Role, actualUserMessage.PartyInfo.From.Role);
            Assert.Equal(
                expectedUserMessage.Receiver.PartyIds.First().Id,
                actualUserMessage.PartyInfo.From.PartyId.First().Value);
        }
コード例 #12
0
        /// <summary>
        /// Gets the name of the receiving by.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public Task <ReceivingBasePmode> GetReceivingByName(string name)
        {
            return(Task
                   .Factory
                   .StartNew(() =>
            {
                var pmode = SafeGetReceivingPMode(name);
                if (pmode != null)
                {
                    return new ReceivingBasePmode
                    {
                        Name = pmode.Id,
                        Type = PmodeType.Receiving,
                        Pmode = pmode,
                        Hash = AS4XmlSerializer.ToString(pmode).GetMd5Hash()
                    };
                }

                return null;
            }));
        }
コード例 #13
0
        public async Task ErrorMessageForMultihopUserMessageIsMultihop()
        {
            // Arrange
            AS4Message expectedAS4Message = await CreateReceivedAS4Message(CreateMultiHopPMode());

            var error = Error.CreateFor($"error-{Guid.NewGuid()}", expectedAS4Message.FirstUserMessage, userMessageSendViaMultiHop: true);

            // Act
            XmlDocument document = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(error), CancellationToken.None);

            // Following elements should be present:
            // - To element in the wsa namespace
            // - Action element in the wsa namespace
            // - UserElement in the multihop namespace.
            AssertToElement(document);
            Assert.True(ContainsActionElement(document));
            Assert.True(ContainsUserMessageElement(document));

            AssertMessagingElement(document);
            AssertIfSenderAndReceiverAreReversed(expectedAS4Message, document);
        }
コード例 #14
0
        /// <summary>
        /// Insert an <see cref="InException"/> based on an exception that occurred dring the incoming Submit operation.
        /// </summary>
        /// <param name="exception">The exception which message will be inserted.</param>
        /// <param name="submit">The original message that caused the exception.</param>
        /// <param name="pmode">The PMode that was being used during the Submit operation.</param>
        public async Task <InException> InsertIncomingSubmitExceptionAsync(
            Exception exception,
            SubmitMessage submit,
            ReceivingProcessingMode pmode)
        {
            Stream stream = await AS4XmlSerializer.ToStreamAsync(submit);

            string location = await _bodyStore.SaveAS4MessageStreamAsync(
                _config.InExceptionStoreLocation,
                stream);

            InException entity =
                InException
                .ForMessageBody(messageLocation: location, exception: exception)
                .SetOperationFor(pmode?.ExceptionHandling);

            await entity.SetPModeInformationAsync(pmode);

            _repository.InsertInException(entity);

            return(entity);
        }
コード例 #15
0
        /// <summary>
        /// Puts a message with a single payload to the Holodeck endpoint referencing the given <paramref name="pmodeId"/>.
        /// </summary>
        /// <param name="pmodeId">The pmode id the message should have as reference.</param>
        public void PutMessageSinglePayloadToHolodeckB(string pmodeId)
        {
            var msg = new MessageMetaData
            {
                CollaborationInfo = new HolodeckCollaborationInfo
                {
                    AgreementRef = new HolodeckAgreementRef {
                        PMode = pmodeId
                    },
                    ConversationId = "org:holodeckb2b:test:conversation"
                },
                PayloadInfo = new HolodeckPayloadInfo
                {
                    PartInfo = new[] { SubmitImagePayload }
                }
            };

            string xml  = AS4XmlSerializer.ToString(msg);
            string path = Path.Combine(HolodeckBLocations.OutputPath, $"{pmodeId}-sample.mmd");

            File.WriteAllText(path, xml);
        }
コード例 #16
0
        private async Task <NotifyMessageEnvelope> CreateMinderNotifyMessageEnvelope(
            AS4Message as4Message, Type receivedEntityMessageType)
        {
            UserMessage   userMessage   = as4Message.FirstUserMessage;
            SignalMessage signalMessage = as4Message.FirstSignalMessage;

            if (userMessage == null && signalMessage != null)
            {
                userMessage = await RetrieveRelatedUserMessage(signalMessage);
            }

            if (userMessage == null)
            {
                Logger.Warn("The related usermessage for the received signalmessage could not be found");
                userMessage = new UserMessage(IdentifierFactory.Instance.Create());
            }

            UserMessage minderUserMessage = CreateUserMessageFromMinderProperties(userMessage, signalMessage);

            NotifyMessage notifyMessage =
                AS4MessageToNotifyMessageMapper.Convert(
                    as4Message.FirstSignalMessage,
                    receivedEntityMessageType,
                    as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message));

            // The NotifyMessage that Minder expects, is an AS4Message which contains the specific UserMessage.
            var msg        = AS4Message.Create(minderUserMessage, new SendingProcessingMode());
            var serializer = SerializerProvider.Default.Get(msg.ContentType);

            byte[] content;

            using (var memoryStream = new MemoryStream())
            {
                serializer.Serialize(msg, memoryStream);
                content = memoryStream.ToArray();
            }

            return(new NotifyMessageEnvelope(notifyMessage.MessageInfo, notifyMessage.StatusInfo.Status, content, msg.ContentType, receivedEntityMessageType));
        }
コード例 #17
0
        public void DecorateMandatoryInfoToSendingPMode()
        {
            // Arrange
            var smpResponse = new SmpConfiguration
            {
                PartyRole = "role",
                Url       = "http://some/url"
            };

            var doc = new XmlDocument();

            doc.LoadXml(AS4XmlSerializer.ToString(smpResponse));

            var pmode = new SendingProcessingMode();
            var sut   = new LocalDynamicDiscoveryProfile(GetDataStoreContext);

            // Act
            SendingProcessingMode actual = sut.DecoratePModeWithSmpMetaData(pmode, doc).CompletedSendingPMode;

            // Assert
            Assert.Equal(smpResponse.Url, actual.PushConfiguration.Protocol.Url);
        }
コード例 #18
0
        public async Task SucceedsWithAValidPullConfiguration()
        {
            // Arrange
            const string          expectedMpc          = "expected-mpc";
            SendingProcessingMode expectedSendingPMode = CreateAnonymousSendingPModeWith(expectedMpc);
            var receivedMessage = new ReceivedMessage(await AS4XmlSerializer.ToStreamAsync(expectedSendingPMode));

            var transformer = new PModeToPullRequestTransformer();

            // Act
            using (MessagingContext context = await transformer.TransformAsync(receivedMessage))
            {
                // Assert
                Assert.NotNull(context.AS4Message);
                Assert.True(context.AS4Message.IsPullRequest);

                var actualSignalMessage = context.AS4Message.FirstSignalMessage as PullRequest;
                Assert.Equal(expectedMpc, actualSignalMessage?.Mpc);
                Assert.Equal(expectedSendingPMode.Id, context.SendingPMode.Id);
                Assert.Equal(MessagingContextMode.PullReceive, context.Mode);
            }
        }
コード例 #19
0
        private SendingProcessingMode RetrieveSendingPModeForMessageWithEbmsMessageId(string ebmsMessageId)
        {
            if (ebmsMessageId == null)
            {
                Logger.Debug("Can't retrieve SendingPMode because NotifyMessage.MessageInfo.RefToMessageId is not present");
                return(null);
            }

            using (DatastoreContext context = _createContext())
            {
                var repository     = new DatastoreRepository(context);
                var outMessageData =
                    repository.GetOutMessageData(
                        where : m => m.EbmsMessageId == ebmsMessageId && m.Intermediary == false,
                        selection: m => new { m.PMode, m.ModificationTime })
                    .OrderByDescending(m => m.ModificationTime)
                    .FirstOrDefault();

                if (outMessageData == null)
                {
                    Logger.Debug(
                        "Can't retrieve SendingPMode because no matching stored OutMessage found "
                        + $"for EbmsMessageId = {ebmsMessageId} AND Intermediary = false");

                    return(null);
                }

                var pmode = AS4XmlSerializer.FromString <SendingProcessingMode>(outMessageData.PMode);
                if (pmode == null)
                {
                    Logger.Debug(
                        "Can't use SendingPMode from matching OutMessage for NotifyMessage.MessageInfo.RefToMessageId "
                        + $"{ebmsMessageId} because the PMode field can't be deserialized correctly to a SendingPMode");
                }

                return(pmode);
            }
        }
コード例 #20
0
        public async Task RetrieveSmpResponseFromDatastore()
        {
            // Arrange
            var fixture  = new Party("role", new PartyId(Guid.NewGuid().ToString(), "type"));
            var expected = new SmpConfiguration
            {
                PartyRole = fixture.Role,
                ToPartyId = fixture.PrimaryPartyId,
                PartyType = "type"
            };

            InsertSmpResponse(expected);

            var sut = new LocalDynamicDiscoveryProfile(GetDataStoreContext);

            // Act
            XmlDocument actualDoc = await sut.RetrieveSmpMetaDataAsync(fixture, properties : null);

            // Assert
            var actual = AS4XmlSerializer.FromString <SmpConfiguration>(actualDoc.OuterXml);

            Assert.Equal(expected.ToPartyId, actual.ToPartyId);
        }
コード例 #21
0
        public async Task Test_8_2_8_Send_AS4Message_To_Receiving_MSH_That_Cant_Find_PMode_Result_In_Notification_Error()
        {
            // Arrange
            AS4Component.Start();

            // Act
            AS4Component.PutSubmitMessage("8.2.8-pmode", AS4Component.SubmitPayloadImage);

            // Assert
            IEnumerable <FileInfo> errors =
                await PollingService.PollUntilPresentAsync(AS4Component.ErrorsPath);

            string xml          = File.ReadAllText(errors.First().FullName);
            var    notification = AS4XmlSerializer.FromString <NotifyMessage>(xml);

            Assert.True(notification != null, "Found Error notification cannot be deserialized to a 'NotifyMessage'");
            Assert.True(notification.StatusInfo != null, "Found Error notification doesn't hava a <StatusInfo/> element");

            Assert.Equal(Status.Error, notification.StatusInfo.Status);
            Assert.True(
                notification.StatusInfo.Any.First().SelectSingleNode("//*[local-name()='ErrorDetail']")?.InnerText != null,
                "Found Error notification doesn't have a <SignalMessage/> included");
        }
コード例 #22
0
        public async Task Test_8_1_12_AS4Message_With_Single_Payload_Result_In_Notified_Signed_Non_Repudiation_Receipt()
        {
            // Arrange
            AS4Component.Start();
            Holodeck.CopyPModeToHolodeckB("8.1.12-pmode.xml");

            // Act
            AS4Component.PutSubmitMessageSinglePayload("8.1.12-pmode");

            IEnumerable <FileInfo> receipts =
                await PollingService.PollUntilPresentAsync(AS4Component.ReceiptsPath);

            string xml          = File.ReadAllText(receipts.First().FullName);
            var    notification = AS4XmlSerializer.FromString <NotifyMessage>(xml);

            Assert.True(notification != null, "Found Receipt notification cannot be deserialized to a NotifyMessage");
            Assert.True(notification.StatusInfo != null, "Found Receipt notification doesn't have a <StatusInfo/> element");
            Assert.Equal(Status.Delivered, notification.StatusInfo.Status);
            Assert.True(notification.StatusInfo.Any?.Any(), "Found Receipt notification doesn't have a <SignalMessage/> included");
            Assert.True(
                notification.StatusInfo.Any?.First()?.SelectSingleNode("//*[local-name()='NonRepudiationInformation']") != null,
                "Found Receipt notification doesn't have a <NonRepudiationInformation/> element");
        }
コード例 #23
0
        /// <summary>
        /// Set the PMode that is used to process the message.
        /// </summary>
        /// <param name="pmode"></param>
        public void SetPModeInformation(IPMode pmode)
        {
            if (pmode != null)
            {
                PModeId = pmode.Id;

                // The Xml Serializer is not able to serialize an interface, therefore
                // the argument must first be cast to a correct implementation.

                if (pmode is SendingProcessingMode sp)
                {
                    PMode = AS4XmlSerializer.ToString(sp);
                }
                else if (pmode is ReceivingProcessingMode rp)
                {
                    PMode = AS4XmlSerializer.ToString(rp);
                }
                else
                {
                    throw new NotImplementedException("Unable to serialize the the specified IPMode");
                }
            }
        }
コード例 #24
0
 /// <summary>
 /// Assigns the parent properties.
 /// </summary>
 /// <param name="messageUnit">The MessageUnit from which the properties must be retrieved..</param>
 public void AssignAS4Properties(MessageUnit messageUnit)
 {
     if (messageUnit is UserMessage userMessage)
     {
         FromParty      = userMessage.Sender.PartyIds.First().Id;
         ToParty        = userMessage.Receiver.PartyIds.First().Id;
         Action         = userMessage.CollaborationInfo.Action;
         Service        = userMessage.CollaborationInfo.Service.Value;
         ConversationId = userMessage.CollaborationInfo.ConversationId;
         Mpc            = userMessage.Mpc;
         IsTest         = userMessage.IsTest;
         IsDuplicate    = userMessage.IsDuplicate;
         SoapEnvelope   = AS4XmlSerializer.ToString(UserMessageMap.Convert(userMessage));
     }
     else
     {
         if (messageUnit is SignalMessage signalMessage)
         {
             IsDuplicate = signalMessage.IsDuplicate;
             Mpc         = signalMessage.MultiHopRouting.Select(r => r.mpc).GetOrElse(Constants.Namespaces.EbmsDefaultMpc);
         }
     }
 }
コード例 #25
0
        protected virtual async Task <NotifyMessageEnvelope> CreateNotifyMessageEnvelopeAsync(
            AS4Message as4Message,
            string receivedEntityMessageId,
            Type receivedEntityType)
        {
            SignalMessage tobeNotifiedSignal =
                as4Message.SignalMessages.FirstOrDefault(s => s.MessageId == receivedEntityMessageId);

            NotifyMessage notifyMessage =
                AS4MessageToNotifyMessageMapper.Convert(
                    tobeNotifiedSignal,
                    receivedEntityType,
                    as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message));

            var serialized = await AS4XmlSerializer.ToStringAsync(notifyMessage).ConfigureAwait(false);

            return(new NotifyMessageEnvelope(
                       notifyMessage.MessageInfo,
                       notifyMessage.StatusInfo.Status,
                       System.Text.Encoding.UTF8.GetBytes(serialized),
                       "application/xml",
                       receivedEntityType));
        }
コード例 #26
0
        /// <summary>
        /// Retrieves the SMP meta data <see cref="XmlDocument" /> for a given <paramref name="party" /> using a given
        /// <paramref name="properties" />.
        /// </summary>
        /// <param name="party">The party identifier to select the right SMP meta-data.</param>
        /// <param name="properties">The information properties specified in the <see cref="SendingProcessingMode"/> for this profile.</param>
        public Task <XmlDocument> RetrieveSmpMetaDataAsync(Model.Core.Party party, IDictionary <string, string> properties)
        {
            if (party == null)
            {
                throw new ArgumentNullException(nameof(party));
            }

            if (party.PrimaryPartyId == null ||
                party.PartyIds.FirstOrDefault()?.Type == null ||
                party.Role == null)
            {
                throw new InvalidOperationException(
                          "Given invalid 'ToParty', requires 'Role', 'PartyId', and 'PartyType'");
            }

            SmpConfiguration configuration = FindSmpResponseForToParty(party);
            string           xml           = AS4XmlSerializer.ToString(configuration);

            var document = new XmlDocument();

            document.LoadXml(xml);

            return(Task.FromResult(document));
        }
コード例 #27
0
        /// <summary>
        /// Start receiving on a configured Target
        /// Received messages will be send to the given Callback
        /// </summary>
        /// <param name="messageCallback"></param>
        /// <param name="cancellationToken"></param>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public override void StartReceiving(
            Func <ReceivedMessage, CancellationToken, Task <MessagingContext> > messageCallback,
            CancellationToken cancellationToken)
        {
            if (messageCallback == null)
            {
                throw new ArgumentNullException(nameof(messageCallback));
            }

            _messageCallback = async message =>
            {
                var receivedMessage = new ReceivedMessage(
                    underlyingStream: await AS4XmlSerializer.ToStreamAsync(message.PMode),
                    contentType: Constants.ContentTypes.Soap,
                    origin: message.PMode?.PushConfiguration?.Protocol?.Url ?? "unknown");

                return(await messageCallback(receivedMessage, cancellationToken));
            };

            // Wait some time till the Kernel is fully started
            Thread.Sleep(TimeSpan.FromSeconds(5));

            StartInterval();
        }
コード例 #28
0
        private static void TestConfigInitialization(
            Action <Settings> alterSettings,
            Action <Config> onInitialized)
        {
            string testSettingsFileName = Path.Combine(
                Config.ApplicationPath, "config", "test-settings.xml");

            string originalSettingsFileName = Path.Combine(
                Config.ApplicationPath, "config", "settings.xml");

            var settings = AS4XmlSerializer
                           .FromString <Settings>(File.ReadAllText(originalSettingsFileName));

            alterSettings(settings);

            File.WriteAllText(
                testSettingsFileName,
                AS4XmlSerializer.ToString(settings));

            File.Copy(
                originalSettingsFileName,
                testSettingsFileName,
                overwrite: true);

            Directory.CreateDirectory(Path.Combine(Config.ApplicationPath, "config", "send-pmodes"));
            Directory.CreateDirectory(Path.Combine(Config.ApplicationPath, "config", "receive-pmodes"));

            // Act
            Config.Instance.Initialize(testSettingsFileName);

            // Assert
            onInitialized(Config.Instance);

            // TearDown
            File.Delete(testSettingsFileName);
        }
コード例 #29
0
            public void StartReceiver()
            {
                var stubConfig = new StubConfig(
                    sendingPModes: new Dictionary <string, SendingProcessingMode>
                {
                    ["01-send"] = AS4XmlSerializer.FromString <SendingProcessingMode>(Properties.Resources.send_01)
                },
                    receivingPModes: new Dictionary <string, ReceivingProcessingMode>
                {
                    ["01-receive"] = AS4XmlSerializer.FromString <ReceivingProcessingMode>(Properties.Resources.receive_01)
                });

                // Arrange
                var     receiver        = new PullRequestReceiver(stubConfig);
                Setting receiverSetting = CreateMockReceiverSetting();

                receiver.Configure(new[] { receiverSetting });

                // Act
                receiver.StartReceiving(OnMessageReceived, CancellationToken.None);

                // Assert
                Assert.True(_waitHandle.WaitOne(timeout: TimeSpan.FromMinutes(2)));
            }
コード例 #30
0
 /// <summary>
 /// Gets the sending processing mode of the child representation of an exception.
 /// </summary>
 public override SendingProcessingMode GetSendingPMode()
 {
     return(AS4XmlSerializer.FromString <SendingProcessingMode>(PMode));
 }