List of usage examples for org.springframework.web.client HttpStatusCodeException getStatusCode
public HttpStatus getStatusCode()
From source file:org.syncope.core.rest.ResourceTestITCase.java
@Test public void deleteWithException() { try {/*from w ww . ja v a2 s . c o m*/ restTemplate.delete(BASE_URL + "resource/delete/{resourceName}.json", "resourcenotfound"); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode()); } }
From source file:org.syncope.core.rest.ResourceTestITCase.java
@Test public void updateWithException() { try {/*from w w w . ja v a 2 s. c o m*/ ResourceTO resourceTO = new ResourceTO(); resourceTO.setName("resourcenotfound"); restTemplate.postForObject(BASE_URL + "resource/update.json", resourceTO, ResourceTO.class); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode()); } }
From source file:org.syncope.core.rest.ResourceTestITCase.java
@Test public void delete() { final String resourceName = "ws-target-resource-delete"; restTemplate.delete(BASE_URL + "resource/delete/{resourceName}.json", resourceName); try {/*from w w w .j a v a 2 s. c o m*/ restTemplate.getForObject(BASE_URL + "resource/read/{resourceName}.json", ResourceTO.class, resourceName); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode()); } }
From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java
/** * Returns the workpool identified by the id passed. * * @param id/*w ww . j a v a2 s . co m*/ * @return * @throws WpException */ public Workpool getWorkpoolById(Long id) throws WpException, AfNotFoundException { if (id == null) { throw new WpException("Invalid input"); } try { return _rest.getForObject(baseUrl() + "/workpools/{id}", Workpool.class, id); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.NOT_FOUND) { throw new AfNotFoundException("NOT_FOUND: " + ex.getMessage()); } throw new WpException(ex); } catch (RestClientException e) { throw new WpException(e); } }
From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java
/** * Used to create a workpool. This call can create workpools of Full, * linked, Custom types./*ww w .ja va 2 s .c o m*/ * * NOTE: The created workpool or the Id is not returned as its not needed * at this point in time. If needed @see VmImage.createVmImage() * * @param workpool * @return * @throws WpException, AfConflictException */ public Long createWorkpool(Workpool workpool) throws WpException, AfConflictException { try { // This method does not return the URI uri = _rest.postForLocation(baseUrl() + "/workpools", workpool); return Long.valueOf(AfUtil.extractLastURIToken(uri)); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.CONFLICT) { throw new AfConflictException("CONFLICT_NAME: " + ex.getMessage()); } throw new WpException("Workpool cannot be created: " + ex.getMessage()); } catch (RestClientException e) { throw new WpException("Workpool cannot be created: " + e.getMessage()); } }
From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java
/** * Used to update a VM Image. Name field can be updated. * * @param workpool/* w w w . j a v a 2s. c o m*/ * @throws WpException */ public void updateWorkpool(Workpool workpool) throws WpException, AfNotFoundException, AfConflictException { Long id = workpool.getId(); try { _rest.put(baseUrl() + "/workpools/{id}", workpool, id); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.NOT_FOUND) { throw new AfNotFoundException("NOT_FOUND: " + ex.getMessage()); } else if (ex.getStatusCode() == HttpStatus.CONFLICT) { throw new AfConflictException("CONFLICT_NAME: " + ex.getMessage()); } throw new WpException("Workpool cannot be updated: " + ex.getMessage()); } catch (RestClientException e) { throw new WpException("Workpool cannot be updated: " + e.getMessage()); } }
From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java
/** * Returns the VmImage identified by the id passed. * * @param id/*www. j a va 2 s . co m*/ * @return * @throws WpException */ public VmImage getVmImageById(Long id) throws WpException, AfNotFoundException { if (id == null) { throw new WpException("Empty input"); } try { return _rest.getForObject(baseUrl() + "/vmimages/{id}", VmImage.class, id); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.NOT_FOUND) { throw new AfNotFoundException("NOT_FOUND: " + ex.getMessage()); } throw new WpException(ex); } catch (RestClientException e) { throw new WpException(e); } }
From source file:org.syncope.core.rest.ConnInstanceTestITCase.java
@Test public void deleteWithException() { try {//from w w w. j a va 2s. c o m restTemplate.delete(BASE_URL + "connector/delete/{connectorId}.json", "0"); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode()); } }
From source file:org.springframework.cloud.vault.util.PrepareVault.java
/** * Check whether Vault is available (vault created and unsealed). * * @return/*from w w w . j a va 2s . com*/ */ public boolean isAvailable() { Map<String, String> parameters = parameters(vaultProperties); ResponseEntity<String> exchange = null; try { exchange = restTemplate.getForEntity(SEAL_STATUS_URL_TEMPLATE, String.class, parameters); if (exchange.getStatusCode().is2xxSuccessful()) { return true; } } catch (HttpStatusCodeException e) { if (e.getStatusCode().is4xxClientError()) { return false; } } if (exchange.getStatusCode().is4xxClientError()) { return false; } throw new IllegalStateException("Vault error: " + exchange.toString()); }
From source file:org.syncope.core.rest.TaskTestITCase.java
@Test public void deal() { try {/*w w w.j a v a2s. c om*/ restTemplate.delete(BASE_URL + "task/delete/{taskId}", 0); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode()); } TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, 1); assertEquals(PropagationTaskExecStatus.SUBMITTED.name(), execution.getStatus()); execution = restTemplate.getForObject( BASE_URL + "task/execution/report/{executionId}" + "?executionStatus=SUCCESS&message=OK", TaskExecTO.class, execution.getId()); assertEquals(PropagationTaskExecStatus.SUCCESS.name(), execution.getStatus()); assertEquals("OK", execution.getMessage()); restTemplate.delete(BASE_URL + "task/delete/{taskId}", 1); try { restTemplate.getForObject(BASE_URL + "task/execution/read/{executionId}", TaskExecTO.class, execution.getId()); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode()); } }