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); } } }
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); } }
/// <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); }
/// <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(); }