Esempio n. 1
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());
        }
Esempio n. 2
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;
     }
 }