Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////

        public void get(HttpRequestAdapter requestAdapter, Authenticator authenticator, HttpResponseHandler responseAdapter)
        {
            HttpWebRequest request = buildGetRequest(requestAdapter, authenticator);
            int statusCode = dispatch(request, authenticator, responseAdapter);

            if (401 == statusCode)
            {
                request = buildGetRequest(requestAdapter, authenticator);
                statusCode = dispatch(request, authenticator, responseAdapter);
            }

            if (statusCode < 200 || statusCode > 299)
            {
                BaseException e = new BaseException(this, HttpStatus.getReason(statusCode));
                e.FaultCode = statusCode;
                String requestUri = requestAdapter.RequestUri;
                e.addContext("requestUri", requestUri);
                throw e;
            }

        }
Ejemplo n.º 2
0
        public void post(HttpRequestAdapter requestAdapter, HttpResponseHandler responseAdapter)
        {
            HttpWebRequest request = buildPostRequest(requestAdapter, null);
            int statusCode = dispatch(request, null, responseAdapter);

            if (statusCode < 200 || statusCode > 299)
            {
                BaseException e = new BaseException(this, HttpStatus.getReason(statusCode));
                e.FaultCode = statusCode;
                String requestUri = requestAdapter.RequestUri;
                e.addContext("requestUri", requestUri);
                throw e;
            }

        }
        public static BaseException toBaseException(JsonObject jsonObject)
        {

            String originator = jsonObject.GetString("originator", "NULL");
            String fault_string = jsonObject.GetString("faultMessage", "NULL");

            BaseException answer = new BaseException(originator, fault_string);

            {
                String errorDomain = jsonObject.GetString("errorDomain", null);
                answer.ErrorDomain = errorDomain;
            }

            int faultCode = jsonObject.GetInt("faultCode", BaseException.DEFAULT_FAULT_CODE);
            answer.FaultCode = faultCode;

            String underlyingFaultMessage = jsonObject.GetString("underlyingFaultMessage", null);
            answer.UnderlyingFaultMessage = underlyingFaultMessage;

            JsonArray stack_trace = jsonObject.GetJsonArray("stackTrace", null);
            if (null != stack_trace)
            {
                for (int i = 0, count = stack_trace.Count(); i < count; i++)
                {
                    String key = "cause[" + i + "]";
                    String value = stack_trace.GetString(i, "NULL");
                    answer.addContext(key, value);
                }
            }

            JsonObject fault_context = jsonObject.GetJsonObject("faultContext", null);
            if (null != fault_context)
            {
                foreach (KeyValuePair<string, object> kvp in fault_context)
                {
                    Object value = kvp.Value;
                    if (null != value && value is String)
                    {
                        String key = kvp.Key;
                        answer.addContext(key, (String)value);
                    }
                }
            }
            return answer;
        }