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:monkeys.web.BananasController.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody//from  w w  w.  j  av  a 2 s  .c om
public ResponseEntity<Void> createBanana(@RequestBody Banana banana) {
    bananaRepository.save(banana);
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}

From source file:ch.wisv.areafiftylan.utils.ResponseEntityBuilder.java

/**
 * Create a standard response for all requests to the API
 *
 * @param httpStatus  The HTTP Status of the response
 * @param httpHeaders Optional Http Headers for the response.
 * @param message     The message in human readable String format
 * @param object      Optional object related to the request (like a created User)
 *
 * @return The ResponseEntity in standard Area FiftyLAN format.
 *//*  www . ja  v a  2  s .co m*/
public static ResponseEntity<?> createResponseEntity(HttpStatus httpStatus, HttpHeaders httpHeaders,
        String message, Object object) {
    Map<String, Object> responseBody = new LinkedHashMap<>();
    responseBody.put("status", httpStatus.toString());
    responseBody.put("timestamp", LocalDateTime.now().toString());
    responseBody.put("message", message);
    responseBody.put("object", object);

    if (httpHeaders == null) {
        httpHeaders = new HttpHeaders();
    }
    return new ResponseEntity<>(responseBody, httpHeaders, httpStatus);
}

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

public static HttpHeaders zipHeaders() {
    HttpHeaders bitsHeaders = new HttpHeaders();
    bitsHeaders.add(CONTENT_TYPE_HEADER_NAME, "application/zip");

    return bitsHeaders;
}

From source file:com.develcom.cliente.Cliente.java

public void buscarArchivo() throws FileNotFoundException, IOException {

    CodDecodArchivos cda = new CodDecodArchivos();
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    //        Bufer bufer = new Bufer();
    byte[] buffer = null;
    ResponseEntity<byte[]> response;

    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    headers.setAccept(Arrays.asList(MediaType.ALL));
    HttpEntity<String> entity = new HttpEntity<>(headers);

    response = restTemplate.exchange(//from w  w w  .ja  v  a 2s.  co m
            "http://localhost:8080/ServicioDW4J/expediente/buscarFisicoDocumento/21593", HttpMethod.GET, entity,
            byte[].class);

    if (response.getStatusCode().equals(HttpStatus.OK)) {
        buffer = response.getBody();
        FileOutputStream output = new FileOutputStream(new File("c:/documentos/archivo.cod"));
        IOUtils.write(response.getBody(), output);
        cda.decodificar("c:/documentos/archivo.cod", "c:/documentos/archivo.pdf");
    }

}

From source file:com.develcom.reafolder.ClienteBajaArchivo.java

public void buscarArchivo() throws FileNotFoundException, IOException {

    CodDecodArchivos cda = new CodDecodArchivos();
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    Bufer bufer = new Bufer();
    byte[] buffer = null;
    ResponseEntity<byte[]> response;

    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    headers.setAccept(Arrays.asList(MediaType.ALL));
    HttpEntity<String> entity = new HttpEntity<>(headers);

    response = restTemplate.exchange(/*  ww  w . j a  va 2 s.  com*/
            "http://localhost:8080/ServicioDW4J/expediente/buscarFisicoDocumento/21593", HttpMethod.GET, entity,
            byte[].class);

    if (response.getStatusCode().equals(HttpStatus.OK)) {
        buffer = response.getBody();
        FileOutputStream output = new FileOutputStream(new File("c:/documentos/archivo.cod"));
        IOUtils.write(response.getBody(), output);
        cda.decodificar("c:/documentos/archivo.cod", "c:/documentos/archivo.pdf");
    }

}

From source file:de.codecentric.boot.admin.services.ApplicationRegistrator.java

private static HttpHeaders createHttpHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    return HttpHeaders.readOnlyHttpHeaders(headers);
}

From source file:org.cloudfoundry.example.Controller.java

private static RequestEntity<?> getOutgoingRequest(RequestEntity<?> incoming) {
    HttpHeaders headers = new HttpHeaders();
    headers.putAll(incoming.getHeaders());

    URI uri = headers.remove(FORWARDED_URL).stream().findFirst().map(URI::create)
            .orElseThrow(() -> new IllegalStateException(String.format("No %s header present", FORWARDED_URL)));

    return new RequestEntity<>(incoming.getBody(), headers, incoming.getMethod(), uri);
}

From source file:org.focusns.common.web.WebUtils.java

public static <T> ResponseEntity<T> getResponseEntity(T body, MediaType mediaType) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(mediaType);
    if (body instanceof byte[]) {
        httpHeaders.setContentLength(((byte[]) body).length);
    }//from w w w.  ja v  a  2 s  .c o m
    return new ResponseEntity<T>(body, httpHeaders, HttpStatus.OK);
}

From source file:cn.org.once.cstack.utils.RestUtils.java

@SuppressWarnings("rawtypes")
public static String sendPostCommand(String url, String volume) {

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "text/plain");
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("Binds", volume);
    @SuppressWarnings("unchecked")
    HttpEntity request = new HttpEntity(params, headers);
    ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
    return response.toString();
}

From source file:org.cloudfoundry.identity.uaa.integration.HealthzEndpointIntegrationTests.java

/**
 * tests a happy-day flow of the <code>/healthz</code> endpoint
 *///from   w w  w  .  j  a v a 2s  .com
@Test
public void testHappyDay() throws Exception {

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

    String body = response.getBody();
    assertTrue(body.contains("ok"));

}