예제 #1
0
        public TransmissionResult Call()
        {
            Trace span = Trace.Create();

            span.Record(Annotations.ServiceName("standalone"));
            span.Record(Annotations.ClientSend());

            try
            {
                ITransmissionResponse transmissionResponse;
                long duration = 0;

                if (this.parameters.UseFactory)
                {
                    using (Stream inputStream = File.Open(this.xmlPayloadFile.FullName, FileMode.Open, FileAccess.Read))
                    {
                        transmissionResponse = this.parameters.HyperwayOutboundComponent.GetTransmissionService()
                                               .Send(inputStream, span);
                    }
                }
                else
                {
                    ITransmissionRequest transmissionRequest = this.CreateTransmissionRequest(span);

                    ITransmitter transmitter;
                    Trace        span1 = span.Child();
                    span1.Record(Annotations.ServiceName("get transmitter"));
                    span1.Record(Annotations.ClientSend());
                    try
                    {
                        transmitter = this.parameters.HyperwayOutboundComponent.GetTransmitter();
                    }
                    finally
                    {
                        span1.Record(Annotations.ClientRecv());
                    }

                    // Performs the transmission
                    var watch = new Stopwatch();
                    watch.Start();
                    transmissionResponse = this.PerformTransmission(
                        this.parameters.EvidencePath, transmitter, transmissionRequest, span);
                    watch.Stop();

                    return(new TransmissionResult(watch.ElapsedMilliseconds, transmissionResponse.GetTransmissionIdentifier()));
                }

                return(new TransmissionResult(duration, transmissionResponse.GetTransmissionIdentifier()));
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
예제 #2
0
        /// <summary>
        /// Конструктор таймера метрик, который трейсит обращения к сервиса к внешним ресурсам
        /// </summary>
        /// <param name="trace"></param>
        /// <param name="tracingServiceName"></param>
        /// <param name="methodName"></param>
        /// <param name="getTracingTagsCallback"></param>
        public TracingTimer(Trace trace, string tracingServiceName, string methodName, Dictionary <string, string> getTracingTagsCallback)
        {
            if ((_trace = trace?.Child()) != null)
            {
                _trace.Record(Annotations.ServiceName(tracingServiceName));
                _trace.Record(Annotations.ClientSend());
                _trace.Record(Annotations.Rpc($"{tracingServiceName}_{methodName}"));

                foreach (var tag in getTracingTagsCallback)
                {
                    _trace.Record(Annotations.Tag(tag.Key, tag.Value));
                }
            }
        }
예제 #3
0
        public ITransmissionResponse Send(ITransmissionRequest request, Trace traceParent)
        {
            this.transmissionRequest = request;

            this.root = traceParent.Child();
            this.root.Record(Annotations.ServiceName("Send AS2 message"));
            this.root.Record(Annotations.ClientSend());
            try
            {
                return(this.SendHttpRequest(this.PrepareHttpRequest()));
            }
            catch (HyperwayTransmissionException e)
            {
                this.root.Record(Annotations.Tag("exception", e.Message));
                throw;
            }
            finally
            {
                this.root.Record(Annotations.ClientRecv());
            }
        }
예제 #4
0
        protected ITransmissionResponse PerformTransmission(
            DirectoryInfo evidencePath,
            ITransmitter transmitter,
            ITransmissionRequest transmissionRequest,
            Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("transmission"));
            span.Record(Annotations.ClientSend());
            try
            {
                // ... and performs the transmission
                Stopwatch watch = new Stopwatch();
                watch.Start();
                // long start = System.DateTime.Now;
                ITransmissionResponse transmissionResponse = transmitter.Transmit(transmissionRequest, span);
                watch.Stop();

                long durationInMs = watch.ElapsedMilliseconds; // System.DateTime.Now - start;

                Log.Debug(
                    String.Format(
                        "Message using messageId {0} sent to {1} using {2} was assigned transmissionId {3} took {4}ms\n",
                        transmissionResponse.GetHeader().Identifier.Identifier,
                        transmissionResponse.GetEndpoint().Address,
                        transmissionResponse.GetProtocol().Identifier,
                        transmissionResponse.GetTransmissionIdentifier(),
                        durationInMs));

                this.SaveEvidence(transmissionResponse, evidencePath, span);

                return(transmissionResponse);
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
예제 #5
0
        protected ITransmissionRequest CreateTransmissionRequest(Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("create transmission request"));
            span.Record(Annotations.ClientSend());

            try
            {
                // creates a transmission request builder and enables trace
                TransmissionRequestBuilder requestBuilder =
                    this.parameters.HyperwayOutboundComponent.GetTransmissionRequestBuilder();

                requestBuilder.SetTransmissionBuilderOverride(true);

                // add receiver participant
                if (this.parameters.Receiver != null)
                {
                    requestBuilder.Receiver(this.parameters.Receiver);
                }

                // add sender participant
                if (this.parameters.Sender != null)
                {
                    requestBuilder.Sender(this.parameters.Sender);
                }

                if (this.parameters.DocType != null)
                {
                    requestBuilder.DocumentType(this.parameters.DocType);
                }

                if (this.parameters.ProcessIdentifier != null)
                {
                    requestBuilder.ProcessType(this.parameters.ProcessIdentifier);
                }

                // Supplies the payload
                using (Stream inputStream = File.Open(this.xmlPayloadFile.FullName, FileMode.Open, FileAccess.Read))
                {
                    requestBuilder.PayLoad(inputStream);
                }

                // Overrides the destination URL if so requested
                if (this.parameters.Endpoint != null)
                {
                    Endpoint endpoint = this.parameters.Endpoint;
                    requestBuilder.OverrideAs2Endpoint(endpoint);
                }

                // Specifying the details completed, creates the transmission request
                return(requestBuilder.Build(span));
            }
            catch (Exception e)
            {
                span.Record(Annotations.Tag("exception", e.Message));
                Console.WriteLine("Message failed : " + e.Message + e.StackTrace);
                return(null);
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
예제 #6
0
        public void DoPost()
        {
            var headers   = this.httpContext.Request.Headers;
            var messageId = headers["message-id"];

            if (string.IsNullOrWhiteSpace(messageId))
            {
                var errorResult = new ContentResult();
                errorResult.StatusCode = StatusCodes.Status400BadRequest;
                errorResult.Content    = "Header field 'Message-ID' not found.";
                throw new NotSupportedException("error management");
                // return errorResult;
            }


            Trace root = Trace.Create();

            root.Record(Annotations.ServiceName("as2servlet.post"));
            root.Record(Annotations.ServerRecv());
            root.Record(Annotations.Tag("message-id", messageId));

            Logger.Debug("Receiving HTTP POST request");
            try
            {
                // Read MIME message
                var         bodyStream  = this.httpContext.Request.Body;
                var         bodyData    = bodyStream.ToBuffer();
                MimeMessage mimeMessage =
                    MimeMessageHelper.CreateMimeMessageAssistedByHeaders(bodyData.ToStream(), headers);

                try
                {
                    Trace span = root.Child();
                    span.Record(Annotations.ServiceName("as2message"));
                    span.Record(Annotations.ServerRecv());
                    MimeMessage mdn = this.inboundHandlerProvider().Receive(headers, mimeMessage);
                    span.Record(Annotations.ServerSend());

                    span = root.Child();
                    span.Record(Annotations.ServiceName("mdn"));
                    span.Record(Annotations.ServerRecv());

                    this.WriteMdn(this.httpContext.Response, mdn, (int)HttpStatusCode.OK);
                    span.Record(Annotations.ServerSend());
                }
                catch (HyperwayAs2InboundException e)
                {
                    String identifier = Guid.NewGuid().ToString();
                    Logger.ErrorFormat("Error [{0}] {1}", identifier, e);

                    // Open message for reading
                    SMimeReader sMimeReader = new SMimeReader(mimeMessage);

                    // Begin builder
                    MdnBuilder mdnBuilder = MdnBuilder.NewInstance(mimeMessage);
                    // Original Message-Id
                    mdnBuilder.AddHeader(MdnHeader.OriginalMessageId, headers[As2Header.MessageId]);
                    // Disposition from exception
                    mdnBuilder.AddHeader(MdnHeader.Disposition, e.Disposition);
                    mdnBuilder.AddText(String.Format("Error [{0}]", identifier), e.Message);

                    // Build and add headers
                    MimeMessage mdn = this.sMimeMessageFactory.CreateSignedMimeMessage(
                        mdnBuilder.Build(),
                        sMimeReader.GetDigestMethod());
                    mdn.Headers.Add(As2Header.As2Version, As2Header.Version);
                    mdn.Headers.Add(As2Header.As2From, headers[As2Header.As2To]);
                    mdn.Headers.Add(As2Header.As2To, headers[As2Header.As2From]);
                    this.WriteMdn(this.httpContext.Response, mdn, (int)HttpStatusCode.BadRequest);
                }
            }
            catch (Exception e)
            {
                root.Record(Annotations.Tag("exception", e.Message));

                // Unexpected internal error, cannot proceed, return HTTP 500 and partly MDN to indicating the problem
                Logger.ErrorFormat("Internal error occured: {0}", e.Message);
                Logger.Error("Attempting to return MDN with explanatory message and HTTP 500 status");

                // TODO: manage failure
                this.WriteFailureWithExplanation(this.httpContext.Request, this.httpContext.Response, e);
            }

            // MDC.clear();
            root.Record(Annotations.ServerSend());
        }