private HttpResponse fetchFromServer(HttpRequest request) throws OAuthRequestException { HttpResponse response = null; try { response = fetcher.fetch(request); if (response == null) { throw new OAuthRequestException(OAuthError.MISSING_SERVER_RESPONSE); } return response; } catch (GadgetException e) { throw new OAuthRequestException(OAuthError.MISSING_SERVER_RESPONSE, "", e); } finally { responseParams.addRequestTrace(request, response); } }
private HttpResponse fetchFromServer(HttpRequest request) throws OAuthRequestException { HttpResponse response = null; try { response = fetcher.fetch(request); if (response == null) { throw new OAuthRequestException(OAuthError.MISSING_SERVER_RESPONSE); } return response; } catch (GadgetException e) { throw new OAuthRequestException(OAuthError.MISSING_SERVER_RESPONSE, "", e); } finally { responseParams.addRequestTrace(request, response); } }
private HttpResponse fetchFromServer(HttpRequest request) throws OAuthRequestException { HttpResponse response = null; try { response = fetcher.fetch(request); if (response == null) { throw new OAuthRequestException(OAuthError.MISSING_SERVER_RESPONSE); } return response; } catch (GadgetException e) { throw new OAuthRequestException(OAuthError.MISSING_SERVER_RESPONSE, "", e); } finally { responseParams.addRequestTrace(request, response); } }
@Test public void testNullSafe() { params.addRequestTrace(null, null); new OAuthRequestException("error", "errorText"); params.logDetailedWarning("org.apache.shindig.gadgets.oauth.OAuthResponseParamsTest","testNullSafe","wow"); params.logDetailedWarning("org.apache.shindig.gadgets.oauth.OAuthResponseParamsTest","testNullSafe","new runtime", new RuntimeException()); }
@Test public void testNullSafe() { params.addRequestTrace(null, null); new OAuthRequestException("error", "errorText"); params.logDetailedWarning("org.apache.shindig.gadgets.oauth.OAuthResponseParamsTest","testNullSafe","wow"); params.logDetailedWarning("org.apache.shindig.gadgets.oauth.OAuthResponseParamsTest","testNullSafe","new runtime", new RuntimeException()); }
@Test public void testNullSafe() { params.addRequestTrace(null, null); new OAuthRequestException("error", "errorText"); params.logDetailedWarning("wow"); params.logDetailedWarning("new runtime", new RuntimeException()); }
@Test public void testException() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); params.addRequestTrace(req, ok); OAuthRequestException e = new OAuthRequestException("error", "errorText"); checkStringContains(e.toString(), "[error,errorText]"); params.addRequestTrace(null, null); Throwable cause = new RuntimeException(); e = new OAuthRequestException(OAuthError.UNAUTHENTICATED, "errorText", cause); checkStringContains(e.toString(), "[UNAUTHENTICATED,Unauthenticated OAuth fetch]"); assertEquals(cause, e.getCause()); }
@Test public void testSendTraceToClient() { OAuthRequestException e = new OAuthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION, "whoa there cowboy"); params.addRequestTrace(null, null); params.addRequestTrace(null, null); HttpResponseBuilder responseBuilder = new HttpResponseBuilder(); params.addToResponse(responseBuilder, e); HttpResponse response = responseBuilder.create(); String errorText = response.getMetadata().get("oauthErrorText"); assertEquals("whoa there cowboy", errorText); params.setSendTraceToClient(true); params.addToResponse(responseBuilder, e); response = responseBuilder.create(); errorText = response.getMetadata().get("oauthErrorText"); checkStringContains("includes error text", errorText, "whoa there cowboy"); checkStringContains("Request 1 logged", errorText, "Sent request 1:\n\n"); checkStringContains("Request 2 logged", errorText, "Sent request 2:\n\n"); }
@Test public void testException() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); params.addRequestTrace(req, ok); OAuthRequestException e = new OAuthRequestException("error", "errorText"); checkStringContains(e.toString(), "[error,errorText]"); params.addRequestTrace(null, null); Throwable cause = new RuntimeException(); e = new OAuthRequestException(OAuthError.UNAUTHENTICATED, "errorText", cause); checkStringContains(e.toString(), "[UNAUTHENTICATED,Unauthenticated OAuth fetch]"); assertEquals(cause, e.getCause()); }
@Test public void testSendTraceToClient() { OAuthRequestException e = new OAuthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION, "whoa there cowboy"); params.addRequestTrace(null, null); params.addRequestTrace(null, null); HttpResponseBuilder responseBuilder = new HttpResponseBuilder(); params.addToResponse(responseBuilder, e); HttpResponse response = responseBuilder.create(); String errorText = response.getMetadata().get("oauthErrorText"); assertEquals("whoa there cowboy", errorText); params.setSendTraceToClient(true); params.addToResponse(responseBuilder, e); response = responseBuilder.create(); errorText = response.getMetadata().get("oauthErrorText"); checkStringContains("includes error text", errorText, "whoa there cowboy"); checkStringContains("Request 1 logged", errorText, "Sent request 1:\n\n"); checkStringContains("Request 2 logged", errorText, "Sent request 2:\n\n"); }
@Test public void testException() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); params.addRequestTrace(req, ok); OAuthRequestException e = new OAuthRequestException("error", "errorText"); checkStringContains(e.toString(), "[error,errorText]"); params.addRequestTrace(null, null); Throwable cause = new RuntimeException(); e = new OAuthRequestException(OAuthError.UNAUTHENTICATED, "errorText", cause); checkStringContains(e.toString(), "[UNAUTHENTICATED,Unauthenticated OAuth fetch]"); assertEquals(cause, e.getCause()); }
@Test public void testSendTraceToClient() { OAuthRequestException e = new OAuthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION, "whoa there cowboy"); params.addRequestTrace(null, null); params.addRequestTrace(null, null); HttpResponseBuilder responseBuilder = new HttpResponseBuilder(); params.addToResponse(responseBuilder, e); HttpResponse response = responseBuilder.create(); String errorText = response.getMetadata().get("oauthErrorText"); assertEquals("whoa there cowboy", errorText); params.setSendTraceToClient(true); params.addToResponse(responseBuilder, e); response = responseBuilder.create(); errorText = response.getMetadata().get("oauthErrorText"); checkStringContains("includes error text", errorText, "whoa there cowboy"); checkStringContains("Request 1 logged", errorText, "Sent request 1:\n\n"); checkStringContains("Request 2 logged", errorText, "Sent request 2:\n\n"); }
@Test public void testSawErrorResponse() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); HttpResponse redir = new HttpResponseBuilder().setHttpStatusCode(302).create(); HttpResponse notFound = new HttpResponseBuilder().setHttpStatusCode(404).create(); HttpResponse doh = new HttpResponseBuilder().setHttpStatusCode(502).create(); OAuthResponseParams params = new OAuthResponseParams(token, origRequest, crypter); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, ok); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, redir); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, null); assertTrue(params.sawErrorResponse()); params = new OAuthResponseParams(token, origRequest, crypter); params.addRequestTrace(req, notFound); assertTrue(params.sawErrorResponse()); params = new OAuthResponseParams(token, origRequest, crypter); params.addRequestTrace(req, doh); assertTrue(params.sawErrorResponse()); params.addRequestTrace(req, ok); assertTrue(params.sawErrorResponse()); }
@Test public void testSawErrorResponse() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); HttpResponse redir = new HttpResponseBuilder().setHttpStatusCode(302).create(); HttpResponse notFound = new HttpResponseBuilder().setHttpStatusCode(404).create(); HttpResponse doh = new HttpResponseBuilder().setHttpStatusCode(502).create(); OAuthResponseParams params = new OAuthResponseParams(token, origRequest, crypter); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, ok); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, redir); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, null); assertTrue(params.sawErrorResponse()); params = new OAuthResponseParams(token, origRequest, crypter); params.addRequestTrace(req, notFound); assertTrue(params.sawErrorResponse()); params = new OAuthResponseParams(token, origRequest, crypter); params.addRequestTrace(req, doh); assertTrue(params.sawErrorResponse()); params.addRequestTrace(req, ok); assertTrue(params.sawErrorResponse()); }
@Test public void testSawErrorResponse() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); HttpResponse redir = new HttpResponseBuilder().setHttpStatusCode(302).create(); HttpResponse notFound = new HttpResponseBuilder().setHttpStatusCode(404).create(); HttpResponse doh = new HttpResponseBuilder().setHttpStatusCode(502).create(); OAuthResponseParams params = new OAuthResponseParams(token, origRequest, crypter); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, ok); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, redir); assertFalse(params.sawErrorResponse()); params.addRequestTrace(req, null); assertTrue(params.sawErrorResponse()); params = new OAuthResponseParams(token, origRequest, crypter); params.addRequestTrace(req, notFound); assertTrue(params.sawErrorResponse()); params = new OAuthResponseParams(token, origRequest, crypter); params.addRequestTrace(req, doh); assertTrue(params.sawErrorResponse()); params.addRequestTrace(req, ok); assertTrue(params.sawErrorResponse()); }