Esempio n. 1
0
        protected override void HandlerPropertyBagLoaded()
        {
            IPropertyBag config = this.HandlerPropertyBag;

            if (null != config)
            {
                XmlDocument handlerConfigDom = ConfigProperties.IfExistsExtractConfigDom(config);
                if (null != handlerConfigDom)
                {
                    HttpAdapterProperties.TransmitHandlerConfiguration(handlerConfigDom);
                }
            }
        }
        /// <summary>
        /// Implementation for AsyncTransmitterEndpoint::ProcessMessage
        /// Transmit the message and optionally return the response message
        /// </summary>
        public override IBaseMessage ProcessMessage(IBaseMessage message)
        {
            this.solicitMsg = message;

            HttpAdapterProperties props       = new HttpAdapterProperties(message, this.propertyNamespace);
            IBaseMessage          responseMsg = null;

            if (props.IsTwoWay)
            {
                WebResponse response = SendHttpRequest(this.solicitMsg, props);
                responseMsg = BuildResponseMessage(response);
            }
            else
            {
                WebResponse response = SendHttpRequest(this.solicitMsg, props);
                response.Close();
            }

            return(responseMsg);
        }
Esempio n. 3
0
        public ConfigProperties CreateProperties(string uri)
        {
            ConfigProperties properties = new HttpAdapterProperties(uri);

            return(properties);
        }
        private WebResponse SendHttpRequest(IBaseMessage msg, HttpAdapterProperties config)
        {
            #region SSO Usage Example
            // If we needed to use SSO to lookup the remote system credentials

            /*
             * string ssoAffiliateApplication = props.AffiliateApplication;
             * if (ssoAffiliateApplication.Length > 0)
             * {
             *  SSOResult ssoResult = new SSOResult(msg, affiliateApplication);
             *  string userName  = ssoResult.UserName;
             *  string password  = ssoResult.Result[0];
             *  string etcEtcEtc = ssoResult.Result[1]; // (you can have additional metadata associated with the login in SSO)
             *
             *  // use these credentials to login to the remote system
             *  // ideally zero off the password memory once we are done
             * }
             */
            #endregion // SSO Usage Example

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(config.Uri);
            request.Method  = config.HttpVerb;
            request.Timeout = config.Timeout;

            // Configure the authentication type...
            if (HttpAdapterProperties.AuthenticationType.KerberosAuthentication == config.AuthType)
            {
                request.AllowWriteStreamBuffering = true;
                request.PreAuthenticate           = false;
                request.Credentials = CredentialCache.DefaultCredentials;
            }
            else
            {
                request.AllowWriteStreamBuffering = false;
                request.PreAuthenticate           = true;
            }

            // Note: both the body part and the stream maybe null, so we need to
            // check for them
            string           charset  = string.Empty;
            IBaseMessagePart bodyPart = msg.BodyPart;
            Stream           btsStream;

            if (null != bodyPart && (null != (btsStream = bodyPart.GetOriginalDataStream())))
            {
                charset = bodyPart.Charset;
                string contentTypeCharset = config.ContentType;

                if (contentTypeCharset.ToLowerInvariant().StartsWith("text/"))
                {
                    // Append charset information (if it's not there already)!
                    if (charset != null && charset.Length > 0 && contentTypeCharset.ToLowerInvariant().IndexOf("charset=") == -1)
                    {
                        contentTypeCharset += "; charset=" + charset;
                    }
                }
                request.ContentType = contentTypeCharset;

                // Wrap the BTS stream in the seekable stream to obtain the content-legnth!
                btsStream             = new VirtualStream(btsStream);
                request.ContentLength = btsStream.Length;

                // Get the request stream and write the data into it...
                Stream webStream = request.GetRequestStream();
                int    bytesRead = 0;
                byte[] buff      = new byte[IO_BUFFER_SIZE];
                while ((bytesRead = btsStream.Read(buff, 0, IO_BUFFER_SIZE)) > 0)
                {
                    webStream.Write(buff, 0, bytesRead);
                }

                webStream.Flush();
                webStream.Close();
            }

            return(request.GetResponse());
        }