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: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 v  a  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));
}

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

@ResponseBody
@RequestMapping(value = "repreport/{year}/get", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<ReportDataSet> readFTypes(@PathVariable("year") String year, @RequestBody Map data) {
    logger.info(year);/*  w w  w.  j a va2  s  .  c om*/
    logger.info(data);
    Assert.notNull(data, "Data is null.");
    Assert.notNull(year, "Year is null.");
    String reps = data.get("reps").toString();
    String months = data.get("months").toString();
    ReportDataSet reportDataSet = repReportService.getReports(reps, months, year);
    HttpHeaders headers = new HttpHeaders();
    headers.add("success", "Success");
    return new ResponseEntity<ReportDataSet>(reportDataSet, headers, HttpStatus.OK);
}

From source file:io.pivotal.spring.cloud.service.eureka.SurgicalRoutingRequestTransformer.java

@Override
public HttpRequest transformRequest(HttpRequest request, ServiceInstance instance) {
    Map<String, String> metadata = instance.getMetadata();
    if (metadata.containsKey(CF_APP_GUID) && metadata.containsKey(CF_INSTANCE_INDEX)) {
        final String headerValue = String.format("%s:%s", metadata.get(CF_APP_GUID),
                metadata.get(CF_INSTANCE_INDEX));
        // request.getHeaders might be immutable, so return a wrapper
        return new HttpRequestWrapper(request) {
            @Override/*from   www .  ja v a2s.com*/
            public HttpHeaders getHeaders() {
                HttpHeaders headers = new HttpHeaders();
                headers.putAll(super.getHeaders());
                headers.add(SURGICAL_ROUTING_HEADER, headerValue);
                return headers;
            }
        };
    }
    return request;
}

From source file:business.services.PaNumberService.java

public HttpEntity<InputStreamResource> writePaNumbers(List<PathologyItem> items, Integer labNumber,
        String labRequestCode) throws Exception {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(out, PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING);
    CSVWriter csvwriter = new CSVWriter(writer, ';', '"');

    csvwriter.writeNext(FILE_HEADER);/*  w w w.j a  v  a 2 s  .  com*/

    for (PathologyItem item : items) {
        log.info(item.getPaNumber());
        String[] toppings = { labNumber.toString(), item.getPaNumber(), "", "" };
        csvwriter.writeNext(toppings);
    }

    String filename = "panumbers_" + labRequestCode + ".csv";

    try {
        csvwriter.flush();
        writer.flush();
        out.flush();
        InputStream in = new ByteArrayInputStream(out.toByteArray());
        csvwriter.close();
        writer.close();
        out.close();
        InputStreamResource resource = new InputStreamResource(in);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf("text/csv;charset=" + PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING));
        headers.set("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers);
        return response;
    } catch (IOException e) {
        throw new Exception(e);
    }
}

From source file:com.nebhale.gpxconverter.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "", consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.IMAGE_PNG_VALUE)
ResponseEntity<Void> image(@RequestBody DOMSource source,
        @RequestParam(defaultValue = "roadmap") String maptype,
        @RequestParam(defaultValue = "500") Integer width, @RequestParam(defaultValue = "500") Integer height) {
    this.logger.info("Rendering existing GPX file");
    List<Point> points = this.parser.parsePoints((Document) source.getNode());

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(this.mapBuilder.build(points, maptype, width, height));

    return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER);
}

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);// w ww.j  av  a  2  s. c o m
}

From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java

@Test
public void testRoot() throws Exception {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.TEXT_HTML);
    mockMvc.perform(get("/").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print())
            .andExpect(status().isOk()).andExpect(view().name("index"))
            .andExpect(forwardedUrl("/WEB-INF/views/index.jsp"));

}

From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json", value = "driveradd")
@ResponseStatus(HttpStatus.CREATED)//from   w w  w. ja v a 2 s. co m
@ResponseBody
public ResponseEntity<Driver> createDriver(@RequestBody Driver driver, UriComponentsBuilder builder) {

    marketPlaceController.registerDriver(driver);

    HttpHeaders headers = new HttpHeaders();

    URI newDriverLocation = builder.path("/aggregators/dvla/drivers/{license}")
            .buildAndExpand(driver.getDriversLicense()).toUri();

    LOG.info("REST CREATE DRIVER - new driver @ " + newDriverLocation.toString());

    headers.setLocation(newDriverLocation);

    Driver newDriver = marketPlaceController.getDriverDetails(driver.getDriversLicense());

    return new ResponseEntity<Driver>(newDriver, headers, HttpStatus.CREATED);
}

From source file:eu.impress.impressplatform.Application.java

@Override
public void run(String... strings) throws Exception {
    String bedavailability;/*from  w  w  w  . j  a  v a  2 s .co  m*/
    String bedavailabilityDEEnvelope;
    String bedavailabilityDE;
    String bedavailabilityJSON;
    /*RESTManager r = new RESTManager();
     String  s = r.consumePopulation();*/

    //get HAVE String
    bedavailability = b.getBedAvailablityHAVE("");

    //get DE String
    bedavailabilityDEEnvelope = b.createBedAvailabilityDE();

    //encapsulate in DE
    bedavailabilityDE = b.getBedAvailabilityEDXLDE(bedavailabilityDEEnvelope, bedavailability);

    //produce json message
    bedavailabilityJSON = b.forwardBedAvailability(bedavailabilityDE);
    log.info("Json message: " + bedavailabilityJSON);

    //push message to EMCR
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    HttpEntity<String> entity = new HttpEntity<String>(bedavailabilityJSON, headers);
    String answer = restTemplate.postForObject(EMCRUrl, entity, String.class);

    log.info("EMCR response: " + answer);
    //log.info("Current message: " + bedavailabilityJSON);        

}

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

@RequestMapping(value = "/items")
private ResponseEntity<List<String>> selectTag() {
    List<String> list = itemDashBoardService.readItems();

    HttpHeaders headers = new HttpHeaders();
    headers.add("success", "Success");
    return new ResponseEntity<List<String>>(list, headers, HttpStatus.OK);
}