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:hello.TodoController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<Iterable<Todo>> list() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept-Patch", "application/json-patch+json");
    return new ResponseEntity<Iterable<Todo>>(repository.findAll(), headers, HttpStatus.OK);
}

From source file:tools.RequestSendingRunnable.java

private RequestEntity<Void> requestWithTraceId() {
    HttpHeaders headers = new HttpHeaders();
    headers.add(Span.TRACE_ID_NAME, Span.idToHex(this.traceId));
    headers.add(Span.SPAN_ID_NAME, Span.idToHex(this.spanId));
    URI uri = URI.create(this.url);
    RequestEntity<Void> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, uri);
    log.info("Request [" + requestEntity + "] is ready");
    return requestEntity;
}

From source file:com.healthcit.cacure.web.controller.FormElementBatchDeleteController.java

@RequestMapping(value = "/questionList.delete", method = RequestMethod.POST)
public ResponseEntity<String> batchDelete(@RequestParam(value = "feIds[]", required = false) Long[] feIds) {
    HashSet<Long> uniqueIds = new HashSet<Long>(Arrays.asList(feIds));
    Set<Long> deleted = new HashSet<Long>();
    for (Long id : uniqueIds) {
        try {/*from   www .ja va2 s.com*/
            qaManager.deleteFormElementByID(id);
            deleted.add(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    JSONArray jsonArray = new JSONArray();
    for (Long id : deleted) {
        jsonArray.add(id);
    }

    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    return new ResponseEntity<String>(jsonArray.toString(), headers, HttpStatus.OK);
}

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:org.cloudfoundry.identity.batch.integration.BatchEndpointIntegrationTests.java

/**
 * tests a unauthorized flow of the <code>/batch</code> endpoint
 *///from   ww  w.ja  v a 2 s  .c  o  m
@Test
public void testUnauthorized() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization",
            String.format("Basic %s", new String(Base64.encode("batch:bogus".getBytes()))));
    ResponseEntity<String> response = serverRunning.getForString("/batch/", headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());

    String map = response.getBody();
    // System.err.println(map);
    assertTrue(map.contains("{\"error\""));

}

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

private ResponseEntity<String> getIndexHtml() {
    ResponseEntity<String> response;
    try {//from  w w  w  . ja v a 2 s . com
        HttpHeaders headers = new HttpHeaders();
        headers.add("content-type", "text/html");
        response = new ResponseEntity<String>(
                FileCopyUtils.copyToString(
                        new FileReader(ResourceLocator.getClasspathRelativeFile("assets/index.html"))),
                headers, HttpStatus.OK);
        return response;
    } catch (Exception e) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.github.ljtfreitas.restify.http.spring.client.call.exec.ResponseEntityConverter.java

private HttpHeaders headersOf(Headers headers) {
    HttpHeaders httpHeaders = new HttpHeaders();
    headers.all().forEach(h -> httpHeaders.add(h.name(), h.value()));
    return httpHeaders;
}

From source file:org.cloudfoundry.identity.batch.integration.BatchEndpointIntegrationTests.java

/**
 * tests a happy-day flow of the <code>/batch</code> endpoint
 */// w ww  .ja  va2  s .c  o  m
@Test
public void testHappyDay() throws Exception {

    String credentials = String.format("%s:%s", "batch", "batchsecret");
    String auth = String.format("Basic %s", new String(Base64.encode(credentials.getBytes())));

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", auth);
    ResponseEntity<String> response = serverRunning.getForString("/batch/", headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());

    String map = response.getBody();
    assertTrue(map.contains("jobs"));

}

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);
}

From source file:org.cloudfoundry.identity.varz.integration.VarzEndpointIntegrationTests.java

/**
 * tests a happy-day flow of the <code>/varz</code> endpoint
 *//*from  w w  w  .  java  2  s  . c  o m*/
@Test
public void testHappyDay() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", testAccounts.getVarzAuthorizationHeader());
    ResponseEntity<String> response = serverRunning.getForString("/", headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());

    String map = response.getBody();
    assertTrue(map.contains("thread_pool"));

}