List of usage examples for org.springframework.http HttpHeaders set
@Override public void set(String headerName, @Nullable String headerValue)
From source file:org.obiba.mica.user.UserProfileService.java
private <T> T executeQuery(String serviceUrl, Class<T> returnType) { RestTemplate template = newRestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set(APPLICATION_AUTH_HEADER, getApplicationAuth()); HttpEntity<String> entity = new HttpEntity<>(null, headers); ResponseEntity<T> response = template.exchange(serviceUrl, HttpMethod.GET, entity, returnType); return response.getBody(); }
From source file:com.cisco.cta.taxii.adapter.httpclient.HttpHeadersAppender.java
public void appendTo(HttpHeaders headers) { headers.setContentType(MediaType.APPLICATION_XML); headers.setAccept(ImmutableList.of(MediaType.APPLICATION_XML)); headers.set("X-Taxii-Accept", "urn:taxii.mitre.org:message:xml:1.1"); headers.set("X-TAXII-Content-Type", "urn:taxii.mitre.org:message:xml:1.1"); headers.set("X-Taxii-Protocol", "urn:taxii.mitre.org:protocol:https:1.0"); headers.set("X-TAXII-Services", "urn:taxii.mitre.org:services:1.1"); headers.set("User-Agent", "taxii-log-adapter-" + Version.getImplVersion()); }
From source file:com.ge.predix.acceptance.test.zone.admin.DefaultZoneAuthorizationIT.java
/** * 1. Create a token from zone issuer with scopes for accessing: a. zone specific resources, AND b. * acs.zones.admin//w ww. ja va 2 s . co m * * 2. Try to access a zone specific resource . This should work 3. Try to access /v1/zone - THIS SHOULD FAIL * * @throws Exception */ public void testAccessGlobalResourceWithZoneIssuer() throws Exception { OAuth2RestTemplate zone2AcsTemplate = this.acsRestTemplateFactory.getACSZone2RogueTemplate(); HttpHeaders zoneTwoHeaders = new HttpHeaders(); zoneTwoHeaders.set(PolicyHelper.PREDIX_ZONE_ID, this.zoneHelper.getZone2Name()); // Write a resource to zone2. This should work ResponseEntity<Object> responseEntity = this.privilegeHelper.postResources(zone2AcsTemplate, zoneHelper.getAcsBaseURL(), zoneTwoHeaders, new BaseResource("/sites/sanramon")); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.NO_CONTENT); // Try to get global resource from global/baseUrl. This should FAIL try { zone2AcsTemplate.exchange(this.zoneHelper.getAcsBaseURL() + "/v1/zone/" + this.zone2Name, HttpMethod.GET, null, Zone.class); Assert.fail("Able to access non-zone specific resource with a zone specific issuer token!"); } catch (OAuth2AccessDeniedException e) { // expected } // Try to get global resource from zone2Url. This should FAIL try { zone2AcsTemplate.exchange(this.zoneHelper.getAcsBaseURL() + "/v1/zone/" + this.zone2Name, HttpMethod.GET, new HttpEntity<>(zoneTwoHeaders), Zone.class); Assert.fail("Able to access non-zone specific resource from a zone specific URL, " + "with a zone specific issuer token!"); } catch (InvalidRequestException e) { // expected } }
From source file:org.appverse.web.framework.backend.test.util.frontfacade.BaseAbstractAuthenticationRequiredTest.java
protected TestLoginInfo login() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode((getUsername() + ":" + getPassword()).getBytes("UTF-8")))); HttpEntity<String> entity = new HttpEntity<String>("headers", headers); ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange( "http://localhost:" + port + baseApiPath + basicAuthenticationEndpointPath, HttpMethod.POST, entity, AuthorizationData.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); List<String> xsrfTokenHeaders = responseEntity.getHeaders().get(DEFAULT_CSRF_HEADER_NAME); assertNotNull(xsrfTokenHeaders);/*from w ww. j a va 2 s.co m*/ assertEquals(xsrfTokenHeaders.size(), 1); assertNotNull(xsrfTokenHeaders.get(0)); AuthorizationData authorizationData = responseEntity.getBody(); assertNotNull(authorizationData); List<String> roles = authorizationData.getRoles(); assertNotNull(roles); assertEquals(roles.size() > 0, true); assertEquals(roles.contains(getAnUserRole()), true); TestLoginInfo loginInfo = new TestLoginInfo(); loginInfo.setXsrfToken(xsrfTokenHeaders.get(0)); loginInfo.setAuthorizationData(authorizationData); loginInfo.setJsessionid(responseEntity.getHeaders().getFirst("Set-Cookie")); return loginInfo; }
From source file:example.company.UrlLevelSecurityTests.java
@Test public void allowsPostRequestForAdmin() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.ACCEPT, "application/hal+json"); headers.set(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(("ollie:gierke").getBytes()))); mvc.perform(get("/employees").// headers(headers)).// andExpect(content().contentType(MediaTypes.HAL_JSON)).// andExpect(status().isOk()).// andDo(print());/*from w ww.j ava 2 s .co m*/ headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); String location = mvc.perform(post("/employees").// content(PAYLOAD).// headers(headers)).// andExpect(status().isCreated()).// andDo(print()).// andReturn().getResponse().getHeader(HttpHeaders.LOCATION); ObjectMapper mapper = new ObjectMapper(); String content = mvc.perform(get(location)).// andReturn().getResponse().getContentAsString(); Employee employee = mapper.readValue(content, Employee.class); assertThat(employee.getFirstName(), is("Saruman")); assertThat(employee.getLastName(), is("the White")); assertThat(employee.getTitle(), is("Wizard")); }
From source file:com.orange.cepheus.broker.Configuration.java
public void addRemoteHeaders(HttpHeaders httpHeaders) { if (remoteServiceName != null) { httpHeaders.set("Fiware-Service", remoteServiceName); }//from w ww. j a va 2 s . com if (remoteServicePath != null) { httpHeaders.set("Fiware-ServicePath", remoteServicePath); } if (remoteAuthToken != null) { httpHeaders.set("X-Auth-Token", remoteAuthToken); } }
From source file:miage.ecom.web.admin.controller.ProductImage.java
@RequestMapping(value = "/product/{id}/image", method = RequestMethod.POST) public ResponseEntity<String> create(@PathVariable("id") int productId, @RequestParam("image") MultipartFile image) { HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("Content-type", "text/html"); String success = null;//from w ww . ja v a 2 s .c o m String msg = null; String imageUrl = ""; Product product = productFacade.find(productId); if (product == null) { success = "false"; msg = "Ce produit n'existe pas / plus"; } if (image.isEmpty()) { success = "false"; msg = "Impossible de sauvegarder l'image"; } if (!image.getContentType().contains("image")) { success = "false"; msg = "Format de fichier non valide"; } if (success == null) { try { URL thumbUrl = imageManager.uploadThumb(image.getInputStream(), 200); if (thumbUrl != null) { imageUrl = thumbUrl.toString(); product.setImage(imageUrl); productFacade.edit(product); success = "true"; } else { success = "false"; msg = "Impossible de gnrer l'image"; } } catch (Exception ex) { success = "false"; msg = "Impossible de gnrer l'image : " + ex.getMessage(); } } return new ResponseEntity<String>( "{success:" + success + ",msg:\"" + msg + "\",image:\"" + imageUrl + "\"}", responseHeaders, HttpStatus.OK); }
From source file:bibibi.controllers.CitationsController.java
@RequestMapping(value = "/export", method = RequestMethod.GET) public HttpEntity<FileSystemResource> getFile() throws IOException { BibWriter bw = new BibWriter("export", this.citationRepository.findAll()); bw.writeFile();/*from w w w .ja v a2 s. co m*/ HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.APPLICATION_OCTET_STREAM); header.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + bw.getFile().getName()); header.setContentLength(bw.getFile().length()); return new HttpEntity<>(new FileSystemResource(bw.getFile()), header); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java
@Test public void testImplicitClientInfo() throws Exception { HttpHeaders headers = new HttpHeaders(); ImplicitResourceDetails app = testAccounts.getDefaultImplicitResource(); headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), "")); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(app.getClientId(), response.getBody().get("client_id")); }
From source file:com.ecsteam.cloudlaunch.services.jenkins.JenkinsService.java
private HttpEntity<String> getAuthorizationEntity() { if (authEntity == null) { String unencoded = user + ":" + password; String encoded = Base64.getEncoder().encodeToString(unencoded.getBytes()); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + encoded); authEntity = new HttpEntity<String>(headers); }/* w w w.j av a2s. c om*/ return authEntity; }