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()); } }
public ConsumerTrace(string serviceName, string rpc, string encodedTraceId, string encodedSpanId, string encodedParentSpanId, string sampledStr, string flagsStr) { var spanState = ExtractorHelper.TryParseTrace(encodedTraceId, encodedSpanId, encodedParentSpanId, sampledStr, flagsStr); if (spanState != default(SpanState)) { Trace = Trace.CreateFromId(spanState).Child(); } else { Trace = Trace.Create(); } Trace.Current = Trace; Trace.Record(Annotations.ConsumerStart()); Trace.Record(Annotations.ServiceName(serviceName)); Trace.Record(Annotations.Rpc(rpc)); }
protected void SaveEvidence( ITransmissionResponse transmissionResponse, DirectoryInfo evidencePath, Trace root) { Trace span = Trace.Create(); span.Record(Annotations.ServiceName("save evidence")); span.Record(Annotations.ClientSend()); try { this.SaveEvidence( transmissionResponse, "-as2-mdn.txt", #pragma warning disable 612 transmissionResponse.GetNativeEvidenceBytes(), #pragma warning restore 612 evidencePath); } finally { span.Record(Annotations.ClientRecv()); } }
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()); }