本文整理汇总了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);
}