Example usage for org.springframework.http HttpHeaders HttpHeaders

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

Introduction

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

Prototype

public HttpHeaders() 

Source Link

Document

Construct a new, empty instance of the HttpHeaders object.

Usage

From source file:com.vinidsl.googleioextended.rest.BaseRequest.java

/**
 * Returns the HttpHeaders to be used in the request.
 * @return/*  ww  w  .j  a  v a 2 s.c  om*/
 */
public HttpHeaders getHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "application/json");
    headers.add("X-Parse-Application-Id", "eOZ0eFf8g2uJuX2xom30uzsTPXjdGc4kvBUXsG7K");
    headers.add("X-Parse-REST-API-Key", "Qi8G0MAn090msWUuEchhKtIPzh0tPF8FlxKDRWXJ");
    return headers;
}

From source file:com.codekul.simpleboot.controller.ControllerRestServices.java

@RequestMapping(value = "/user", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public /*@ResponseBody*/ ResponseEntity<User> userInfo() {

    User userBody = new User();
    userBody.setUserName("Android");
    userBody.setPassword("android");

    HttpHeaders headers = new HttpHeaders();

    ResponseEntity<User> entity = new ResponseEntity<>(userBody, headers, HttpStatus.OK);
    return entity;
}

From source file:net.eusashead.hateoas.conditional.interceptor.AsyncTestController.java

@RequestMapping(method = RequestMethod.GET)
public Callable<ResponseEntity<String>> get() {
    return new Callable<ResponseEntity<String>>() {

        @Override/*from   w  w w  .  j av  a2  s. c o m*/
        public ResponseEntity<String> call() throws Exception {
            HttpHeaders headers = new HttpHeaders();
            headers.setETag("\"123456\"");
            return new ResponseEntity<String>("hello", headers, HttpStatus.OK);
        }
    };

}

From source file:com.greglturnquist.spring.social.ecobee.api.impl.AbstractEcobeeApiTest.java

@Before
public void setUp() {

    this.ecobee = new EcobeeTemplate("ACCESS_TOKEN");
    this.mockServer = MockRestServiceServer.createServer(ecobee.getRestTemplate());

    this.responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_JSON);

    this.unauthorizedEcobee = new EcobeeTemplate();

    // Create a mock server just to avoid hitting real Ecobee if something gets past the authorization check.
    MockRestServiceServer.createServer(unauthorizedEcobee.getRestTemplate());
}

From source file:net.eusashead.hateoas.conditional.interceptor.SyncTestController.java

@RequestMapping(method = RequestMethod.HEAD)
public ResponseEntity<String> head() {
    HttpHeaders headers = new HttpHeaders();
    headers.setETag("\"123456\"");
    return new ResponseEntity<String>(headers, HttpStatus.OK);
}

From source file:com.isalnikov.controller.MessageController.java

@RequestMapping(value = { "/message/{code}" }, method = RequestMethod.GET)
@ResponseBody/*from  www .j  ava 2s.com*/
public ResponseEntity index(@PathVariable("code") String code, Locale locale) {

    String result = messageSource.getMessage(code, new Object[] {}, locale);
    System.out.println(String.format("%s  :  %s", locale.getLanguage(), result));

    String res = String.format("%s  :  %s", locale.getLanguage(), messageHelper.getMessage(code));

    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-type", "application/json;charset=UTF-8");
    ResponseEntity responseEntity = new ResponseEntity<>(res, headers, HttpStatus.OK);
    return responseEntity;
}

From source file:cz.muni.fi.mushroomhunter.restclient.AllMushroomsSwingWorker.java

@Override
protected List<MushroomDto> doInBackground() throws Exception {
    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity<String> request = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<MushroomDto[]> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/mushroom/", HttpMethod.GET, request, MushroomDto[].class);
    MushroomDto[] mushroomDtoArray = responseEntity.getBody();
    List<MushroomDto> mushroomDtoList = new ArrayList<>();
    mushroomDtoList.addAll(Arrays.asList(mushroomDtoArray));
    return mushroomDtoList;
}

From source file:org.zalando.riptide.Actions.java

/**
 * Normalizes the {@code Location} and {@code Content-Location} headers of any given response by resolving them
 * against the given {@code uri}./*from   w  w  w .j av a  2 s.  c  o  m*/
 *
 * @param uri the base uri to resolve against
 * @return a function that normalizes responses
 */
public static ThrowingFunction<ClientHttpResponse, ClientHttpResponse, IOException> normalize(final URI uri) {
    return response -> {
        final HttpHeaders headers = new HttpHeaders();
        headers.putAll(response.getHeaders());

        Optional.ofNullable(headers.getLocation()).map(uri::resolve).ifPresent(headers::setLocation);

        Optional.ofNullable(headers.getFirst(CONTENT_LOCATION)).map(uri::resolve)
                .ifPresent(location -> headers.set(CONTENT_LOCATION, location.toASCIIString()));

        return new ForwardingClientHttpResponse() {

            @Override
            protected ClientHttpResponse delegate() {
                return response;
            }

            @Override
            public HttpHeaders getHeaders() {
                return headers;
            }

        };
    };
}

From source file:com.biz.report.controller.RepReportController.java

@RequestMapping(value = "/reps")
private ResponseEntity<List<String>> readReps() {
    List<String> list = repReportService.readReps();
    HttpHeaders headers = new HttpHeaders();
    headers.add("success", "Success");
    return new ResponseEntity<List<String>>(list, headers, HttpStatus.OK);
}

From source file:github.priyatam.springrest.resource.DriverResource.java

@RequestMapping(method = RequestMethod.GET, value = "/driver/{licenseNo}")
@ResponseBody/*from  ww  w  . j  ava 2  s .c  o m*/
public ResponseEntity<Driver> getDriver(@PathVariable String licenseNo) {
    logger.debug(String.format("Retrieving Driver %s :", licenseNo));

    Driver driver = persistenceHelper.loadDriverByLicenseNum(licenseNo);
    if (driver == null) {
        logger.warn("No Driver found");
        return new ResponseEntity<Driver>(null, new HttpHeaders(), HttpStatus.NOT_FOUND);
    }

    // Convert to Restful Resource, update ETag and HATEOAS references
    responseBuilder.toDriver(Lists.newArrayList(driver));

    return new ResponseEntity<Driver>(driver, HttpStatus.OK);
}