예제 #1
0
        private void ProcessRequest(string uri, HttpContext context, HttpReceiveEndpoint ep)
        {
            // Create a new message...
            IBaseMessage msg = ConstructMessage(uri, context, ep);

            // Submit the message using the StandardReceiveBatchHandler
            SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(transportProxy, terminator, 1);

            // Do one-way-submit
            batch.SubmitMessage(msg, null);
            batch.Done();

            if (!batch.Wait())
            {
                Trace.WriteLine("HttpReceiveAdapter.ProcessRequest(): Failed to process the Http Request!", "HttpReceive: Error");
                throw new HttpException(400, "Failed to process the Http Request");
            }

            context.Response.StatusCode = 202;
        }
예제 #2
0
        internal void SubmitFiles(ControlledTermination control, IList <string> filesInProcess)
        {
            if (Files == null || Files.Count == 0)
            {
                return;
            }

            _filesInProcess = filesInProcess;

            try
            {
                using (SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(_transportProxy, control, Files.Count))
                {
                    foreach (BatchMessage file in Files)
                    {
                        batch.SubmitMessage(file.Message, file.UserData);
                    }
                    batch.Done();

                    TraceMessage("[SftpReceiverEndpoint] SubmitFiles (firstAttempt) about to wait on BatchComplete");
                    if (batch.Wait())
                    {
                        TraceMessage("[SftpReceiverEndpoint] SubmitFiles (firstAttempt) overall success");
                        OnBatchComplete(this, new StatusEventArgs {
                            OverallStatus = true
                        });
                    }
                }
                TraceMessage("[SftpReceiverEndpoint] Leaving SubmitFiles");
            }
            catch (Exception ex)
            {
                throw ExceptionHandling.HandleComponentException(
                          EventLogEventIDs.UnableToSubmitBizTalkMessage,
                          System.Reflection.MethodBase.GetCurrentMethod(), ex);
            }
        }
        private bool SubmitMessage(BrokeredMessage message)
        {
            try
            {
                SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(this.transportProxy, this.control, 1);

                batch.SubmitMessage(CreateMessage(message));

                batch.Done();

                if (batch.Wait() == true)
                {
                    message.Complete();
                }

                return(batch.OverallSuccess);
            }
            catch (Exception e)
            {
                this.transportProxy.SetErrorInfo(e);
            }

            return(false);
        }
        private bool SubmitMessage(Shared.Components.Entry message)
        {
            try
            {
                SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(this.transportProxy, this.control, 1);

                batch.SubmitMessage(CreateMessage(message));

                batch.Done();

                if (batch.Wait() == true)
                {
                    atomState.LastEntryId = message.Id;
                }

                return(batch.OverallSuccess);
            }
            catch (Exception e)
            {
                this.transportProxy.SetErrorInfo(e);
            }

            return(false);
        }
예제 #5
0
        private void ProcessRequestResponse(string uri, HttpContext context, HttpReceiveEndpoint ep)
        {
            // Create a new message...
            IBaseMessage msg = ConstructMessage(uri, context, ep);

            // Use the request-response handler to send the request message
            SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(this.transportProxy, terminator, 1);

            DateTime            expDateTime     = DateTime.Now.AddSeconds(ep.Configuration.Timeout);
            HttpResponseHandler responseHandler = new HttpResponseHandler(this.transportProxy);

            // Do two-way submit operation: EPM should generate a response in this case
            batch.SubmitRequestMessage(msg, Guid.NewGuid().ToString("D"), true, expDateTime, responseHandler);

            // Done will call "Enter" on the terminator to ensure proper ref-counting
            batch.Done();

            // Wait for the callback (this should always complete quickly)
            if (!batch.Wait())
            {
                throw new HttpException(500, "Failed to submit the Http request to BizTalk Server");
            }

            if (batch.FailedMessages.Count != 0)
            {
                throw new HttpException(500, "Failed to submit the Http request to BizTalk Server");
            }

            // It's a good idea to have a timeout on the response message
            IBaseMessage responseMsg = responseHandler.WaitForResponse(ep.Configuration.Timeout);

            if (responseMsg == null)
            {
                // Response did not arrive in time!
                throw new HttpException(500, "Failed to retrieve the Http response message from BizTalk Server");
            }

            // Copy the data from the response message into the HTTP response stream.
            Exception transmitException = null;

            try
            {
                using (Stream httpStream = context.Response.OutputStream)
                {
                    // Set the response content-type (ideally, this should be extracted from message)
                    context.Response.ContentType = ep.Configuration.ReturnContentType;

                    Stream btsStream = responseMsg.BodyPart.GetOriginalDataStream();

                    // Note, the data is handled in a streaming fashion to
                    // prevent us going out of memory for large messages.
                    int    bytesRead = 0;
                    byte[] buff      = new byte[IO_BUFFER_SIZE];
                    while ((bytesRead = btsStream.Read(buff, 0, IO_BUFFER_SIZE)) > 0)
                    {
                        httpStream.Write(buff, 0, bytesRead);
                    }

                    httpStream.Flush();
                }
            }
            catch (Exception ex)
            {
                transmitException = ex;
            }
            finally
            {
                // After processing the response message successfully, it MUST be deleted
                // from BizTalk message box (a.k.a. Application Queue). Otherwise, the message
                // remain in the queue forever causing the system to become unresponsive.
                responseHandler.ResponseConsumed(transmitException);
            }
        }