List of usage examples for org.springframework.web.client HttpClientErrorException getStatusCode
public HttpStatus getStatusCode()
From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java
private static String testUriSchemes(CloudFoundryClient client, String[] uriSchemes, String uriAuthority) { int i = 0;/* w w w . j a v a2 s.co m*/ int retries = 0; String scheme = null; while (i < uriSchemes.length) { scheme = uriSchemes[i]; String uriToUse = scheme + "//" + uriAuthority; try { getTunnelProtocolVersion(client, uriToUse); break; } catch (HttpClientErrorException e) { if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) { if (retries < 10) { retries++; } else { throw new TunnelException("Not able to locate tunnel server at: " + uriToUse, e); } } else { throw new TunnelException("Error accessing tunnel server at: " + uriToUse, e); } } catch (ResourceAccessException e) { if (e.getMessage().contains("refused") || e.getMessage().contains("unable")) { i++; } else { throw e; } } catch (RuntimeException e) { throw e; } } return scheme; }
From source file:com.hemou.android.account.AccountUtils.java
/** * Is the given {@link Exception} due to a 401 Unauthorized API response? * //from ww w . j a v a2 s .co m * @param e * @return true if 401, false otherwise */ public static boolean isUnauthorized(final Exception e) { Log.e(TAG, "Exception occured[" + Thread.currentThread().getId() + "]:{type:" + e.getClass().getName() + "," + e.getLocalizedMessage() + "}"); String errorMess = e.getMessage(); if (!StringUtils.isEmpty(errorMess) && (errorMess.contains("The authorization has expired") || errorMess.contains("401 Unauthorized") || errorMess.contains("403 Forbidden"))) return true; if (e instanceof NotAuthorizedException) { Log.e(TAG, "?..."); return true; } // if (e instanceof ResourceAccessException) // return true; if (e instanceof HttpClientErrorException) { HttpClientErrorException expt = (HttpClientErrorException) e; HttpStatus status = expt.getStatusCode(); if (Arrays.asList(HttpStatus.UNAUTHORIZED, HttpStatus.NETWORK_AUTHENTICATION_REQUIRED, HttpStatus.NON_AUTHORITATIVE_INFORMATION, HttpStatus.PROXY_AUTHENTICATION_REQUIRED, //403?????? HttpStatus.FORBIDDEN).contains(status)) return true; } return false; }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
public static boolean isWrongCredentialsException(CoreException e) { Throwable cause = e.getCause(); if (cause instanceof HttpClientErrorException) { HttpClientErrorException httpException = (HttpClientErrorException) cause; HttpStatus statusCode = httpException.getStatusCode(); if (statusCode.equals(HttpStatus.FORBIDDEN) && httpException instanceof CloudFoundryException) { return ((CloudFoundryException) httpException).getDescription().equals("Operation not permitted"); //$NON-NLS-1$ }//from ww w. j av a2 s.c o m } return false; }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
/** * //from www .j a va 2 s .c om * @param e to check if it is a Bad Request 400 HTTP Error. * @return determines if the given exception is a Bad Request 400 Exception. * If so, returns it the corresponding HttpClientErrorException. Otherwise * returns null. */ public static HttpClientErrorException getBadRequestException(Exception t) { HttpClientErrorException httpException = getHttpClientError(t); if (httpException != null) { HttpStatus statusCode = httpException.getStatusCode(); if (HttpStatus.BAD_REQUEST.equals(statusCode)) { return httpException; } } return null; }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
public static boolean isHttpException(Throwable t, HttpStatus status) { HttpClientErrorException httpException = getHttpClientError(t); if (httpException != null) { HttpStatus statusCode = httpException.getStatusCode(); return statusCode.equals(status); }// w ww . j av a2 s .co m return false; }
From source file:io.pivotal.Migrate.java
@Override public void run(String... strings) throws Exception { try {//from w w w. j a v a 2s . c o m github.deleteRepository(); } catch (HttpClientErrorException e) { if (e.getStatusCode().value() != HttpStatus.NOT_FOUND.value()) { throw e; } } System.out.println("Creating a test repository to place the issues in"); github.createRepository(); System.out.println("Finding the project info"); JiraProject project = jira.findProject(getJiraProjectId()); System.out.println("Creating Milestones"); github.createMilestones(project.getVersions()); System.out.println("Creating Labels"); github.createComponentLabels(project.getComponents()); github.createIssueTypeLabels(project.getIssueTypes()); System.out.println("Getting JIRA issues"); List<JiraIssue> issues = jira.findIssues(jiraConfig.getMigrateJql()); System.out.println("Found " + issues.size() + " JIRA issues to migrate"); System.out.println("Creating issues"); github.createIssues(issues); }
From source file:org.osmtools.ra.context.RelationLoaderService.java
@Cacheable("relation") public Relation loadRelation(long relationId) { try {// w ww. ja v a 2 s .co m Osm osmRoot = restOperations.getForObject(GET_RELATION_URL, Osm.class, String.valueOf(relationId)); List<Relation> list = converterService.convert(osmRoot); for (Relation relation : list) { if (relationId == relation.getRelationId()) return relation; } throw new RuntimeException("Relation ID " + relationId + " not found"); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.GONE) { throw new RelationGoneException(); } else throw e; } }
From source file:com.alexshabanov.springrestapi.XmlDrivenConfigTest.java
@Test public void shouldThrowHttpClientErrorExceptionWithBadRequest() { doThrow(IllegalArgumentException.class).when(profileController).deleteProfile(id); try {//from ww w .j av a2s.c om restClient.delete(path(CONCRETE_PROFILE_RESOURCE), id); } catch (HttpClientErrorException e) { assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); } }
From source file:io.spring.initializr.web.project.MainControllerServiceMetadataIntegrationTests.java
@Test public void textPlainNotAccepted() { try {//from ww w. j a v a 2 s .c om execute("/metadata/config", String.class, null, "text/plain"); } catch (HttpClientErrorException ex) { assertEquals(HttpStatus.NOT_ACCEPTABLE, ex.getStatusCode()); } }
From source file:net.orpiske.tcs.service.rest.functional.DomainCreateTest.java
@Test public void testAuthenticationError() { HttpEntity<Domain> requestEntity = new HttpEntity<Domain>(RestDataFixtures.customCsp(), getHeaders(USERNAME + ":" + BAD_PASSWORD)); RestTemplate template = new RestTemplate(); try {/*from w w w. jav a 2 s. c om*/ ResponseEntity<Domain> responseEntity = template .postForEntity("http://localhost:8080/tcs/domain/terra.com.br", requestEntity, Domain.class); fail("Request Passed incorrectly with status " + responseEntity.getStatusCode()); } catch (HttpClientErrorException e) { assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode()); } }