List of usage examples for org.springframework.web.client RestTemplate getForEntity
@Override public <T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException
From source file:org.kurento.repository.test.util.HttpRepositoryTest.java
protected void downloadFromURL(String urlToDownload, File downloadedFile) throws Exception { RestTemplate template = getRestTemplate(); ResponseEntity<byte[]> entity = template.getForEntity(urlToDownload, byte[].class); assertEquals(HttpStatus.OK, entity.getStatusCode()); FileOutputStream os = new FileOutputStream(downloadedFile); os.write(entity.getBody());// www .j ava 2s. c om os.close(); }
From source file:org.zaizi.SensefyResourceApplicationTests.java
@Test public void testKeywordSearchAnauthorized() { RestTemplate template = new TestRestTemplate(); // keywordSearch ResponseEntity<String> response = template.getForEntity(baseTestServerUrl() + "keywordSearch", String.class); Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); }
From source file:org.bonitasoft.web.designer.studio.workspace.StudioWorkspaceResourceHandler.java
protected ResponseEntity<String> doGet(final Path filePath, String action) { if (restClient.isConfigured()) { final String url = createGetURL(filePath, action); RestTemplate restTemplate = restClient.getRestTemplate(); return restTemplate.getForEntity(URI.create(url), String.class); }/*from w w w .j a v a 2 s.c o m*/ return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); }
From source file:com.ge.predix.test.utils.PolicyHelper.java
public ResponseEntity<PolicySet> getPolicySet(final String policyName, final RestTemplate restTemplate, final String endpoint) { ResponseEntity<PolicySet> policySetResponse = restTemplate .getForEntity(endpoint + ACS_POLICY_SET_API_PATH + policyName, PolicySet.class); return policySetResponse; }
From source file:com.bcknds.demo.oauth2.security.ClientCredentialAuthenticationTests.java
/** * Test secure endpoint without authentication *///from w ww. j av a2 s . com @Test public void testSecureEndpointNoAuthentication() { RestTemplate restTemplate = new RestTemplate(); try { restTemplate.getForEntity(SECURE_ENDPOINT, String.class); fail("Exception expected. None was thrown."); } catch (HttpClientErrorException ex) { assertEquals(ex.getStatusCode(), HttpStatus.UNAUTHORIZED); } catch (ResourceAccessException ex) { fail("It appears that the server may not be running. Please start it before running tests"); } catch (Exception ex) { fail(ex.getMessage()); } }
From source file:com.bcknds.demo.oauth2.security.ClientCredentialAuthenticationTests.java
/** * Test authentication failure to method secure endpoint that requires only authentication * using no authentication/* ww w . j a va 2s . c o m*/ */ @Test public void testClientCredentialsMethodNotLoggedIn() { RestTemplate restTemplate = new RestTemplate(); try { restTemplate.getForEntity(METHOD_SECURE_ENDPOINT, String.class); fail("Expected exception. None was thrown."); } catch (HttpClientErrorException ex) { assertEquals(ex.getStatusCode(), HttpStatus.UNAUTHORIZED); } catch (ResourceAccessException ex) { fail("It appears that the server may not be running. Please start it before running tests"); } catch (Exception ex) { fail(ex.getMessage()); } }
From source file:com.ge.predix.test.utils.ZoneHelper.java
public Zone retrieveZone(final String zoneName) { try {/*from ww w . ja va 2s. c o m*/ RestTemplate acs = this.acsRestTemplateFactory.getACSTemplateWithPolicyScope(); ResponseEntity<Zone> responseEntity = acs.getForEntity(this.acsBaseUrl + ACS_ZONE_API_PATH + zoneName, Zone.class); return responseEntity.getBody(); } catch (RestClientException e) { LOGGER.error("Unexpected exception while retrieving a Zone with name " + zoneName, e); return null; } }
From source file:com.atwelm.aezwidget.data.ConfigurationServer.java
/** * Loads the layouts from the server and provides them in the callback if provided * @param callback Contains the layouts or error information *//* w w w.ja va2 s.c o m*/ public void loadLayouts(final LoadLayoutCallback callback) { final ConfigurationServer self = this; Thread t = new Thread(new Runnable() { @Override public void run() { try { RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new GsonHttpMessageConverter()); ResponseEntity<AEZFetchLayoutResponseInterface> responseEntity = restTemplate .getForEntity(mServerAddress, mServerType.getResponseClass()); int returnStatus = responseEntity.getStatusCode().value(); if (returnStatus <= 200 && returnStatus < 300) { AEZFetchLayoutResponseInterface response = responseEntity.getBody(); List<AEZLayout> receivedLayouts = response.getLayouts(); callback.success(receivedLayouts); } else { callback.failure(returnStatus, null); } } catch (HttpStatusCodeException rsce) { Log.e(LOG_IDENTIFIER, rsce.toString()); callback.failure(rsce.getStatusCode().value(), rsce.toString()); } catch (RestClientException rce) { Log.e(LOG_IDENTIFIER, rce.toString()); callback.failure(-1, rce.toString()); } } }); t.start(); }
From source file:sample.tomcat.X509ApplicationTests.java
@Test public void testAuthenticatedHello() throws Exception { RestTemplate template = new TestRestTemplate(); final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory( httpClient());/* w w w .ja va 2 s . co m*/ template.setRequestFactory(factory); ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello", String.class); assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); assertEquals("hello", httpsEntity.getBody()); }