Exemple #1
0
        /// <summary>
        /// Maps from a domain model representation to a XML representation of an AS4 receipt.
        /// </summary>
        /// <param name="model">The domain model to convert.</param>
        internal static Xml.SignalMessage Convert(Receipt model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(new Xml.SignalMessage
            {
                MessageInfo = new MessageInfo
                {
                    MessageId = model.MessageId,
                    RefToMessageId = model.RefToMessageId,
                    Timestamp = model.Timestamp.LocalDateTime
                },
                Receipt = new Xml.Receipt
                {
                    UserMessage =
                        model.UserMessage != null
                            ? UserMessageMap.Convert(model.UserMessage)
                            : null,
                    NonRepudiationInformation =
                        model.NonRepudiationInformation != null
                            ? MapNonRepudiationInformation(model.NonRepudiationInformation)
                            : null
                }
            });
        }
        private static Receipt CreateReceiptWithRelatedUserMessageInfo()
        {
            string ebmsMessageId = $"user-{Guid.NewGuid()}";
            var    userMessage   = new UserMessage(ebmsMessageId);

            return(Receipt.CreateFor($"receipt-{Guid.NewGuid()}", userMessage));
        }
Exemple #3
0
        private async Task CorrectHandlingOnSynchronouslyReceivedMultiHopReceipt(
            bool actAsIntermediaryMsh,
            string receivePModeId,
            OutStatus expectedOutStatus,
            Operation expectedSignalOperation)
        {
            // Arrange
            SendingProcessingMode pmode             = CreateMultihopPMode(StubListenLocation);
            UserMessage           simpleUserMessage = CreateMultihopUserMessage(receivePModeId, pmode);

            AS4Message as4Message = AS4Message.Create(simpleUserMessage, pmode);

            var signal     = new ManualResetEvent(false);
            var serializer = new SoapEnvelopeSerializer();

            StubHttpServer.StartServer(
                StubListenLocation,
                res =>
            {
                res.StatusCode  = 200;
                res.ContentType = Constants.ContentTypes.Soap;

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

                serializer.Serialize(AS4Message.Create(receipt), res.OutputStream);
            },
                signal);

            // Act
            PutMessageToSend(as4Message, pmode, actAsIntermediaryMsh);

            // Assert
            signal.WaitOne();

            OutMessage sentMessage = await PollUntilPresent(
                () => _databaseSpy.GetOutMessageFor(m => m.EbmsMessageId == simpleUserMessage.MessageId),
                timeout : TimeSpan.FromSeconds(10));

            Assert.Equal(expectedOutStatus, sentMessage.Status.ToEnum <OutStatus>());

            InMessage receivedMessage = await PollUntilPresent(
                () => _databaseSpy.GetInMessageFor(m => m.EbmsRefToMessageId == simpleUserMessage.MessageId),
                timeout : TimeSpan.FromSeconds(10));

            Assert.Equal(MessageType.Receipt, receivedMessage.EbmsMessageType);
            Assert.Equal(expectedSignalOperation, receivedMessage.Operation);
        }
        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"));
        }
        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);
        }
        private static SignalMessage CreateMultihopSignalMessage(string refToMessageId, string pmodeId)
        {
            var userMessage = new UserMessage(
                refToMessageId,
                "some-mpc",
                new CollaborationInfo(
                    new AgreementReference("http://agreements.europa.org/agreement", pmodeId),
                    new Service("Forward_Push_Service", "eu:europe:services"),
                    "Forward_Push_Action",
                    CollaborationInfo.DefaultConversationId),
                new Party("Sender", new PartyId("org:eu:europa:as4:example:accesspoint:A")),
                new Party("Receiver", new PartyId("org:eu:europa:as4:example:accesspoint:B")),
                new PartInfo[0],
                new MessageProperty[0]);

            return(Receipt.CreateFor(
                       $"receipt-{Guid.NewGuid()}",
                       userMessage,
                       userMessageSendViaMultiHop: true));
        }
        public async Task Received_Bundled_User_And_Receipt_Message_Should_Process_All_Messages()
        {
            // Arrange
            string ebmsMessageId = "test-" + Guid.NewGuid();

            StoreToBeAckOutMessage(ebmsMessageId, CreateSendingPMode());

            var userMessage = new UserMessage(
                "usermessage-" + Guid.NewGuid(),
                new CollaborationInfo(
                    agreement: new AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: "receive_bundled_message_pmode"),
                    service: new Service(
                        value: "bundling",
                        type: "as4.net:receive_agent:componenttest"),
                    action: "as4.net:receive_agent:bundling",
                    conversationId: "as4.net:receive_agent:conversation"));

            var receipt = new Receipt($"receipt-{Guid.NewGuid()}", ebmsMessageId);

            var bundled = AS4Message.Create(userMessage);

            bundled.AddMessageUnit(receipt);

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, bundled);

            // Assert
            AS4Message receivedReceipt = await response.DeserializeToAS4Message();

            Assert.IsType <Receipt>(receivedReceipt.FirstSignalMessage);
            Assert.Equal(userMessage.MessageId, receivedReceipt.FirstSignalMessage.RefToMessageId);

            AssertIfInMessageExistsForSignalMessage(ebmsMessageId);
            AssertIfInMessageIsStoredFor(userMessage.MessageId, Operation.ToBeDelivered);
        }
        private static AS4Message CreateAS4ReceiptMessage(string refToMessageId)
        {
            var r = new Receipt($"receipt-{Guid.NewGuid()}", refToMessageId);

            return(AS4Message.Create(r, CreateSendingPMode()));
        }