Example usage for org.springframework.web.util UriComponentsBuilder newInstance

List of usage examples for org.springframework.web.util UriComponentsBuilder newInstance

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder newInstance.

Prototype

public static UriComponentsBuilder newInstance() 

Source Link

Document

Create a new, empty builder.

Usage

From source file:io.bosh.client.SpringDirectorClientBuilder.java

public SpringDirectorClient build() {
    // TODO validate
    URI root = UriComponentsBuilder.newInstance().scheme("https").host(host).port(25555).build().toUri();
    RestTemplate restTemplate = new RestTemplate(createRequestFactory(host, username, password));
    restTemplate.getInterceptors().add(new ContentTypeClientHttpRequestInterceptor());
    handleTextHtmlResponses(restTemplate);
    return new SpringDirectorClient(root, restTemplate);
}

From source file:org.wallride.web.controller.admin.article.ArticleDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Article article = articleService.getArticleById(id);
    if (article == null) {
        throw new HttpNotFoundException();
    }//from   ww  w .jav a 2s  .c o  m

    if (!article.getLanguage().equals(language)) {
        Article target = articleService.getArticleByCode(article.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/articles/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", article);
            redirectAttributes.addAttribute("code", article.getCode());
            return "redirect:/_admin/{language}/articles/create?code={code}";
        }
    }

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new ArticleSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    ArticleSearchForm form = (ArticleSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = articleService.getArticleIds(form.toArticleSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(article.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("article", article);
    model.addAttribute("query", query);
    return "article/describe";
}

From source file:org.openlmis.notification.web.BaseWebIntegrationTest.java

private URI buildUri(String url, Map<String, ?> params) {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance().uri(URI.create(url));

    params.entrySet().forEach(e -> builder.queryParam(e.getKey(), e.getValue()));

    return builder.build(true).toUri();
}

From source file:com.fns.grivet.controller.NamedQueryController.java

@PreAuthorize("hasAuthority('write:query')")
@PostMapping("/api/v1/query")
public ResponseEntity<?> createNamedQuery(@RequestBody NamedQuery query) {
    ResponseEntity<?> result = ResponseEntity.unprocessableEntity().build();
    Assert.isTrue(StringUtils.isNotBlank(query.getName()), "Query name must not be null, empty or blank.");
    Assert.notNull(query.getQuery(), "Query string must not be null!");
    Assert.isTrue(isSupportedQuery(query), "Query must start with either CALL or SELECT");
    // check for named parameters; but only if they exist
    if (!query.getParams().isEmpty()) {
        query.getParams().keySet()/*  ww w  .j  a v a2  s.co  m*/
                .forEach(k -> Assert.isTrue(query.getQuery().contains(String.format(":%s", k)),
                        String.format("Query must contain named parameter [%s]", k)));
    }
    namedQueryService.create(query);
    log.info("Named Query \n\n{}\n\n successfully registered!", query);
    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    if (query.getParams().isEmpty()) {
        result = ResponseEntity
                .created(ucb.path("/api/v1/query/{name}").buildAndExpand(query.getName()).toUri()).build();
    } else {
        result = ResponseEntity.noContent().build();
    }
    return result;
}

From source file:com.cloud.baremetal.networkservice.Force10BaremetalSwitchBackend.java

private String buildLink(String switchIp, String path) {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    builder.scheme("http");
    builder.host(switchIp);//ww w. ja  v a2 s .c  om
    builder.port(8008);
    builder.path(path);
    return builder.build().toUriString();
}

From source file:com.nebhale.cyclinglibrary.web.PointController.java

@RequestMapping(method = RequestMethod.GET, produces = ApplicationMediaType.POINTS_PNG_VALUE)
@ResponseBody/*ww  w  .ja va 2 s .  c om*/
ResponseEntity<Void> read(@PathVariable Long itemId,
        @RequestParam(value = "maptype", defaultValue = "roadmap") String mapType,
        @RequestParam(defaultValue = "250") Integer width, @RequestParam(defaultValue = "250") Integer height,
        @Value("#{request.getRemoteAddr()}") String userIp) {

    Item item = this.itemRepository.read(itemId);

    URI uri = UriComponentsBuilder.newInstance() //
            .scheme("http") //
            .host("maps.googleapis.com") //
            .path("/maps/api/staticmap") //
            .queryParam("key", this.apiKey) //
            .queryParam("sensor", false) //
            .queryParam("userIp", userIp) //
            .queryParam("size", String.format("%dx%d", width, height)) //
            .queryParam("maptype", mapType) //
            .queryParam("scale", 2) //
            .queryParam("path",
                    String.format("color:0xff0000ff|weight:2|%s",
                            this.polylineEncoder.encodeSingle(MAX_ENCODED_LENGTH, item.getPoints()))) //
            .build().toUri();

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

    return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER);
}

From source file:com.example.securelogin.domain.service.passwordreissue.PasswordReissueServiceImpl.java

@Override
public String createAndSendReissueInfo(String username) {

    String rowSecret = passwordGenerator.generatePassword(10, passwordGenerationRules);

    if (!accountSharedService.exists(username)) {
        return rowSecret;
    }//from w  ww.  j a v  a 2s  . c  o  m

    Account account = accountSharedService.findOne(username);

    String token = UUID.randomUUID().toString();

    LocalDateTime expiryDate = dateFactory.newTimestamp().toLocalDateTime().plusSeconds(tokenLifeTimeSeconds);

    PasswordReissueInfo info = new PasswordReissueInfo();
    info.setUsername(username);
    info.setToken(token);
    info.setSecret(passwordEncoder.encode(rowSecret));
    info.setExpiryDate(expiryDate);

    passwordReissueInfoRepository.create(info);

    UriComponentsBuilder uriBuilder = UriComponentsBuilder.newInstance();
    uriBuilder.scheme(protocol).host(host).port(port).path(contextPath).pathSegment("reissue")
            .pathSegment("resetpassword").queryParam("form").queryParam("token", info.getToken());
    String passwordResetUrl = uriBuilder.build().toString();

    mailSharedService.send(account.getEmail(), passwordResetUrl);

    return rowSecret;

}

From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvConfigurationIntegrationTests.java

/**
 * @see DATAREST-271//from   ww w  . j  ava 2  s  .  c o m
 */
@Test
public void assetConsidersPaginationCustomization() {

    HateoasPageableHandlerMethodArgumentResolver resolver = context
            .getBean(HateoasPageableHandlerMethodArgumentResolver.class);

    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    resolver.enhance(builder, null, new PageRequest(0, 9000, Direction.ASC, "firstname"));

    MultiValueMap<String, String> params = builder.build().getQueryParams();

    assertThat(params.containsKey("myPage"), is(true));
    assertThat(params.containsKey("mySort"), is(true));

    assertThat(params.get("mySize"), hasSize(1));
    assertThat(params.get("mySize").get(0), is("7000"));
}

From source file:com.wavemaker.tools.deployment.tomcat.TomcatManager.java

private UriComponentsBuilder newUriBuilder() {
    UriComponentsBuilder uri = UriComponentsBuilder.newInstance();
    uri.scheme("http");
    uri.host(this.host).port(this.port);
    return uri;//from w w w.j  a  v a2 s . c  om
}

From source file:info.joseluismartin.gtc.AbstractTileCache.java

/**
 * Create a parameter map from a query string
 * @param uri the query string//from   ww w  .  j a  v a 2 s .  c om
 * @return a map with parameters
 */
protected Map<String, String> getParameterMap(String uri) {
    UriComponentsBuilder b = UriComponentsBuilder.newInstance();
    b.query(uri);
    UriComponents c = b.build();
    return c.getQueryParams().toSingleValueMap();
}