private void innerTestCantCopyWithoutUserProject( boolean sourceNormal, boolean destNormal, Path source, Path dest) throws IOException { String sdesc = (sourceNormal ? "normal bucket" : "requester-pays bucket"); String ddesc = (destNormal ? "normal bucket" : "requester-pays bucket"); String description = "Copying from " + sdesc + " to " + ddesc; try { Files.copy(source, dest); Assert.fail("Shouldn't have been able to copy from " + sdesc + " to " + ddesc); // for some reason this throws "GoogleJsonResponseException" instead of "StorageException" // when going from requester pays bucket to requester pays bucket, but otherwise we get a // normal StorageException. } catch (HttpResponseException hex) { Assert.assertEquals(description, hex.getStatusCode(), 400); Assert.assertTrue( description, hex.getMessage() .contains("Bucket is requester pays bucket but no user project provided")); } catch (StorageException ex) { assertIsRequesterPaysException(description, ex); } }
} catch (HttpResponseException e) { System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace();
System.err.println(e.getMessage()); } catch (IOException e) {
/** * Triggers the authentication process for the associated {@code username}. */ public void getUserAuthenticated() throws IOException { // assume user is authenticated before service = new GmailServiceMaker(username).makeGmailService(); while (true) { try { // touch one API endpoint to check authentication getListOfUnreadEmailOfUser(); break; } catch (HttpResponseException e) { if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_FORBIDDEN || e.getStatusCode() == HttpStatusCodes.STATUS_CODE_UNAUTHORIZED || e.getStatusCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST) { System.out.println(e.getMessage()); // existing credential missing or not working, should do authentication for the account again service = new GmailServiceMaker(username, true).makeGmailService(); } else { throw new IOException(e); } } } }
public static DoubanException handleHttpResponseError (HttpResponseException ex) { return new DoubanException(HTTP_RESPONSE_ERROR_STATUS_CODE, "HttpResponseException : http status : " + ex.getStatusCode() + " message : " + ex.getMessage()); }
LOG.debug("retrying 502: " + e.getMessage() + ", i=" + i); try {
return null; throw new IOException(ex.getMessage());
logger.error(e.getMessage()); throw new IOException(e.getMessage());
logger.error(e.getMessage()); throw new IOException(e.getMessage());
logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage());
public static String getLatestRevision(ServerProfile profile) throws IOException { // trying to construct the URL like // https://api.enterprise.apigee.com/v1/organizations/apigee-cs/apis/taskservice/ // response is like // { // "name" : "taskservice1", // "revision" : [ "1" ] // } String revision = ""; HttpRequest restRequest = REQUEST_FACTORY .buildGetRequest(new GenericUrl(profile.getHostUrl() + "/" + profile.getApi_version() + "/organizations/" + profile.getOrg() + "/apis/" + profile.getApplication() + "/")); restRequest.setReadTimeout(0); HttpHeaders headers = new HttpHeaders(); headers.setAccept("application/json"); restRequest.setHeaders(headers); try { HttpResponse response = executeAPI(profile, restRequest); AppRevision apprev = response.parseAs(AppRevision.class); Collections.sort(apprev.revision, new StringToIntComparator()); revision = apprev.revision.get(0); logger.info(PrintUtil.formatResponse(response, gson.toJson(apprev).toString())); } catch (HttpResponseException e) { logger.error(e.getMessage()); } return revision; }
public static void getRevision(ServerProfile profile) throws IOException { // trying to construct the URL like // https://api.enterprise.apigee.com/v1/organizations/apigee-cs/apis/taskservice/ // response is like // { // "name" : "taskservice1", // "revision" : [ "1" ] // } HttpRequest restRequest = REQUEST_FACTORY .buildGetRequest(new GenericUrl(profile.getHostUrl() + "/" + profile.getApi_version() + "/organizations/" + profile.getOrg() + "/apis/" + profile.getApplication() + "/")); restRequest.setReadTimeout(0); HttpHeaders headers = new HttpHeaders(); headers.setAccept("application/json"); restRequest.setHeaders(headers); try { HttpResponse response = executeAPI(profile, restRequest); AppRevision apprev = response.parseAs(AppRevision.class); Collections.sort(apprev.revision, new StringToIntComparator()); setVersionRevision(apprev.revision.get(0)); logger.info(PrintUtil.formatResponse(response, gson.toJson(apprev).toString())); } catch (HttpResponseException e) { logger.error(e.getMessage()); } }
logger.error(e.getMessage());
@Override public void registerRunner() throws IOException { Registration reg = new Registration(); reg.token = config.getNextToken(); reg.publicKey = config.getPublicKey(); JsonHttpContent content = new JsonHttpContent(JSON_FACTORY, reg); HttpRequest request = requestFactory.buildPostRequest(registerUrl, content); logger.log(Level.INFO, "trying to register runner at {0}", registerUrl.toString()); RegistrationToken regToken = null; try { HttpResponse response = request.execute(); if (response.isSuccessStatusCode()) { //content(response); regToken = response.parseAs(RegistrationToken.class); } else { logger.log(Level.SEVERE, "failed to register as gilab runner at {0}", registerUrl.toString()); } } catch (HttpResponseException ex) { logger.log(Level.SEVERE, "failed to register gilab runner with token = '{2}' at {0}, " + "because of {1}", new Object[]{registerUrl.toString(), ex.getMessage(), reg.token}); } if (regToken == null || regToken.id == 0) { throw new IOException("failed to register gilab runner"); } config.setToken(regToken.token); logger.log(Level.INFO, "registered runner with ID = {0}", regToken.id); config.saveConfig(); }
/** Tests that a non-retriable error is not retried. */ @Test public void testErrorCodeForbidden() throws IOException { when(mockLowLevelRequest.execute()).thenReturn(mockLowLevelResponse); when(mockLowLevelResponse.getStatusCode()) .thenReturn(403) // Non-retryable error. .thenReturn(200); // Shouldn't happen. try { Storage.Buckets.Get result = storage.buckets().get("test"); HttpResponse response = result.executeUnparsed(); assertNotNull(response); } catch (HttpResponseException e) { assertThat(e.getMessage(), Matchers.containsString("403")); } verify(mockHttpResponseInterceptor).interceptResponse(any(HttpResponse.class)); verify(mockLowLevelRequest, atLeastOnce()).addHeader(anyString(), anyString()); verify(mockLowLevelRequest).setTimeout(anyInt(), anyInt()); verify(mockLowLevelRequest).setWriteTimeout(anyInt()); verify(mockLowLevelRequest).execute(); verify(mockLowLevelResponse).getStatusCode(); expectedLogs.verifyWarn("Request failed with code 403"); }
logger.error(e.getMessage());
protected APIException getAPIException(HttpResponseException ex) { try { APIExceptionMessage exceptionMessage = fromJson(ex.getContent(), TypeReferenceFactory.getTypeRef(APIExceptionMessage.class)); return new APIException(ex.getStatusCode(), exceptionMessage.getMessage(), ex); } catch (APIException e) { return new APIException(ex.getStatusCode(), ex.getMessage()); } }