示例#1
0
 /**
  * OAuth authenticated fetch.
  */
 public sResponse fetch(sRequest request)
 {
     realRequest = request;
     clientState = new OAuthClientState(
         fetcherConfig.getStateCrypter(),
         request.getOAuthArguments().getOrigClientState());
     responseParams = new OAuthResponseParams(request.getSecurityToken(), request, fetcherConfig.getStateCrypter());
     try
     {
         return(fetchNoThrow());
     }
     catch (Exception e)
     {
         // We log here to record the request/response pairs that created the failure.
         responseParams.logDetailedWarning("OAuth fetch unexpected fatal error", e);
         throw e;
     }
 }
示例#2
0
        public override void Fetch(HttpRequestWrapper request, HttpResponseWrapper response)
        {
            sRequest rcr = buildHttpRequest(request);

            // Serialize the response
            sResponse results = requestPipeline.execute(rcr);

            // Rewrite the response
            if (contentRewriterRegistry != null)
            {
                results = contentRewriterRegistry.rewriteHttpResponse(rcr, results);
            }

            // Serialize the response
            String output = convertResponseToJson(rcr.getSecurityToken(), request, results);

            // Find and set the refresh interval
            SetResponseHeaders(request, response.getResponse(), results);

            response.setStatus((int)HttpStatusCode.OK);
            response.setContentType("application/json");
            response.getResponse().ContentEncoding = Encoding.UTF8;
            response.Write(Encoding.UTF8.GetBytes(UNPARSEABLE_CRUFT + output));
        }
示例#3
0
        /**
         * Fetch data and build a response to return to the client.  We try to always return something
         * reasonable to the calling app no matter what kind of madness happens along the way.  If an
         * unchecked exception occurs, well, then the client is out of luck.
         */
        private sResponse fetchNoThrow()
        {
            HttpResponseBuilder response = null;

            try
            {
                accessorInfo = fetcherConfig.getTokenStore().getOAuthAccessor(
                    realRequest.getSecurityToken(), realRequest.getOAuthArguments(), clientState,
                    responseParams);
                response = fetchWithRetry();
            }
            catch (OAuthResponseParams.OAuthRequestException e)
            {
                // No data for us.
                responseParams.logDetailedWarning("OAuth fetch fatal error", e);
                responseParams.setSendTraceToClient(true);
                if (response == null)
                {
                    response = new HttpResponseBuilder()
                               .setHttpStatusCode(sResponse.SC_FORBIDDEN);
                    responseParams.addToResponse(response);
                    return(response.create());
                }
            }

            // OK, got some data back, annotate it as necessary.
            if (response.getHttpStatusCode() >= 400)
            {
                responseParams.logDetailedWarning("OAuth fetch fatal error");
                responseParams.setSendTraceToClient(true);
            }
            else if (responseParams.getAznUrl() != null && responseParams.sawErrorResponse())
            {
                responseParams.logDetailedWarning("OAuth fetch error, reprompting for user approval");
                responseParams.setSendTraceToClient(true);
            }

            responseParams.addToResponse(response);

            return(response.create());
        }