List of usage examples for org.springframework.http HttpHeaders set
@Override public void set(String headerName, @Nullable String headerValue)
From source file:com.allogy.amazonaws.elasticbeanstalk.worker.simulator.application.WorkerApplication.java
private HttpEntity<String> createHttpEntity(MessageWrapper messageWrapper, Message message) { String messageId = message.getMessageId(); HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", "aws-sqsd/1.1 (simulated bridge)"); headers.set("X-Aws-Sqsd-Msgid", messageId); headers.set("X-Aws-Sqsd-Queue", messageWrapper.getQueueName()); headers.set("X-Aws-Sqsd-Receive-Count", Integer.toString(messageWrapper.getMessageCount())); headers.setContentType(MediaType.APPLICATION_JSON); return new HttpEntity<>(message.getBody(), headers); }
From source file:com.tce.oauth2.spring.client.controller.UserInfoController.java
@RequestMapping("/userinfo") public String index(HttpServletRequest request) { if (request.getSession().getAttribute("access_token") == null) { return "redirect:/"; }/*from w w w . ja v a2s . com*/ String accessToken = (String) request.getSession().getAttribute("access_token"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + accessToken); HttpEntity<?> entity = new HttpEntity<>(headers); ResponseEntity<User> response = restTemplate.exchange(OAUTH_URL + "/userinfo", HttpMethod.GET, entity, User.class); if (response.getStatusCode().is4xxClientError()) { return "redirect:/login"; } User user = response.getBody(); request.getSession(false).setAttribute("username", user.getUsername()); return "redirect:/"; }
From source file:io.pivotal.spring.cloud.service.config.VaultTokenRenewalAutoConfiguration.java
private HttpEntity<Map<String, Long>> buildTokenRenewRequest(String vaultToken, long renewTTL) { Map<String, Long> requestBody = new HashMap<>(); requestBody.put("increment", renewTTL); HttpHeaders headers = new HttpHeaders(); headers.set("X-Vault-Token", vaultToken); HttpEntity<Map<String, Long>> request = new HttpEntity<Map<String, Long>>(requestBody, headers); return request; }
From source file:org.openlmis.fulfillment.service.request.RequestHeaders.java
/** * Converts this instance to {@link HttpHeaders}. *///from w w w.j a v a2 s. co m public HttpHeaders toHeaders() { HttpHeaders httpHeaders = new HttpHeaders(); forEach((entry -> httpHeaders.set(entry.getKey(), entry.getValue()))); return httpHeaders; }
From source file:io.github.cdelmas.spike.springboot.car.CarsController.java
@RequestMapping(method = RequestMethod.GET) public ResponseEntity<List<CarRepresentation>> allCars() { List<Car> cars = carRepository.all(); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("total-count", String.valueOf(cars.size())); return new ResponseEntity<>(cars.stream().map(this::toCarRepresentation).collect(toList()), responseHeaders, HttpStatus.OK);/*ww w .j a v a 2 s.c om*/ }
From source file:sample.jetty.SampleJettyApplicationTests.java
@Test public void testCompression() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Accept-Encoding", "gzip"); HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders); ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody())); try {/*from w w w . jav a2 s .co m*/ // assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World"); } finally { inflater.close(); } }
From source file:org.shaigor.rest.retro.service.security.IntegrationTest.java
/** * Logic to test unauthorized access to protected resource * @param uri//from w w w . j a va2 s.c o m */ protected void testInvalidTokenErrorMessge(String uri) { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Bearer FOO"); ResponseEntity<String> response = helper.getForResponse(uri, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String authenticate = response.getHeaders().getFirst("WWW-Authenticate"); assertTrue("Wrong header: " + authenticate, authenticate.contains("error=\"invalid_token\"")); }
From source file:io.syndesis.runtime.APITokenRule.java
@Override protected void after() { MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.set("refresh_token", refreshToken); map.set("client_id", "admin-cli"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + accessToken); ResponseEntity<JsonNode> json = restTemplate.postForEntity("http://localhost:" + keycloakPort + "/auth/realms/" + keycloakRealm + "/protocol/" + keycloakProtocol + "/logout", map, JsonNode.class); assertThat(json.getStatusCode()).as("logout status code").isEqualTo(HttpStatus.NO_CONTENT); }
From source file:org.cloudfoundry.identity.uaa.scim.RemoteScimUserProvisioning.java
@Override public ScimUser removeUser(String id, int version) throws ScimResourceNotFoundException { HttpHeaders headers = new HttpHeaders(); headers.set("If-Match", String.format("%d", version)); return restTemplate.exchange(baseUrl + "/User/{id}", HttpMethod.DELETE, new HttpEntity<Void>(headers), ScimUser.class, id).getBody(); }
From source file:org.cloudfoundry.identity.statsd.integration.UaaMetricsEmitterIT.java
@Test public void testStatsDClientEmitsMetricsCollectedFromUAA() throws InterruptedException, IOException { RestTemplate template = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set(headers.ACCEPT, MediaType.TEXT_HTML_VALUE); ResponseEntity<String> loginResponse = template.exchange(UAA_BASE_URL + "/login", HttpMethod.GET, new HttpEntity<>(null, headers), String.class); if (loginResponse.getHeaders().containsKey("Set-Cookie")) { for (String cookie : loginResponse.getHeaders().get("Set-Cookie")) { headers.add("Cookie", cookie); }/* w w w . j a va 2 s.c o m*/ } String csrf = IntegrationTestUtils.extractCookieCsrf(loginResponse.getBody()); LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>(); body.add("username", TEST_USERNAME); body.add("password", TEST_PASSWORD); body.add(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME, csrf); loginResponse = template.exchange(UAA_BASE_URL + "/login.do", HttpMethod.POST, new HttpEntity<>(body, headers), String.class); assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode()); assertNotNull(getMessage("uaa.audit_service.user_authentication_count:1", 5000)); }