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:fi.hsl.parkandride.front.ContactController.java

@RequestMapping(method = POST, value = CONTACTS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Contact> createContact(@RequestBody Contact contact, User currentUser,
        UriComponentsBuilder builder) {/*from   w  w  w  .ja v  a  2s. co m*/
    log.info("createContact");
    Contact newContact = contactService.createContact(contact, currentUser);
    log.info("createContact({})", newContact.id);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path(CONTACT).buildAndExpand(newContact.id).toUri());
    return new ResponseEntity<>(newContact, headers, CREATED);
}

From source file:edu.fing.tagsi.db4o.business.CiudadesController.java

public Recorrido ObtenerRecorrido(Ciudad origen, Ciudad destino) {
    RestTemplate restTemplate = new RestTemplate();
    RequestRecorrido req = new RequestRecorrido(origen.getNombre(), destino.getNombre());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<RequestRecorrido> entity = new HttpEntity<>(req, headers);
    RecorridoREST recorrido = restTemplate.postForObject(URL, entity, RecorridoREST.class);

    if (recorrido.getCiudades() != null) {
        NodoCamino[] ciudades = new NodoCamino[recorrido.getCiudades().length];
        for (int i = 0; i < ciudades.length; i++) {
            if (i == 0) {
                ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), true, 0,
                        null);/*  www.ja  va  2s. c o  m*/
            } else {
                Tramo tramo = recorrido.getRutas()[i - 1];
                ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), false,
                        tramo.getDistancia(), tramo.getRutas());
            }
        }
        Recorrido resultado = new Recorrido(recorrido.getDistanciaTotal(), ciudades);
        return resultado;
    } else {
        return null;
    }

}

From source file:HCNIOEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    ResponseEntity<String> stringResponseEntity = null;
    try (CloseableHttpAsyncClient hc = createCloseableHttpAsyncClient()) {
        for (int i = 0; i < requestOptions.getCount(); i++) {
            final HttpHeaders headers = new HttpHeaders();
            for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) {
                headers.put(e.getKey(), Collections.singletonList(e.getValue()));
            }//  w  w w . j  a v  a2  s  . com

            final HttpEntity<Void> requestEntity = new HttpEntity<>(headers);

            AsyncRestTemplate template = new AsyncRestTemplate(
                    new HttpComponentsAsyncClientHttpRequestFactory(hc));
            final ListenableFuture<ResponseEntity<String>> exchange = template.exchange(requestOptions.getUrl(),
                    HttpMethod.GET, requestEntity, String.class);
            stringResponseEntity = exchange.get();
            System.out.println(stringResponseEntity.getBody());

        }
        return stringResponseEntity;
    }
}

From source file:net.eusashead.hateoas.response.impl.AbstractResponseBuilder.java

public AbstractResponseBuilder(HttpServletRequest request) {

    // Validate the request
    if (request == null) {
        throw new IllegalArgumentException("HttpServletRequest is null.");
    }//from  w  w  w.j  a  v a2s .c om

    // Set the request
    this.request = request;

    // Check the HTTP verb is supported
    this.assertVerb();

    // Create new headers
    this.headers = new HttpHeaders();
}

From source file:grails.plugin.cloudfoundry.GrailsHttpResponse.java

public HttpHeaders getHeaders() {
    if (headers == null) {
        headers = new HttpHeaders();
        // Header field 0 is the status line for most HttpURLConnections, but not on GAE
        String name = connection.getHeaderFieldKey(0);
        if (StringUtils.hasLength(name)) {
            headers.add(name, connection.getHeaderField(0));
        }/*from  w  w w .j a  v a  2s .  co m*/
        int i = 1;
        while (true) {
            name = connection.getHeaderFieldKey(i);
            if (!StringUtils.hasLength(name)) {
                break;
            }
            headers.add(name, connection.getHeaderField(i));
            i++;
        }
    }
    return headers;
}

From source file:fi.hsl.parkandride.front.OperatorController.java

@RequestMapping(method = POST, value = OPERATORS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Operator> createOperator(@RequestBody Operator operator, User currentUser,
        UriComponentsBuilder builder) {/*from  w  ww.  j  a  v  a 2s  . c  o m*/
    log.info("createOperator");
    Operator newOperator = operatorService.createOperator(operator, currentUser);
    log.info("createOperator({})", newOperator.id);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path(OPERATOR).buildAndExpand(newOperator.id).toUri());
    return new ResponseEntity<>(newOperator, headers, CREATED);
}

From source file:au.id.hazelwood.sos.web.controller.framework.GlobalExceptionHandler.java

@ExceptionHandler(value = NotFoundException.class)
public ResponseEntity<Object> handleNotFound(Exception ex, WebRequest request) {
    return handleExceptionInternal(ex, createDefaultResponseBody(ex, HttpStatus.NOT_FOUND), new HttpHeaders(),
            HttpStatus.NOT_FOUND, request);
}

From source file:com.arya.latihan.controller.ItemController.java

@RequestMapping(method = RequestMethod.POST)
@Transactional(readOnly = false)//  www. ja  v  a 2s . com
public ResponseEntity<Void> saveItem(@RequestBody @Valid Item item) {
    Integer lastCode = itemRepository.findLastCode();
    String code = "M-" + String.format("%08d", (lastCode + 1));
    item.setCode(code);
    item = itemRepository.save(item);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(item.getId())
            .toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}

From source file:ru.portal.controllers.RestController.java

@RequestMapping(value = { "/main" })
@ResponseBody/*from www.ja va 2s  .  co  m*/
public ResponseEntity<String> main() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-type", "application/json;charset=UTF-8");
    ResponseEntity responseEntity = new ResponseEntity<>("main", headers, HttpStatus.OK);

    return responseEntity;

}

From source file:io.sevenluck.chat.controller.LoginController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseEntity<?> handleException(LoginException e) {
    logger.error("login failed:", e.getMessage());
    return new ResponseEntity<>(ExceptionDTO.newUnauthorizedInstance(e.getMessage()), new HttpHeaders(),
            HttpStatus.UNAUTHORIZED);/*from  w  w w.  j  a  v a  2s .  co m*/
}