List of usage examples for org.springframework.http HttpHeaders add
@Override public void add(String headerName, @Nullable String headerValue)
From source file:org.trustedanalytics.servicebroker.gearpump.service.CloudFoundryService.java
private String deleteUaaClient(String clientId, String token) { HttpHeaders headers = new HttpHeaders(); headers.add(AUTHORIZATION_HEADER, token); headers.add(CONTENT_TYPE_HEADER, "application/json"); try {/*from w ww. ja v a 2 s . co m*/ LOGGER.debug("Deleting UAA client: {}", clientId); return executeWithHeaders(DELETE_UAA_CLIENT_URL, HttpMethod.DELETE, "", headers, uaaApiEndpoint, clientId).getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { LOGGER.debug("Cannot delete UAA client: {}. It is not exists.", clientId); } else { LOGGER.debug("Cannot delete UAA client: {} Error: {}", clientId, e.getStatusText()); throw e; } } return null; }
From source file:bg.vitkinov.edu.services.JokeService.java
@RequestMapping(value = "/jokeImage/{id}", method = RequestMethod.GET, produces = { MediaType.IMAGE_PNG_VALUE }) public ResponseEntity<byte[]> getJokeImage(@PathVariable Long id, @RequestHeader(value = "Accept") String acceptType, @RequestParam(required = false, defaultValue = "Arial-14") String font, @RequestParam(required = false, defaultValue = "black") String foreColor, @RequestParam(required = false) String backColor) { Joke joke = jokeRepository.findOne(id); ServiceInstance instance = loadBalancerClient.choose("image-service"); if (instance == null) return null; /*/*www . j a v a 2s . co m*/ MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.set("text", Base64.getEncoder().encodeToString(joke.getContent().getBytes())); params.set("Accept", acceptType); params.set("base64", "true"); params.set("font", font); params.set("foreColor", foreColor); params.set("foreColor", foreColor); params.set("backColor", backColor); */ HttpHeaders params = new HttpHeaders(); MediaType requestAcceptType = acceptType == null || "".equals(acceptType) ? MediaType.IMAGE_PNG : MediaType.parseMediaType(acceptType); params.setAccept(Arrays.asList(requestAcceptType)); params.add("text", Base64.getEncoder().encodeToString(joke.getContent().getBytes())); params.add("base64", "true"); params.add("font", font); params.add("foreColor", foreColor); params.add("backColor", backColor); // URI url = URI.create(String.format("%s/img", instance.getUri().toString())) URI url = instance.getUri().resolve("/img"); HttpEntity<byte[]> entity = new HttpEntity<byte[]>(null, params); return restTemplate.exchange(url.toString(), HttpMethod.POST, entity, byte[].class); }
From source file:org.trustedanalytics.servicebroker.gearpump.service.CloudFoundryService.java
private String createUaaToken(String clientId, String clientSecret) throws DashboardServiceException { LOGGER.info("Creating new UAA token"); String autorizationString = clientId + ":" + clientSecret; autorizationString = new String(Base64.getEncoder().encode(autorizationString.getBytes())); HttpHeaders headers = new HttpHeaders(); headers.add(AUTHORIZATION_HEADER, "Basic " + autorizationString); headers.add(CONTENT_TYPE_HEADER, "application/x-www-form-urlencoded"); ResponseEntity<String> response = executeWithHeaders(CREATE_UAA_TOKEN_URL, HttpMethod.POST, CREATE_UAA_TOKEN_BODY_TEMPLATE, headers, uaaTokenApiEndpoint); String uaaToken;/*from w ww.j a v a2s .c o m*/ try { uaaToken = cfCaller.getValueFromJson(response.getBody(), UAA_TOKEN_TYPE) + " " + cfCaller.getValueFromJson(response.getBody(), UAA_ACCESS_TOKEN); } catch (IOException e) { throw new DashboardServiceException("Cannot obtain UAA token.", e); } LOGGER.debug("UAA access token has been obtained."); return uaaToken; }
From source file:com.hpe.elderberry.Taxii11Template.java
private <T> HttpEntity<T> wrapRequest(T body) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(APPLICATION_XML); headers.setAccept(singletonList(APPLICATION_XML)); headers.add("X-TAXII-Services", VID_TAXII_SERVICES_11); headers.add("X-TAXII-Content-Type", VID_TAXII_XML_11); String binding = conn.getDiscoveryUrl().getScheme().endsWith("s") ? VID_TAXII_HTTPS_10 : VID_TAXII_HTTP_10; headers.add("X-TAXII-Protocol", binding); return new HttpEntity<>(body, headers); }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java
@Test public void methodRequiredHeaderWithoutValue() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("header", "headerValue"); ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method15", "1;v;headerValue", 1, "v"); }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java
@Test public void methodOptionalHeaderWithoutValueAndDefault1() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("header", "headerValue"); ControllerUtil.sendAndReceiveWithSession(mockMvc, headers, "remoteProviderSimple", "method18", "headerValue"); }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java
@Test public void methodRequiredHeaderWithValueAndDefault1() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("header", "headerValue"); headers.add("anotherName", "headerValue1"); ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method17", "headerValue1"); }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java
@Test public void methodMultipleHeaders1() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("last", "lastHeader"); ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method19", "100;default1;default2;lastHeader", 100); }
From source file:org.cloudfoundry.identity.uaa.api.common.impl.UaaConnectionHelper.java
/** * Add the Authorization, Content-Type, and Accept headers to the request * //from w ww . j a v a2 s . co m * @param headers */ private void getHeaders(HttpHeaders headers) { OAuth2AccessToken token = getAccessToken(); headers.add("Authorization", token.getTokenType() + " " + token.getValue()); if (headers.getContentType() == null) { headers.setContentType(MediaType.APPLICATION_JSON); } if (headers.getAccept() == null || headers.getAccept().size() == 0) { headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); } }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java
@Test public void methodRequiredHeaderWithValue() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("header", "headerValue"); headers.add("anotherName", "headerValue1"); headers.add("anotherName", "headerValue2"); ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method16", "11;headerValue1", 11); }