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


Java ServletUriComponentsBuilder类代码示例

本文整理汇总了Java中org.springframework.web.servlet.support.ServletUriComponentsBuilder的典型用法代码示例。如果您正苦于以下问题:Java ServletUriComponentsBuilder类的具体用法?Java ServletUriComponentsBuilder怎么用?Java ServletUriComponentsBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServletUriComponentsBuilder类属于org.springframework.web.servlet.support包,在下文中一共展示了ServletUriComponentsBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveMedic

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的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: createUserProject

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}", method = RequestMethod.POST)
@ApiOperation(value = "Create a relation between user and project")
@ApiResponses(value = {
        @ApiResponse(code = 404, message = "ID of project or user invalid")
})
//TODO: Replace explicit user{id} with AuthN user id.
public ResponseEntity<?> createUserProject(@ApiParam(value = "ID of user", required = true)
                                              @PathVariable("userId") Integer userId,
                                           @ApiParam(value = "ID of project", required = true)
                                              @PathVariable("id") Integer projectId) {
    try {
        projectService.saveUserProject(userId, projectId);
        URI location = ServletUriComponentsBuilder.fromCurrentRequest()
                                                  .path("/{id}/users/{userId}")
                                                  .buildAndExpand(projectId, userId).toUri();
        return ResponseEntity.created(location).build();
    }catch (NullPointerException | UserProjectException e){
        throw new NotFoundException("ID of project or user invalid");
    }
}
 
开发者ID:Code4SocialGood,项目名称:C4SG-Obsolete,代码行数:22,代码来源:ProjectController.java

示例3: createUser

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的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

示例4: createPost

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@PostMapping()
public ResponseEntity<Void> createPost(@RequestBody @Valid PostForm post, HttpServletRequest request) {

    log.debug("create a new [email protected]" + post);

    Post saved = this.postService.createPost(post);

    log.debug("saved post id is @" + saved.getId());
    URI loacationHeader = ServletUriComponentsBuilder
        .fromContextPath(request)
        .path("/posts/{slug}")
        .buildAndExpand(saved.getSlug())
        .toUri();

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(loacationHeader);

    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}
 
开发者ID:hantsy,项目名称:spring-microservice-sample,代码行数:20,代码来源:PostController.java

示例5: createComment

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@PostMapping(value = "/{slug}/comments")
public ResponseEntity<Void> createComment(
    @PathVariable("slug") @NotNull String slug, @RequestBody CommentForm comment, HttpServletRequest request) {

    log.debug("new comment of [email protected]" + slug + ", comment" + comment);

    Comment _comment = Comment.builder()
        .post(new Slug(slug))
        .content(comment.getContent())
        .build();

    Comment saved = this.commentRepository.save(_comment);

    log.debug("saved comment @" + saved.getId());

    URI location = ServletUriComponentsBuilder
        .fromContextPath(request)
        .path("/posts/{slug}/comments/{id}")
        .buildAndExpand(slug, saved.getId())
        .toUri();

     return ResponseEntity.created(location).build();
}
 
开发者ID:hantsy,项目名称:spring-microservice-sample,代码行数:24,代码来源:PostController.java

示例6: createPlugin

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Void> createPlugin(@RequestBody PluginIdContainer pluginIdContainer) {
    if (null != pluginRepository.findByPluginNameEquals(pluginIdContainer.getPluginId())) {
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

    PluginEntity pluginEntity = new PluginEntity(pluginIdContainer.getPluginId(), pluginIdContainer.getDefaultVersion(),
            pluginIdContainer.getDocumentationLink(), new ArrayList<>());
    pluginEntity = pluginRepository.save(pluginEntity);

    for (PluginVersion pluginVersion : pluginIdContainer.getVersions().values()) {
        pluginEntity.getVersions().add(Transformer.fromPluginVersion(pluginEntity, pluginVersion));
    }

    pluginRepository.save(pluginEntity);

    URI uri = ServletUriComponentsBuilder
            .fromCurrentRequest().path("/{id}")
            .buildAndExpand(pluginIdContainer.getPluginId()).toUri();

    return ResponseEntity.created(uri).build();
}
 
开发者ID:linkedin,项目名称:custom-gradle-plugin-portal,代码行数:23,代码来源:PluginsResource.java

示例7: addVersion

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@RequestMapping(value = "/{id:.+}", method = RequestMethod.POST)
public ResponseEntity<Void> addVersion(@PathVariable("id") String id,
                                       @RequestBody PluginVersion version) {
    PluginEntity plugin = pluginRepository.findByPluginNameEquals(id);

    if (null == plugin) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    if (null != versionRepository.findByPluginEntityAndPluginVersionEquals(plugin, version.getVersion())) {
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

    PluginVersionEntity versionEntity = Transformer.fromPluginVersion(plugin, version);
    plugin.getVersions().add(versionEntity);
    pluginRepository.save(plugin);

    URI uri = ServletUriComponentsBuilder
            .fromCurrentRequest().path("/{id}")
            .buildAndExpand(version.getVersion()).toUri();

    return ResponseEntity.created(uri).build();
}
 
开发者ID:linkedin,项目名称:custom-gradle-plugin-portal,代码行数:24,代码来源:PluginsResource.java

示例8: getLocaleUrl

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
public String getLocaleUrl(String locale) throws Exception {
    UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest().replaceQueryParam("locale", locale);
    RequestAttributes attributes = org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes();
    if (attributes instanceof ServletRequestAttributes) {
        int statusCode = ((ServletRequestAttributes) attributes).getResponse().getStatus();
        switch (statusCode) {
            case 200:
                break;
            case 404:
                builder.replacePath("" + statusCode);
                break;
            default:
                builder.replacePath("error");
        }
    }
    URI serverUri = new URI(this.casConfigurationProperties.getServer().getName());
    if ("https".equalsIgnoreCase(serverUri.getScheme())) {
        builder.port((serverUri.getPort() == -1) ? 443 : serverUri.getPort());
    }
    return builder.scheme(serverUri.getScheme()).host(serverUri.getHost()).build(true).toUriString();
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:22,代码来源:TaraProperties.java

示例9: setup

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@BeforeClass
public static void setup() {
	UriComponentsBuilder builder = ServletUriComponentsBuilder.fromUriString("dummy");
	linkHeaderBuilder = new HateoasLinkHeaderBuilder(builder);

	Pageable nextPageable = mock(Pageable.class);
	when(nextPageable.getPageNumber()).thenReturn(4);

	Pageable prevPageable = mock(Pageable.class);
	when(prevPageable.getPageNumber()).thenReturn(2);

	page = mock(Page.class);
	when(page.nextPageable()).thenReturn(nextPageable);
	when(page.previousPageable()).thenReturn(prevPageable);
	when(page.getTotalPages()).thenReturn(6);
}
 
开发者ID:cmateosl,项目名称:role-api,代码行数:17,代码来源:HateoasLinkHeaderBuilderTest.java

示例10: createUserOrganization

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}", method = RequestMethod.POST)
@ApiOperation(value = "Create a relation between user and organization")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of organization or user invalid") })
// TODO: Replace explicit user{id} with AuthN user id.
public ResponseEntity<?> createUserOrganization(
		@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId,
		@ApiParam(value = "ID of organization", required = true) @PathVariable("id") Integer organizationId) {
	
   	System.out.println("************** OrganizationController.createUserOrganization()" 
               + ": userId=" + userId  
               + "; organizationId=" + organizationId  
               + " **************");
   	
	try {
		organizationService.saveUserOrganization(userId, organizationId);
		URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}/users/{userId}")
				.buildAndExpand(organizationId, userId).toUri();
		return ResponseEntity.created(location).build();
	} catch (NullPointerException | UserOrganizationException e) {
		throw new NotFoundException("ID of organization or user invalid, or relationship already exist");
	}
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:24,代码来源:OrganizationController.java

示例11: postUser

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "新增用户")
@PostMapping
public ResponseEntity<?> postUser(@RequestBody User user) {
    Optional<User> result = userService.getUserByName(user.getUsername());

    if (!result.isPresent()) {
        userService.addUser(user);
        URI location = ServletUriComponentsBuilder
                .fromCurrentRequest()
                .path("/{id}")
                .buildAndExpand(user.getId())
                .toUri();
        return ResponseEntity.created(location).body(user);
    } else {
        return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).build();
    }
}
 
开发者ID:ustcwudi,项目名称:springboot-seed,代码行数:18,代码来源:UserController.java

示例12: connectToProxiedTarget

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
private void connectToProxiedTarget(WebSocketSession session) {
	URI sessionUri = session.getUri();
	ZuulWebSocketProperties.WsBrokerage wsBrokerage = getWebSocketBrokarage(
			sessionUri);

	Assert.notNull(wsBrokerage, "wsBrokerage");

	String path = getWebSocketServerPath(wsBrokerage, sessionUri);
	Assert.notNull(path, "Web socket uri path");

	String routeHost = zuulPropertiesResolver.getRouteHost(wsBrokerage);
	Assert.notNull(routeHost, "routeHost");

       String uri = ServletUriComponentsBuilder
               .fromHttpUrl(routeHost)
               .path(path)
               .replaceQuery(sessionUri.getQuery())
               .toUriString();

	ProxyWebSocketConnectionManager connectionManager = new ProxyWebSocketConnectionManager(
			messagingTemplate, stompClient, session, headersCallback, uri);
	connectionManager.errorHandler(this.errorHandler);
	managers.put(session, connectionManager);
	connectionManager.start();
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:26,代码来源:ProxyWebSocketHandler.java

示例13: postClass

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的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

示例14: createTag

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
/**
 * Process POST /tags request
 * Create a tag
 *
 * @param tag tag to create
 * @return response entity
 */
@Override
public ResponseEntity<Object> createTag(@ApiParam(value = "Create a tag", required = true) @RequestBody Tag tag) {

    // Create tag in database
    TagEntity entity = toTagEntity(tag);
    tagRepository.save(entity);

    URI location = ServletUriComponentsBuilder.fromCurrentRequest()
            .path("/{id}")
            .buildAndExpand(entity.getId())
            .toUri();

    // Update tag's URL in database
    entity.setUrl(location.toString());
    tagRepository.save(entity);

    return ResponseEntity.created(location).build();
}
 
开发者ID:PestaKit,项目名称:microservice-email,代码行数:26,代码来源:TagApiController.java

示例15: createTemplate

import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入依赖的package包/类
/**
 * Process POST /templates request
 * Create a template
 *
 * @param template template to create
 * @return response entity
 */
@Override
public ResponseEntity<Object> createTemplate(@ApiParam(value = "Create a template", required = true) @RequestBody TemplateBody template) {

    // Create template in database
    TemplateEntity entity = toTemplateEntity(template);

    templateRepository.save(entity);

    URI location = ServletUriComponentsBuilder.fromCurrentRequest()
            .path("/{id}")
            .buildAndExpand(entity.getId())
            .toUri();

    // Update template's URL in database
    entity.setUrl(location.toString());
    templateRepository.save(entity);

    return ResponseEntity.created(location).build();
}
 
开发者ID:PestaKit,项目名称:microservice-email,代码行数:27,代码来源:TemplateApiController.java


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