/// <summary>
        /// Called when receiving an http request from Java side
        /// </summary>
        /// <param name="httpMessage">The HTTP message.</param>
        public void OnNext(IHttpMessage httpMessage)
        {
            LOGGER.Log(Level.Info, "HttpHandler OnNext is called");
            string requestString = httpMessage.GetRequestString();

            if (requestString != null && requestString.Equals(SPEC))
            {
                LOGGER.Log(Level.Info, "HttpHandler OnNext, requestString:" + requestString);
                LOGGER.Log(Level.Info, "HttpHandler OnNext, port number:" + httpServerPort.PortNumber);

                httpMessage.SetUriSpecification(GetAllSpecifications());
            }
            else
            {
                LOGGER.Log(Level.Info, "HttpHandler OnNext, handling http request.");
                byte[]          byteData        = httpMessage.GetQueryReuestData();
                AvroHttpRequest avroHttpRequest = AvroHttpSerializer.FromBytesWithJoson(byteData);
                LOGGER.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "HttpHandler OnNext, requestData:", avroHttpRequest));

                string spec = GetSpecification(avroHttpRequest.PathInfo);
                if (spec != null)
                {
                    LOGGER.Log(Level.Info, "HttpHandler OnNext, target:" + spec);
                    ReefHttpRequest request = ToHttpRequest(avroHttpRequest);

                    foreach (var h in request.Header)
                    {
                        LOGGER.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "HttpRequest Header-key: {0}, value: {1}.", h.Key, h.Value));
                    }
                    ReefHttpResponse response = new ReefHttpResponse();

                    IHttpHandler handler;
                    eventHandlers.TryGetValue(spec.ToLower(CultureInfo.CurrentCulture), out handler);

                    byte[] responseData;
                    if (handler != null)
                    {
                        LOGGER.Log(Level.Info, "HttpHandler OnNext, get eventHandler:" + handler.GetSpecification());
                        handler.OnHttpRequest(request, response);
                        responseData = response.OutputStream;
                    }
                    else
                    {
                        responseData =
                            ByteUtilities.StringToByteArrays(string.Format(CultureInfo.CurrentCulture, "No event handler found at CLR side for {0}.", spec));
                    }
                    httpMessage.SetQueryResponseData(responseData);
                }
            }
        }
Example #2
0
        public void TestHttpRequestSerializationJasonRoundTrip()
        {
            AvroHttpRequest r = CreatAvorHttpRequest();

            string str = AvroHttpSerializer.ToJson(r);

            byte[] bytes = ByteUtilities.StringToByteArrays(str);
            var    r1    = AvroHttpSerializer.FromBytesWithJoson(bytes);

            var ri  = ByteUtilities.ByteArrarysToString(r.InputStream);
            var ri1 = ByteUtilities.ByteArrarysToString(r1.InputStream);

            Assert.AreEqual(ri, ri1);
            Assert.AreEqual(r.QueryString, r1.QueryString);
        }