Example usage for org.springframework.http HttpHeaders setLocation

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

Introduction

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

Prototype

public void setLocation(@Nullable URI location) 

Source Link

Document

Set the (new) location of a resource, as specified by the Location header.

Usage

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

@RequestMapping(method = POST, value = USERS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<User> createUser(@RequestBody NewUser newUser, User actor, UriComponentsBuilder builder) {
    log.info("createUser({}, {}, {})", newUser.role, urlEncode(newUser.username), newUser.operatorId);
    User createdUser = userService.createUser(newUser, actor);
    log.info("createUser({})", createdUser.id);

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

From source file:com.gazbert.bxbot.rest.api.EngineConfigController.java

/**
 * Updates Engine configuration for the bot.
 *
 * @return 204 'No Content' HTTP status code if engine config was updated successfully, some other HTTP status code otherwise.
 *//*from  ww w.  j  a  v a  2  s .  co  m*/
@RequestMapping(value = "/engine", method = RequestMethod.PUT)
public ResponseEntity<?> updateEngine(@AuthenticationPrincipal User user, @RequestBody EngineConfig config) {

    engineConfigService.updateConfig(config);
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders
            .setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/").buildAndExpand().toUri());
    return new ResponseEntity<>(null, httpHeaders, HttpStatus.NO_CONTENT);
}

From source file:com.tamnd2.basicwebapp.rest.mvc.BlogController.java

@RequestMapping(value = "/{blogId}/blog-entries", method = RequestMethod.POST)
public ResponseEntity<BlogEntryResource> createBlogEntry(@PathVariable Long blogId,
        @RequestBody BlogEntryResource sentBlogEntry) {
    BlogEntry createdBlogEntry = null;/*  w w  w.  j a v a  2 s . c  o m*/
    try {
        createdBlogEntry = blogService.createBlogEntry(blogId, sentBlogEntry.toBlogEntry());
        BlogEntryResource createdResource = new BlogEntryResourceAsm().toResource(createdBlogEntry);
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(URI.create(createdResource.getLink("self").getHref()));
        return new ResponseEntity<BlogEntryResource>(createdResource, headers, HttpStatus.CREATED);
    } catch (BlogNotFoundException e) {
        throw new NotFoundException(e);
    }
}

From source file:de.escalon.hypermedia.sample.event.ReviewController.java

@Action("ReviewAction")
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) {
    Assert.notNull(review);/*from w w w  .ja v  a  2 s  . co  m*/
    Assert.notNull(review.getReviewRating());
    Assert.notNull(review.getReviewRating().getRatingValue());
    ResponseEntity<Void> responseEntity;
    try {
        eventBackend.addReview(eventId, review.getReviewBody(), review.getReviewRating());
        final HttpHeaders headers = new HttpHeaders();
        headers.setLocation(AffordanceBuilder
                .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri());
        responseEntity = new ResponseEntity<Void>(headers, HttpStatus.CREATED);
    } catch (NoSuchElementException ex) {
        responseEntity = new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
    }
    return responseEntity;
}

From source file:com.gazbert.bxbot.rest.api.EmailAlertsConfigController.java

/**
 * Updates Email Alerts configuration for the bot.
 *
 * @return 204 'No Content' HTTP status code if Email Alerts config was updated, some other HTTP status code otherwise.
 *//*from   ww w .j ava  2 s.co  m*/
@RequestMapping(value = "/emailalerts", method = RequestMethod.PUT)
ResponseEntity<?> updateEmailAlerts(@AuthenticationPrincipal User user, @RequestBody EmailAlertsConfig config) {

    emailAlertsConfigService.updateConfig(config);
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders
            .setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/").buildAndExpand().toUri());
    return new ResponseEntity<>(null, httpHeaders, HttpStatus.NO_CONTENT);
}

From source file:com.gazbert.bxbot.rest.api.ExchangeConfigController.java

/**
 * Updates Exchange configuration for the bot.
 *
 * @return 204 'No Content' HTTP status code if exchange config was updated, some other HTTP status code otherwise.
 *///from w w  w.  j av a2  s .c om
@RequestMapping(value = "/exchange", method = RequestMethod.PUT)
ResponseEntity<?> updateExchange(@AuthenticationPrincipal User user, @RequestBody ExchangeConfig config) {

    exchangeConfigService.updateConfig(config);
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders
            .setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/").buildAndExpand().toUri());
    return new ResponseEntity<>(null, httpHeaders, HttpStatus.NO_CONTENT);
}

From source file:com.jee.shiro.rest.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = "applaction/json")
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);

    // ?/*from   www .j  ava 2s. co  m*/
    taskService.saveTask(task);

    // Restful?url, ?id.
    Long id = task.getId();
    URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);

    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:cn.aozhi.songify.rest.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);

    // ?//from   www. ja v a 2  s  .  c  om
    taskService.saveTask(task);

    // Restful?url, ?id.
    Long id = task.getId();
    URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);

    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:cn.dsgrp.field.stock.rest.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);

    // ?/*from  w  ww .  ja  v a2 s . c om*/
    taskService.saveTask(task);

    // Restful?url, ?id.
    BigInteger id = task.getId();
    URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);

    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:org.farrukh.examples.rest.inbound.GreetingInboundGateway.java

/**
 * Sends a message back to the service./* ww  w.ja  v  a  2s  . c  o m*/
 *
 * @param request the request.
 * @param headers the request headers.
 * @return the http status code.
 */
@RequestMapping(value = "/convert", method = POST, consumes = Response.JSON_MIME_TYPE)
public ResponseEntity<Response<Greeting>> postGreeting(@RequestBody final Request<Greeting> request,
        @RequestHeader final HttpHeaders headers) {
    Greeting greeting = request.getPayload();
    Greeting converted = coreService.convert(greeting);
    Response<Greeting> response = new Response<>();
    response.setPayload(converted);
    ControllerLinkBuilder linkTo = linkTo(
            methodOn(GreetingInboundGateway.class).postGreeting(request, headers));
    response.add(linkTo.withSelfRel());
    HttpHeaders responseHeader = new HttpHeaders();
    responseHeader.setLocation(linkTo.toUri());
    return new ResponseEntity<>(response, responseHeader, HttpStatus.OK);
}