List of usage examples for org.springframework.http HttpHeaders setLocation
public void setLocation(@Nullable URI location)
From source file:org.wallride.web.support.ControllerUtils.java
public static ResponseEntity<?> createRedirectResponseEntity(HttpServletRequest nativeRequest, HttpServletResponse nativeResponse, String path) { UrlPathHelper pathHelper = new UrlPathHelper(); String url = pathHelper.getContextPath(nativeRequest) + path; String encodedUrl = nativeResponse.encodeRedirectURL(url); HttpHeaders headers = new HttpHeaders(); headers.setLocation(URI.create(encodedUrl)); ResponseEntity<?> response = new ResponseEntity<>(null, headers, HttpStatus.FOUND); return response; }
From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilder.java
/** * Creates a typed ResponseEntity with HTTP status code 201/204 with a given location. * * @param location/*from w ww .j ava2 s . co m*/ * The location of the created resource * @param noContent * false means updated resource which returns 204, true means created resource which returns 201 * @return The corresponding ResponseEntity */ public static <T> ResponseEntity<T> created(final String location, final boolean noContent) { HttpStatus status = noContent ? HttpStatus.NO_CONTENT : HttpStatus.CREATED; if (location != null) { HttpHeaders headers = new HttpHeaders(); headers.setLocation(URI.create(location)); return new ResponseEntity<T>(headers, status); } return new ResponseEntity<T>(status); }
From source file:com.recursivechaos.clearent.controller.SaleController.java
private HttpHeaders createHeaders(Sale newSale) { final URI location = responseService.getLocationUri(newSale); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return headers; }
From source file:com.billkoch.examples.people.controllers.PeopleController.java
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Person> create(@RequestBody Person person) { Person persistedPerson = peopleRepository.save(person); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(person.getId()).toUri()); return new ResponseEntity<>(persistedPerson, headers, HttpStatus.CREATED); }
From source file:com.arya.latihan.controller.SalesOrderController.java
@RequestMapping(method = RequestMethod.POST) @Transactional(readOnly = false)//from w w w . j ava2 s .c o m public ResponseEntity<SalesOrder> saveSalesOrder(@Valid SalesOrder salesOrder) { salesOrder = salesOrderRepository.save(salesOrder); URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(salesOrder.getId()) .toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity<SalesOrder>(headers, HttpStatus.CREATED); }
From source file:com.cocktail.controller.CocktailController.java
@RequestMapping(value = "/cocktails/cocktail", method = RequestMethod.POST) public ResponseEntity<?> addCocktail(@RequestBody CocktailResource cocktailDTO, UriComponentsBuilder ucBuilder) { Cocktail cocktail = cocktailService.addCocktail(cocktailDTO); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/Cocktails/Cocktail/{id}").buildAndExpand(cocktail.getId()).toUri()); return new ResponseEntity<>(null, headers, HttpStatus.CREATED); }
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) {/* w w w . ja v a 2s . c o 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: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 www . jav a 2 s . co 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:net.orpiske.tcs.service.rest.controller.DomainCommandsController.java
@RequestMapping(value = "/{domain}", method = RequestMethod.POST) @ResponseBody/*from w w w. ja va 2 s. co m*/ public ResponseEntity<Domain> createCspTagCloud(@RequestBody final Domain domain, UriComponentsBuilder builder) { if (logger.isDebugEnabled()) { logger.debug("CSP command controller handling a create CSP request for " + domain); } DomainCreateEvent tagCloudEvent = tagCloudService.createDomain(new RequestCreateDomainEvent(domain)); Domain domainObj = tagCloudEvent.getDomain(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(builder.path("/domain/{domain}").buildAndExpand(domainObj.getDomain()).toUri()); return new ResponseEntity<Domain>(domainObj, httpHeaders, HttpStatus.OK); }
From source file:de.escalon.hypermedia.spring.sample.ReviewController.java
@Action("ReviewAction") @RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST, params = { "review", "rating" }) public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestParam String review, @RequestParam int rating) { final HttpHeaders headers = new HttpHeaders(); headers.setLocation( AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri()); return new ResponseEntity(headers, HttpStatus.CREATED); }