本文整理匯總了Java中org.springframework.http.HttpHeaders.setLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.setLocation方法的具體用法?Java HttpHeaders.setLocation怎麽用?Java HttpHeaders.setLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.setLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveMedic
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@PostMapping
public ResponseEntity<?> saveMedic(@RequestBody Medic medic, BindingResult result) {
medicValidator.validate(medic, result);
if (result.hasErrors()) {
return new ResponseEntity<>(result.getAllErrors(), HttpStatus.NOT_ACCEPTABLE);
}
Medic newMedic = medicService.save(medic);
if (newMedic != null) {
final URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/v1/medics/{id}").build()
.expand(newMedic.getId()).toUri();
final HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}
return new ResponseEntity<Void>(HttpStatus.SERVICE_UNAVAILABLE);
}
示例2: createOrder
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/order/", method = RequestMethod.POST)
public ResponseEntity<?> createOrder(@RequestBody Order order, UriComponentsBuilder ucBuilder) {
logger.info("Creating order : {}", order);
if (orderService.orderExists(order)) {
logger.error("Unable to create. An order with id {} already exist", order.getOrderId());
return new ResponseEntity(new CustomErrorType("Unable to create. An order with id " +
order.getOrderId() + " already exists."),HttpStatus.CONFLICT);
}
Order currentOrder = orderService.createOrder(order);
Long currentOrderId = currentOrder.getOrderId();
JSONObject orderInfo = new JSONObject();
orderInfo.put("orderId", currentOrderId);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/api/order/").buildAndExpand(order.getOrderId()).toUri());
return new ResponseEntity<JSONObject>(orderInfo, HttpStatus.CREATED);
}
示例3: checkResetToken
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@RequestMapping(value = "/noauth/resetPassword", params = { "resetToken" }, method = RequestMethod.GET)
public ResponseEntity<String> checkResetToken(
@RequestParam(value = "resetToken") String resetToken) {
HttpHeaders headers = new HttpHeaders();
HttpStatus responseStatus;
String resetPasswordURI = "/login/resetPassword";
UserCredentials userCredentials = userService.findUserCredentialsByResetToken(resetToken);
if (userCredentials != null) {
try {
URI location = new URI(resetPasswordURI + "?resetToken=" + resetToken);
headers.setLocation(location);
responseStatus = HttpStatus.SEE_OTHER;
} catch (URISyntaxException e) {
log.error("Unable to create URI with address [{}]", resetPasswordURI);
responseStatus = HttpStatus.BAD_REQUEST;
}
} else {
responseStatus = HttpStatus.CONFLICT;
}
return new ResponseEntity<>(headers, responseStatus);
}
示例4: postClass
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> postClass(JwtAuthenticationToken token, @RequestBody Class klass) {
UserContext userContext = (UserContext) token.getPrincipal();
Class saved = classService.save(userContext.getTenantId(), userContext.getOrgId(), klass);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}")
.buildAndExpand(saved.getSourcedId()).toUri());
return new ResponseEntity<>(saved, httpHeaders, HttpStatus.CREATED);
}
示例5: checkActivateToken
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@RequestMapping(value = "/noauth/activate", params = { "activateToken" }, method = RequestMethod.GET)
public ResponseEntity<String> checkActivateToken(
@RequestParam(value = "activateToken") String activateToken) {
HttpHeaders headers = new HttpHeaders();
HttpStatus responseStatus;
UserCredentials userCredentials = userService.findUserCredentialsByActivateToken(activateToken);
if (userCredentials != null) {
String createPasswordURI = "/login/createPassword";
try {
URI location = new URI(createPasswordURI + "?activateToken=" + activateToken);
headers.setLocation(location);
responseStatus = HttpStatus.SEE_OTHER;
} catch (URISyntaxException e) {
log.error("Unable to create URI with address [{}]", createPasswordURI);
responseStatus = HttpStatus.BAD_REQUEST;
}
} else {
responseStatus = HttpStatus.CONFLICT;
}
return new ResponseEntity<>(headers, responseStatus);
}
示例6: createTicketGrantingTicket
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
/**
* Create new ticket granting ticket.
*
* @param requestBody username and password application/x-www-form-urlencoded values
* @param request raw HttpServletRequest used to call this method
* @return ResponseEntity representing RESTful response
*/
@RequestMapping(value = "/tickets", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public final ResponseEntity<String> createTicketGrantingTicket(@RequestBody final MultiValueMap<String, String> requestBody,
final HttpServletRequest request) {
try (Formatter fmt = new Formatter()) {
final TicketGrantingTicket tgtId = this.cas.createTicketGrantingTicket(obtainCredential(requestBody));
final URI ticketReference = new URI(request.getRequestURL().toString() + '/' + tgtId.getId());
final HttpHeaders headers = new HttpHeaders();
headers.setLocation(ticketReference);
headers.setContentType(MediaType.TEXT_HTML);
fmt.format("<!DOCTYPE HTML PUBLIC \\\"-//IETF//DTD HTML 2.0//EN\\\"><html><head><title>");
//IETF//DTD HTML 2.0//EN\\\"><html><head><title>");
fmt.format("%s %s", HttpStatus.CREATED, HttpStatus.CREATED.getReasonPhrase())
.format("</title></head><body><h1>TGT Created</h1><form action=\"%s", ticketReference.toString())
.format("\" method=\"POST\">Service:<input type=\"text\" name=\"service\" value=\"\">")
.format("<br><input type=\"submit\" value=\"Submit\"></form></body></html>");
return new ResponseEntity<String>(fmt.toString(), headers, HttpStatus.CREATED);
} catch (final Throwable e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
示例7: createUser
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@PostMapping(value = {""})
public ResponseEntity<Void> createUser(
@RequestBody @Valid UserForm form,
HttpServletRequest req) {
log.debug("user [email protected]" + form);
User saved = this.userService.createUser(form);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(
ServletUriComponentsBuilder
.fromContextPath(req)
.path("/users/{username}")
.buildAndExpand(saved.getId()).toUri()
);
return new ResponseEntity<>(headers, HttpStatus.CREATED);
}
示例8: create
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody NoteInput noteInput) {
Note note = new Note();
note.setTitle(noteInput.getTitle());
note.setBody(noteInput.getBody());
note.setTags(getTags(noteInput.getTagUris()));
this.noteRepository.save(note);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders
.setLocation(linkTo(NotesController.class).slash(note.getId()).toUri());
return httpHeaders;
}
示例9: createBook
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@PostMapping
public ResponseEntity<?> createBook(@Valid @RequestBody Book book, UriComponentsBuilder ucBuilder) {
if (bookRepository.findByIsbn(book.getIsbn()).isPresent()) {
throw new BookIsbnAlreadyExistsException(book.getIsbn());
}
bookRepository.save(book);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/api/books/{isbn}").buildAndExpand(book.getIsbn()).toUri());
return new ResponseEntity<>(headers, HttpStatus.CREATED);
}
示例10: handleException
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@ExceptionHandler(value = {ResultException.class})
public ResponseEntity<Object> handleException(ResultException ex, HttpServletRequest request) throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.setLocation(new URI(request.getRequestURI()));
headers.setContentType(MediaType.APPLICATION_JSON);
logger.error("-----exception Handler---Host: {} invokes url: {} ERROR: {} Cause:",request.getRemoteHost(),request.getRequestURL(), ex.getMessage(),ex.getCause());
return handleExceptionInternal(ex,headers,HttpStatus.INTERNAL_SERVER_ERROR,request);
}
示例11: buildAvatarUpdateResponse
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
private static ResponseEntity<Void> buildAvatarUpdateResponse(URI uri) {
HttpHeaders headers = new HttpHeaders();
if (uri != null) {
headers.setLocation(uri);
}
return new ResponseEntity<>(headers, HttpStatus.CREATED);
}
示例12: postEnrollment
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@RequestMapping(value= "/{classId}/enrollments", method = RequestMethod.POST)
public ResponseEntity<?> postEnrollment(JwtAuthenticationToken token, @RequestBody Enrollment enrollment) {
UserContext userContext = (UserContext) token.getPrincipal();
Enrollment savedEnrollment = enrollmentService.save(userContext.getTenantId(), userContext.getOrgId(), enrollment);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}")
.buildAndExpand(savedEnrollment.getSourcedId()).toUri());
return new ResponseEntity<>(savedEnrollment, httpHeaders, HttpStatus.CREATED);
}
示例13: create
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody TagInput tagInput) {
Tag tag = new Tag();
tag.setName(tagInput.getName());
this.repository.save(tag);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(linkTo(TagsController.class).slash(tag.getId()).toUri());
return httpHeaders;
}
示例14: post
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> post(JwtAuthenticationToken token, @RequestBody Org org) {
UserContext userContext = (UserContext) token.getPrincipal();
Org savedOrg = this.orgService.save(userContext.getTenantId(), org);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}")
.buildAndExpand(savedOrg.getSourcedId()).toUri());
return new ResponseEntity<>(savedOrg, httpHeaders, HttpStatus.CREATED);
}
示例15: postLineItem
import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@RequestMapping(value= "/{classId}/lineitems", method = RequestMethod.POST)
public ResponseEntity<?> postLineItem(JwtAuthenticationToken token, @RequestBody LineItem lineItem) {
UserContext userContext = (UserContext) token.getPrincipal();
LineItem savedLineItem = this.lineItemService.save(userContext.getTenantId(), userContext.getOrgId(), lineItem);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}")
.buildAndExpand(savedLineItem.getSourcedId()).toUri());
return new ResponseEntity<>(savedLineItem, httpHeaders, HttpStatus.CREATED);
}