Example usage for org.springframework.http HttpHeaders add

List of usage examples for org.springframework.http HttpHeaders add

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders add.

Prototype

@Override
public void add(String headerName, @Nullable String headerValue) 

Source Link

Document

Add the given, single header value under the given name.

Usage

From source file:com.iata.ndc.trial.controllers.DefaultController.java

@RequestMapping(value = "/sita", method = RequestMethod.GET)
public String getSita() {

    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.getObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    converters.add(converter);/*www .j  a va  2s  .  c o m*/
    restTemplate.setMessageConverters(converters);

    HttpHeaders headers = new HttpHeaders();
    headers.add("client-key", "zmd9apqgg2jwekf8zgqg5ybf");
    headers.setContentType(MediaType.APPLICATION_JSON);

    ResponseEntity<BALocationsResponseWrapper> baLocationsResponse = restTemplate.exchange(
            "https://api.ba.com/rest-v1/v1/balocations", HttpMethod.GET, new HttpEntity<Object>(headers),
            BALocationsResponseWrapper.class);
    System.out.println(baLocationsResponse.getBody().getGetBALocationsResponse().getCountry().size());
    return "index";
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.http.HttpCommunicationTest.java

private HttpEntity<String> createExpectedBasicAuthRequest(String basicAuthToken) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + basicAuthToken);

    return new HttpEntity<>(headers);
}

From source file:guru.nidi.ramltester.spring.SpringMockRamlMessageTest.java

@RequestMapping(value = "path", produces = "text/dummy")
@ResponseBody//from  w  w w.  j  a  v  a 2s  . c  o  m
public ResponseEntity<String> test() {
    final HttpHeaders headers = new HttpHeaders();
    headers.add("head", "resValue");
    return new ResponseEntity<>("respons", headers, HttpStatus.ACCEPTED);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.http.HttpCommunicationTest.java

private HttpEntity<String> createExpectedSimpleJsonRequest() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "application/json");
    headers.add("Content-type", "application/json");

    return new HttpEntity<>(headers);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.http.HttpCommunicationTest.java

private HttpEntity<String> createExpectedPostRequest(String body) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "application/json");
    headers.add("Content-type", "application/x-www-form-urlencoded");

    return new HttpEntity<>(body, headers);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.http.HttpCommunicationTest.java

private HttpHeaders createExpectedBasicAuthJsonHeaders(String basicAuthToken) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-type", "application/json");
    headers.add("Authorization", "Basic " + basicAuthToken);

    return headers;
}

From source file:com.tce.oauth2.spring.client.services.TodoService.java

public Todo add(String accessToken, Todo todo) {
    // Set the headers
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer " + accessToken);
    headers.add("Content-Type", "application/json");

    // Post request
    HttpEntity<Todo> request = new HttpEntity<Todo>(todo, headers);
    Todo todoAdded = restTemplate.postForObject(OAUTH_RESOURCE_SERVER_URL + "/rest/todos/add", request,
            Todo.class);

    return todoAdded;
}

From source file:com.tce.oauth2.spring.client.services.TodoService.java

public Todo edit(String accessToken, Todo todo) {
    // Set the headers
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer " + accessToken);
    headers.add("Content-Type", "application/json");

    // Post request
    HttpEntity<Todo> request = new HttpEntity<Todo>(todo, headers);
    Todo todoEdited = restTemplate.postForObject(OAUTH_RESOURCE_SERVER_URL + "/rest/todos/edit", request,
            Todo.class);

    return todoEdited;
}

From source file:com.tce.oauth2.spring.client.services.TodoService.java

public TodoResponse delete(String accessToken, Long id) {
    // Set the headers
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer " + accessToken);
    headers.add("Content-Type", "application/json");

    // Post request
    HttpEntity<String> request = new HttpEntity<String>("", headers);
    TodoResponse response = restTemplate.postForObject(
            OAUTH_RESOURCE_SERVER_URL + "/rest/todos/" + id + "/delete", request, TodoResponse.class);

    return response;
}

From source file:org.springsource.sinspctr.rest.SInspctrController.java

@ResponseBody
@RequestMapping(value = "/**/*.xml", method = RequestMethod.GET)
public ResponseEntity<String> findConfig(HttpServletRequest request) {
    ResponseEntity<String> response;
    try {//www.  ja  v  a2 s.  c o  m
        String servletPath = request.getServletPath();
        if (servletPath.startsWith("/sinspctr/configs")) {
            servletPath = servletPath.substring("/sinspctr/configs".length(), servletPath.length());
        }
        File siConfigFile = ResourceLocator.getClasspathRelativeFile(servletPath);
        HttpHeaders headers = new HttpHeaders();
        headers.add("content-type", "application/xml");
        response = new ResponseEntity<String>(FileCopyUtils.copyToString(new FileReader(siConfigFile)), headers,
                HttpStatus.OK);
        return response;
    } catch (Exception e) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }
}