List of usage examples for org.springframework.web.client RestClientException RestClientException
public RestClientException(String msg)
From source file:org.openmrs.module.webservices.rest.resource.InventoryStockTakeResource.java
@Override public InventoryStockTake save(InventoryStockTake delegate) { // Ensure that the current user can process the operation if (!userCanProcessAdjustment()) { throw new RestClientException("The current user not authorized to process this operation."); }/*ww w.j a v a2s .c o m*/ StockOperation operation = createOperation(delegate); operationService.submitOperation(operation); return newDelegate(); }
From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java
public synchronized <T> T getFromControlApps(String urlPrefix, TypeReference<?> typeRef) throws Exception { String result;//from w w w . j a v a 2 s . c om try { String url = mkUrl(urlPrefix); result = restTemplate.getForObject(url, String.class); if (result == null) return null; } catch (Throwable e) { throw new Exception("Failed to communicate with controlapps. Is it up?"); } try { T t = objMapper.readValue(result, typeRef); return t; } catch (Throwable e) { throw new RestClientException( "Internal error parsing the result. Please try again later or restart controlapps."); } }
From source file:gateway.test.AlertTriggerTests.java
/** * Test POST /trigger/*from ww w. j a v a2s.c o m*/ * * @throws JsonProcessingException */ @Test public void testCreateTrigger() throws JsonProcessingException { // Mock Response when(restTemplate.postForObject(anyString(), any(), eq(String.class))).thenReturn(any(String.class)); // Test ResponseEntity<?> response = alertTriggerController.createTrigger(new Trigger(), user); // Verify assertTrue(response.getStatusCode().equals(HttpStatus.CREATED)); // Test Exception when(restTemplate.postForObject(anyString(), any(), eq(String.class))) .thenThrow(new RestClientException("Trigger Error")); response = alertTriggerController.createTrigger(new Trigger(), user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("Trigger Error")); }
From source file:de.codecentric.boot.admin.services.ApplicationRegistratorTest.java
@Test public void register_failed() { when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Application.class))) .thenThrow(new RestClientException("Error")); assertFalse(registrator.register()); }
From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java
@Override public List<Submission> findAllSubmission() { HttpHeaders headers = new HttpHeaders(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); HttpEntity<String> request = new HttpEntity<String>(headers); ResponseEntity<String> response = restTemplate.exchange(getSubmissionUrlTemplate(), HttpMethod.GET, request, String.class); String responseBody = response.getBody(); try {/* w w w . ja v a 2s . c o m*/ if (RestUtil.isError(response.getStatusCode())) { ErrorResource error = objectMapper.readValue(responseBody, ErrorResource.class); throw new RestClientException("[" + error.getCode() + "] " + error.getMessage()); } else { SubmissionResources resources = objectMapper.readValue(responseBody, SubmissionResources.class); // SubmissionResources resources = restTemplate.getForObject(getSubmissionUrlTemplate(), SubmissionResources.class); if (resources == null || CollectionUtils.isEmpty(resources.getContent())) { return Collections.emptyList(); } Link listSelfLink = resources.getLink(Link.REL_SELF); Collection<SubmissionResource> content = resources.getContent(); if (!content.isEmpty()) { SubmissionResource firstSubmissionResource = content.iterator().next(); Link linkToFirstResource = firstSubmissionResource.getLink(Link.REL_SELF); System.out.println("href = " + linkToFirstResource.getHref()); System.out.println("rel = " + linkToFirstResource.getRel()); } return resources.unwrap(); // return resources; } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.trustedanalytics.servicebroker.h2o.service.H2oProvisionerClientTest.java
@Test public void provisionInstance_provisionerEndsWithException_exceptionRethrown() throws Exception { // arrange//from w ww . j ava2 s .c o m expectedException.expect(ServiceBrokerException.class); expectedException.expectMessage("Unable to provision h2o for: " + INSTANCE_ID); when(h2oRestMock.createH2oInstance(INSTANCE_ID, H2O_NODES, H2O_MEMORY, KERBEROS, YARN_CONF)) .thenThrow(new RestClientException("")); // act h2oProvisioner.provisionInstance(INSTANCE_ID); }
From source file:de.codecentric.boot.admin.services.ApplicationRegistratorTest.java
@SuppressWarnings("rawtypes") @Test/*from www. j a v a 2s. co m*/ public void register_retry() { when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Application.class))) .thenThrow(new RestClientException("Error")); when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class))) .thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"), HttpStatus.CREATED)); assertTrue(registrator.register()); }
From source file:gateway.test.EventTests.java
/** * Test GET /event//ww w . j a va2s. c om */ @Test public void testGetEvents() { // Mock Response when(restTemplate.getForEntity(anyString(), eq(String.class))) .thenReturn(new ResponseEntity<String>("event", HttpStatus.OK)); // Test ResponseEntity<?> response = eventController.getEvents(null, null, null, null, 0, 10, user); // Verify assertTrue(response.getBody().toString().equals("event")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test REST Exception when(restTemplate.getForEntity(anyString(), eq(String.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, WORKFLOW_ERROR)); response = eventController.getEvents(null, null, null, null, 0, 10, user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); // Test General Exception when(restTemplate.getForEntity(anyString(), eq(String.class))) .thenThrow(new RestClientException("event error")); response = eventController.getEvents(null, null, null, null, 0, 10, user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("event error")); // Test Validation Input Exception when(gatewayUtil.validateInput(anyString(), any())).thenReturn("Error"); response = eventController.getEvents(null, null, null, null, 0, 10, user); assertTrue(response.getStatusCode().equals(HttpStatus.BAD_REQUEST)); assertTrue(response.getBody() instanceof ErrorResponse); }
From source file:com.capitalone.dashboard.collector.DefaultNexusIQClientTest.java
@Test public void getApplications404() throws Exception { settings.setSelectStricterLicense(true); String appJson = getJson("applications.json"); String instanceUrl = "http://nexusiq.com"; String appListUrl = "http://nexusiq.com/api/v2/applications"; doThrow(new RestClientException("404")).when(rest).exchange(eq(appListUrl), eq(HttpMethod.GET), Matchers.any(HttpEntity.class), eq(String.class)); List<NexusIQApplication> apps = defaultNexusIQClient.getApplications(instanceUrl); assertThat(apps.size(), is(0));/*from ww w .j a v a 2 s.c om*/ }
From source file:org.cloudfoundry.identity.uaa.login.ChangePasswordControllerTest.java
@Test public void testChangePasswordWrongPassword() throws Exception { setupSecurityContext();/*from w ww . ja v a 2s .c om*/ Mockito.doThrow(new RestClientException("401 Unauthorized")).when(changePasswordService) .changePassword("bob", "wrong", "new secret"); MockHttpServletRequestBuilder post = post("/change_password.do").contentType(APPLICATION_FORM_URLENCODED) .param("current_password", "wrong").param("new_password", "new secret") .param("confirm_password", "new secret"); mockMvc.perform(post).andExpect(status().isUnprocessableEntity()).andExpect(view().name("change_password")) .andExpect(model().attribute("message_code", "unauthorized")); }