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:cn.org.once.cstack.utils.RestUtils.java
public static String sendGetCommand(String url) { RestTemplate restTemplate = new RestTemplate(); ResponseEntity<?> result = restTemplate.getForEntity(url, String.class); String body = result.getBody().toString(); MediaType contentType = result.getHeaders().getContentType(); HttpStatus statusCode = result.getStatusCode(); logger.info("REST PUT COMMAND " + contentType + " " + statusCode); return body;// ww w. ja v a 2s. c o m }
From source file:org.spring.springxdcloudInstaller.MainApp.java
private static String getLatestBuild() { RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> s = restTemplate.getForEntity( "http://repo.springsource.org/libs-snapshot-local/org/springframework/xd/spring-xd/1.0.0.BUILD-SNAPSHOT/", String.class); return s.getBody(); }
From source file:com.unknown.pkg.InfoEndpointApplicationIT.java
@Test public void fetchInfo() { RestTemplate rest = new RestTemplate(); ResponseEntity<String> response = rest.getForEntity("http://localhost:" + port + "/info", String.class); Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); Assertions.assertThat(response.getBody()).contains("\"version\":\"0.9.0-SNAPSHOT\""); }
From source file:org.kurento.repository.test.TimeoutTests.java
@Test public void playerAutoTerminationTest() throws Exception { String id = uploadFile(new File("test-files/sample.txt")); log.info("File uploaded"); RepositoryHttpPlayer player = getRepository().findRepositoryItemById(id).createRepositoryHttpPlayer(); player.setAutoTerminationTimeout(1000); RestTemplate template = getRestTemplate(); assertEquals(HttpStatus.OK, template.getForEntity(player.getURL(), byte[].class).getStatusCode()); log.info("Request 1 Passed"); Thread.sleep(300);// w w w. j a va 2s . c o m assertEquals(HttpStatus.OK, template.getForEntity(player.getURL(), byte[].class).getStatusCode()); log.info("Request 2 Passed"); Thread.sleep(1500); assertEquals(HttpStatus.NOT_FOUND, template.getForEntity(player.getURL(), byte[].class).getStatusCode()); log.info("Request 3 Passed"); }
From source file:org.zalando.stups.twintip.TwintipApplicationIT.java
@Test public void isConfigured() { String endpointUrl = "http://localhost:" + port + "/.well-known/schema-discovery"; LOG.info("ENDPOINT_URL : {}", endpointUrl); RestTemplate template = new RestTemplate(); ResponseEntity<String> entity = template.getForEntity(endpointUrl, String.class); HttpStatus statusCode = entity.getStatusCode(); String body = entity.getBody(); Assertions.assertThat(statusCode).isEqualTo(HttpStatus.OK); Assertions.assertThat(body).contains("swagger-2.0"); LOG.info("BODY : {}", body); }
From source file:com.unknown.pkg.TwintipCustomProfileApplicationIT.java
@Test public void isConfigured() { String endpointUrl = "http://localhost:" + port + "/.well-known/schema-discovery"; LOG.info("ENDPOINT_URL : {}", endpointUrl); RestTemplate template = new RestTemplate(); ResponseEntity<String> entity = template.getForEntity(endpointUrl, String.class); HttpStatus statusCode = entity.getStatusCode(); String body = entity.getBody(); Assertions.assertThat(statusCode).isEqualTo(HttpStatus.OK); Assertions.assertThat(body).contains("swagger-unreleased"); LOG.info("BODY : {}", body); }
From source file:example.pki.SslPkiTests.java
/** * Plain {@link RestTemplate} without the Root CA configured. Assuming the Root CA * certificate is unknown to the default truststore, the request should fail. *//*from w w w.j a va2 s. c o m*/ @Test public void clientShouldRejectUnknownRootCertificate() { RestTemplate restTemplate = new RestTemplate(); try { restTemplate.getForEntity("https://localhost:" + port, String.class); fail("Missing ResourceAccessException that wraps SSLHandshakeException"); } catch (ResourceAccessException e) { assertThat(e).hasCauseInstanceOf(SSLHandshakeException.class); } }
From source file:com.appranix.adapter.service.AdapterServiceImpl.java
@Override public void adapterRead(int id) throws Exception { try {//from w ww . ja v a 2s . c o m final String uri = "http://localhost:9090/adapter/rest/cm/simple/cis/" + id; RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> result = restTemplate.getForEntity(uri, String.class); System.out.println(result); } catch (Exception e) { throw new Exception("Error in Read Operation"); } }
From source file:com.zalando.zmon.boot.jetty.AbstractRunner.java
@Test public void run() throws InterruptedException { RestTemplate rest = new RestTemplate(); for (int i = 0; i < 100; i++) { ResponseEntity<String> response = rest .getForEntity("http://localhost:" + port + "/api/simple/" + i + "/complex", String.class); Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); }/*from w w w. ja va 2s . c o m*/ ResponseEntity<String> metrics = rest.getForEntity("http://localhost:" + port + "/metrics", String.class); Assertions.assertThat(metrics.getBody()).contains(LINE); // to use browser /metrics // TimeUnit.MINUTES.sleep(2); }
From source file:com.recursivechaos.stoopbot.service.RoomRequestService.java
public List<Items> pollHistory() { RestTemplate restTemplate = new RestTemplate(); log.info("Polling room: " + room); ResponseEntity<History> responseEntity = restTemplate.getForEntity( "http://" + url + ".hipchat.com/v2/room/" + room + "/history?auth_token=" + key, History.class); log.debug("Response received: {}", responseEntity); return responseEntity.getBody().getItems(); }