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.cloudfoundry.identity.api.web.ServerRunning.java
@Override public Statement apply(Statement base, FrameworkMethod method, Object target) { // Check at the beginning, so this can be used as a static field if (assumeOnline) { Assume.assumeTrue(serverOnline.get(port)); } else {/*w w w .j a v a2 s .c o m*/ Assume.assumeTrue(serverOffline.get(port)); } RestTemplate client = new RestTemplate(); boolean online = false; try { client.getForEntity(new UriTemplate(getUrl("/uaa/login", uaaPort)).toString(), String.class); client.getForEntity(new UriTemplate(getUrl("/api/index.html")).toString(), String.class); online = true; logger.debug("Basic connectivity test passed"); } catch (RestClientException e) { logger.warn(String.format( "Not executing tests because basic connectivity test failed for hostName=%s, port=%d", hostName, port), e); if (assumeOnline) { Assume.assumeNoException(e); } } finally { if (online) { serverOffline.put(port, false); if (!assumeOnline) { Assume.assumeTrue(serverOffline.get(port)); } } else { serverOnline.put(port, false); } } return super.apply(base, method, target); }
From source file:org.cloudfoundry.identity.app.integration.ServerRunning.java
@Override public Statement apply(Statement base, FrameworkMethod method, Object target) { // Check at the beginning, so this can be used as a static field if (!integrationTest) { Assume.assumeTrue(serverOnline.get(rootPath)); }//from w ww . j av a 2s. c o m RestTemplate client = new RestTemplate(); boolean online = false; try { client.getForEntity(new UriTemplate(getAuthServerUrl("/login")).toString(), String.class); client.getForEntity(new UriTemplate(getUrl("/login_error.jsp")).toString(), String.class); online = true; logger.debug("Basic connectivity test passed"); } catch (RestClientException e) { logger.warn(String .format("Not executing tests because basic connectivity test failed for root=" + rootPath), e); if (!integrationTest) { Assume.assumeNoException(e); } } finally { if (!online) { serverOnline.put(rootPath, false); } } return super.apply(base, method, target); }
From source file:org.kurento.repository.test.OneRecordingServerTest.java
protected void downloadFromURL(String urlToDownload, File downloadedFile) throws Exception { if (!downloadedFile.exists()) { downloadedFile.createNewFile();//from w w w .ja v a2 s . c o m } log.debug(urlToDownload); RestTemplate client = new RestTemplate(); ResponseEntity<byte[]> response = client.getForEntity(urlToDownload, byte[].class); assertEquals(HttpStatus.OK, response.getStatusCode()); FileOutputStream os = new FileOutputStream(downloadedFile); os.write(response.getBody()); os.close(); }
From source file:org.springframework.data.document.couchdb.core.AbstractCouchTemplateIntegrationTests.java
@Before public void setUpTestDatabase() throws Exception { RestTemplate template = new RestTemplate(); template.setErrorHandler(new DefaultResponseErrorHandler() { @Override// www. j a v a2 s. c om public void handleError(ClientHttpResponse response) throws IOException { // do nothing, error status will be handled in the switch statement } }); ResponseEntity<String> response = template.getForEntity(CouchConstants.TEST_DATABASE_URL, String.class); HttpStatus statusCode = response.getStatusCode(); switch (statusCode) { case NOT_FOUND: createNewTestDatabase(); break; case OK: deleteExisitingTestDatabase(); createNewTestDatabase(); break; default: throw new IllegalStateException("Unsupported http status [" + statusCode + "]"); } }