Exemplo n.º 1
0
        public virtual Response Invoke(string baseUri, IRequest request, IXmlParser xmlParser, Handler handler, out string sessionId)
        {
            HttpWebRequest webRequest = CreateWebRequest(baseUri, request);
            webRequest.CookieContainer = new CookieContainer();
            setUserAgent(webRequest);
            WriteRequest(webRequest, request);

            HttpWebResponse webResponse = ReadResponse(webRequest, xmlParser, handler);
            Cookie jsessionId = webResponse.Cookies[SessionCookieName];
            if (null == jsessionId)
            {
                string cookieToSet = webResponse.Headers["Set-Cookie"];
                if (cookieToSet != null && cookieToSet.StartsWith(SessionCookieName))
                {
                    sessionId = cookieToSet.Substring(SessionCookieName.Length + 1);
                    sessionId = sessionId.Substring(0, sessionId.IndexOf(';'));

                }
                else
                {
                    // Can't throw an exception as the login response might contain a warning with no JSESSIONID.
                    // throw new Exception("Unable to locate JSESSIONID Cookie");
                    sessionId = null;                    
                }
            }
            else
            {
                sessionId = jsessionId.Value;
            }

            return new Response(webResponse.StatusCode);
        }
Exemplo n.º 2
0
        public virtual Response PostInSession(string baseUri, IRequest request, IXmlParser xmlParser, Handler handler, string sessionId)
        {
            HttpWebRequest webRequest = SendRequest(baseUri, request, sessionId);

            HttpWebResponse webResponse = ReadResponse(webRequest, xmlParser, handler);

            return new Response(webResponse.StatusCode);
        }
Exemplo n.º 3
0
        public Response GetInSession(string baseUri, IRequest request, IXmlParser xmlParser, Handler handler, string sessionId)
        {
            if (null == sessionId)
            {
                throw new ArgumentException("'sessionId' must not be null");
            }

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(baseUri + request.Uri);
            setUserAgent(webRequest);
            webRequest.Method = "GET";
            webRequest.Accept = "text/xml";
            webRequest.Headers.Add("Cookie", SessionCookieName + "=" + sessionId);

            HttpWebResponse webResponse = ReadResponse(webRequest, xmlParser, handler);

            return new Response(webResponse.StatusCode);
        }
 public void AddHandler(Handler handler)
 {
     _handlers[handler.ElementName] = handler;
 }
Exemplo n.º 5
0
 private void SendRequest(IRequest request, Handler handler, OnSucessfulRequest onSucessfulRequest, OnFailure failureCallback)
 {
     try
     {
         Response response = _httpInvoker.PostInSession(_baseUri, request, _xmlParser, handler, _sessionId);
         if (response.IsOk)
         {
             if (handler.IsOk)
             {
                 onSucessfulRequest();
             }
             else
             {
                 failureCallback(new FailureResponse(false, handler.Message, handler.Content, null));
             }
         }
         else
         {
             failureCallback(new FailureResponse(true, "HttpStatus: " + response.Status + ", for: " + _baseUri + request.Uri));
         }
     }
     catch (Exception e)
     {
         failureCallback(new FailureResponse(e, "URI: " + _baseUri + request.Uri));
     }
 }
 public SaxContentHandler(Handler rootHandler)
 {
     _handlers.Push(rootHandler);
 }
Exemplo n.º 7
0
        private HttpWebResponse ReadResponse(HttpWebRequest webRequest, IXmlParser xmlParser, Handler handler)
        {
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

            using (StreamReader reader = new StreamReader(webResponse.GetResponseStream(), new UTF8Encoding()))
            {
                xmlParser.Parse(reader, new SaxContentHandler(handler));
            }

            return webResponse;
        }
Exemplo n.º 8
0
 public void AddHandler(Handler handler)
 {
     _handlers[handler.ElementName] = handler;
 }
Exemplo n.º 9
0
        public void RequestHeartbeat(HeartbeatRequest heartbeatRequest, OnSuccess successCallback, OnFailure failureCallback)
        {
            Handler handler = (Handler) new DefaultHandler();

            this.SendRequest((IRequest)heartbeatRequest, handler, (Session.OnSucessfulRequest)(() => successCallback()), failureCallback);
        }
Exemplo n.º 10
0
        public void RequestHistoricMarketData(IHistoricMarketDataRequest historicMarketDataRequest, OnSuccess successCallback, OnFailure failureCallback)
        {
            Handler handler = (Handler) new DefaultHandler();

            this.SendRequest((IRequest)historicMarketDataRequest, handler, (Session.OnSucessfulRequest)(() => successCallback()), failureCallback);
        }
Exemplo n.º 11
0
        public void RequestAccountState(AccountStateRequest accountStateRequest, OnSuccess successCallback, OnFailure failureCallback)
        {
            Handler handler = (Handler) new DefaultHandler();

            this.SendRequest((IRequest)accountStateRequest, handler, (Session.OnSucessfulRequest)(() => successCallback()), failureCallback);
        }
Exemplo n.º 12
0
        public void Subscribe(ISubscriptionRequest subscriptionRequest, OnSuccess successCallback, OnFailure failureCallback)
        {
            Handler handler = (Handler) new DefaultHandler();

            this.SendRequest((IRequest)subscriptionRequest, handler, (Session.OnSucessfulRequest)(() => successCallback()), failureCallback);
        }