List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(MultiValueMap<String, String> headers)
From source file:com.google.cloud.servicebroker.awwvision.RedditScraper.java
@RequestMapping("/reddit") String getRedditUrls(Model model, RestTemplate restTemplate) throws GeneralSecurityException { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.USER_AGENT, redditUserAgent); RedditResponse response = restTemplate .exchange(REDDIT_URL, HttpMethod.GET, new HttpEntity<String>(headers), RedditResponse.class) .getBody();/*from w w w . j av a 2s . c om*/ storeAndLabel(response); return "reddit"; }
From source file:sample.undertow.SampleUndertowApplicationTests.java
@Test public void testCompression() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Accept-Encoding", "gzip"); HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders); RestTemplate restTemplate = new TestRestTemplate(); ResponseEntity<byte[]> entity = restTemplate.exchange("http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody())); try {/*from w ww .j a v a2 s . co m*/ assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World"); } finally { inflater.close(); } }
From source file:com.interop.webapp.WebAppTests.java
@Test public void testHome() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertTrue("Wrong location:\n" + entity.getHeaders(), entity.getHeaders().getLocation().toString().endsWith(port + "/login")); }
From source file:com.github.ffremont.microservices.springboot.node.services.MsService.java
public List<MicroServiceRest> getMicroServices() { MasterUrlBuilder builder = new MasterUrlBuilder(cluster, node, masterhost, masterPort, masterCR); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.parseMediaType(MS_JSON_TYPE_MIME))); HttpEntity<MicroServiceRest> entity = new HttpEntity<>(headers); ResponseEntity<MicroServiceRest[]> response = restTempate.exchange(builder.build(), HttpMethod.GET, entity, MicroServiceRest[].class); return HttpStatus.OK.equals(response.getStatusCode()) ? new ArrayList<>(Arrays.asList(response.getBody())) : null;/*from ww w. ja v a2s . co m*/ }
From source file:com.create.controller.ValidationResultRestTestExecutor.java
private <R, T> void executeTestRestRequest(String urlTemplate, String testName, Class<R> requestObjectType, Class<T> validatedObjectType) throws Exception { final R requestObject = getRequestObject(urlTemplate, testName, requestObjectType); final HttpEntity<R> entity = new HttpEntity<>(requestObject); final ParameterizedTypeReference<ValidationResult<T>> genericResponseType = getGenericResponseType( validatedObjectType);/*from w ww . jav a2 s . c om*/ final ResponseEntity<ValidationResult<T>> responseEntity = restTemplate.exchange(urlTemplate, HttpMethod.POST, entity, genericResponseType); final ValidationResult<T> responseObject = getResponseObject(urlTemplate, testName, validatedObjectType); assertThat(responseEntity.getBody(), is(responseObject)); final HttpStatus statusCode = getExpectedStatusCode(responseObject); assertThat(responseEntity.getStatusCode(), is(statusCode)); }
From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java
public Host getHost() { String url = configuration.getBaseUrl() + "/hosts"; HttpHeaders headers = new HttpHeaders(); HttpEntity<String> getEntity = new HttpEntity<>(headers); logger.debug("REQUESTING HOSTS to " + url); ResponseEntity<String> hosts = template.exchange(url, HttpMethod.GET, getEntity, String.class); logger.debug("hosts " + hosts.getBody()); if (!hosts.getStatusCode().is2xxSuccessful()) { return null; } else {/*from w ww .j av a 2 s.c o m*/ return mapper.fromJson(hosts.getBody(), Host.class); } }
From source file:org.cloudbyexample.dc.web.client.docker.ProvisionClient.java
@Override public ProvisionResponse provision(String uuid) { ProvisionResponse response = null;//from ww w. j a v a 2 s.c om String url = client.createUrl(PROVISION_REQUEST); logger.debug("REST client provision. uuid={} url='{}'", uuid, url); // response = client.getRestTemplate().postForObject(url, responseClazz, createUuidVar(uuid)); Map<String, String> vars = createUuidVar(uuid); response = client.getRestTemplate() .exchange(url, HttpMethod.POST, new HttpEntity(null), responseClazz, vars).getBody(); return response; }
From source file:comsat.sample.mustache.SampleWebMustacheApplicationTests.java
@Test public void testMustacheErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:comsat.sample.velocity.SampleWebVelocityApplicationTests.java
@Test public void testVelocityErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:com.example.SampleWebFreeMarkerApplicationTests.java
@Test public void testFreeMarkerErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/" + contextPath + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); }