List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:com.biz.report.controller.CustomerReportControler.java
@RequestMapping(value = "/customers") private ResponseEntity<List<String>> readCustomers() { HttpHeaders headers = new HttpHeaders(); headers.add("success", "Success"); return new ResponseEntity<List<String>>(customerService.readCustomers(), headers, HttpStatus.OK); }
From source file:com.tce.oauth2.spring.client.services.TodoService.java
public List<Todo> findAll(String accessToken) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + accessToken); HttpEntity<String> entity = new HttpEntity<String>(headers); ResponseEntity<Todo[]> response = restTemplate.exchange(OAUTH_RESOURCE_SERVER_URL + "/rest/todos", HttpMethod.GET, entity, Todo[].class); Todo[] todos = response.getBody();//from w w w. j a v a 2 s . c o m return Arrays.asList(todos); }
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 w w w.j ava 2s . com }
From source file:cz.jirutka.spring.http.client.cache.internal.InMemoryClientHttpResponse.java
public InMemoryClientHttpResponse deepCopy() { HttpHeaders headersCopy = new HttpHeaders(); for (Entry<String, List<String>> entry : headers.entrySet()) { headersCopy.put(entry.getKey(), new LinkedList<>(entry.getValue())); }/*ww w . j a v a2 s . c o m*/ return new InMemoryClientHttpResponse(body.clone(), statusCode, headersCopy); }
From source file:org.trustedanalytics.servicebroker.hdfs.users.UaaClientTokenRetriver.java
public String getToken() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); URI uaaUri = UriComponentsBuilder.fromHttpUrl(uaaConfiguration.getTokenUri()) .queryParam(GRANT_TYPE, GRANT_TYPE_CREDENTIALS).queryParam(RESPONSE_TYPE, RESPONSE_TYPE_TOKEN) .build().encode().toUri();//from ww w. j ava 2 s . co m HttpEntity<String> entity = new HttpEntity<>(PARAMETERS, headers); return uaaRestTemplate.postForObject(uaaUri, entity, UaaTokenResponse.class).getAccessToken(); }
From source file:com.stampit.controller.LoginController.java
@RequestMapping(value = "/authenticateCustomer", method = RequestMethod.POST, consumes = "application/json") public ResponseEntity<String> authenticateUser(@RequestBody String authInfo, HttpServletRequest request) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); AuthInfo authInfoObject = null;//from w w w. j a v a2 s . co m authInfoObject = objectMapper.readValue(authInfo, AuthInfo.class); Customer customer = customerRepository.findByUsernameAndPassword(authInfoObject.getUsername(), authInfoObject.getPassword()); ResponseEntity<String> response = null; if (customer == null) { response = new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.UNAUTHORIZED); } else { CustomerConfirmation confirmation = customerConfirmationRepository.findOne(customer.getIdCustomer()); if (confirmation.getConfirmed()) { response = new ResponseEntity<String>("{\"id\":\"" + customer.getIdCustomer() + "\"}", new HttpHeaders(), HttpStatus.OK); } else { response = new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.UNAUTHORIZED); } } return response; }
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 {//ww w .j a v a 2 s . com assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World"); } finally { inflater.close(); } }
From source file:org.openbaton.nfvo.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ NotFoundException.class, NoResultException.class }) @ResponseStatus(value = HttpStatus.NOT_FOUND) protected ResponseEntity<Object> handleNotFoundException(Exception e, WebRequest request) { if (log.isDebugEnabled()) { log.error("Exception was thrown -> Return message: " + e.getMessage(), e); } else {/* w w w .jav a 2s .c o m*/ log.error("Exception was thrown -> Return message: " + e.getMessage()); } ExceptionResource exc = new ExceptionResource("Not Found", e.getMessage()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }
From source file:org.cloudfoundry.identity.uaa.integration.ImplicitTokenGrantIntegrationTests.java
@Test public void authzViaJsonEndpointFailsWithHttpGet() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); String credentials = String.format("{\"username\":\"%s\",\"password\":\"%s\"}", testAccounts.getUserName(), testAccounts.getPassword()); ResponseEntity<Void> result = serverRunning.getForResponse(implicitUrl() + "&credentials={credentials}", headers, credentials);/*from w w w . j av a 2 s.co m*/ assertEquals(HttpStatus.UNAUTHORIZED, result.getStatusCode()); }
From source file:org.kurento.repository.test.RangeGetTests.java
@Test public void test() throws Exception { String id = "logo.png"; RepositoryItem item;/* ww w . ja va 2s. c o m*/ try { item = getRepository().findRepositoryItemById(id); } catch (NoSuchElementException e) { item = getRepository().createRepositoryItem(id); uploadFile(new File("test-files/" + id), item); } RepositoryHttpPlayer player = item.createRepositoryHttpPlayer(); String url = player.getURL(); player.setAutoTerminationTimeout(100000); // Following sample // http://stackoverflow.com/questions/8293687/sample-http-range-request-session RestTemplate httpClient = getRestTemplate(); { HttpHeaders requestHeaders = new HttpHeaders(); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertTrue("The server doesn't accept ranges", response.getHeaders().containsKey("Accept-ranges")); assertTrue("The server doesn't accept ranges with bytes", response.getHeaders().get("Accept-ranges").contains("bytes")); } long fileLength = 0; { // Range: bytes=0- HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Range", "bytes=0-"); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertEquals("The server doesn't respond with http status code 206 to a request with ranges", HttpStatus.PARTIAL_CONTENT, response.getStatusCode()); fileLength = Long.parseLong(response.getHeaders().get("Content-Length").get(0)); } { HttpHeaders requestHeaders = new HttpHeaders(); long firstByte = fileLength - 3000; long lastByte = fileLength - 1; long numBytes = lastByte - firstByte + 1; requestHeaders.set("Range", "bytes=" + firstByte + "-" + lastByte); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertEquals("The server doesn't respond with http status code 206 to a request with ranges", response.getStatusCode(), HttpStatus.PARTIAL_CONTENT); long responseContentLength = Long.parseLong(response.getHeaders().get("Content-Length").get(0)); assertEquals("The server doesn't send the requested bytes", numBytes, responseContentLength); assertEquals("The server doesn't send the requested bytes", responseContentLength, response.getBody().length); } }