当前位置: 首页>>代码示例>>Java>>正文


Java HttpHeaders.setLocation方法代码示例

本文整理汇总了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);
}
 
开发者ID:JUGIstanbul,项目名称:second-opinion-api,代码行数:23,代码来源:MedicController.java

示例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);
}
 
开发者ID:dockersamples,项目名称:atsea-sample-shop-app,代码行数:21,代码来源:OrderController.java

示例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);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:22,代码来源:AuthController.java

示例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);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:11,代码来源:ClassController.java

示例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);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:22,代码来源:AuthController.java

示例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);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:29,代码来源:TicketsResource.java

示例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);
}
 
开发者ID:hantsy,项目名称:spring-microservice-sample,代码行数:19,代码来源:UserController.java

示例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;
}
 
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:17,代码来源:NotesController.java

示例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);
}
 
开发者ID:sbouclier,项目名称:java-rest-books,代码行数:12,代码来源:BookController.java

示例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);
}
 
开发者ID:ZhuXS,项目名称:Spring-Shiro-Spark,代码行数:9,代码来源:GlobalExceptionHandler.java

示例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);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:8,代码来源:XmEntityResource.java

示例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);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:11,代码来源:ClassController.java

示例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;
}
 
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:14,代码来源:TagsController.java

示例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);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:11,代码来源:OrgController.java

示例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);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:11,代码来源:ClassController.java


注:本文中的org.springframework.http.HttpHeaders.setLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。