List of usage examples for org.springframework.web.util UriComponentsBuilder fromUriString
public static UriComponentsBuilder fromUriString(String uri)
From source file:ru.mystamps.web.controller.ControllerUtils.java
public static String redirectTo(String url, Object... args) { String dstUrl = UriComponentsBuilder.fromUriString(url).buildAndExpand(args).toString(); return "redirect:" + dstUrl; }
From source file:de.blizzy.documentr.web.util.FacadeHostRequestWrapper.java
public static String buildFacadeUrl(String url, String contextPath, String documentrHost) { contextPath = StringUtils.defaultIfBlank(contextPath, StringUtils.EMPTY); if (contextPath.equals("/")) { //$NON-NLS-1$ contextPath = StringUtils.EMPTY; }// w ww. j a va 2s. com String newUrl; if (StringUtils.isNotBlank(contextPath)) { int pos = url.indexOf(contextPath); newUrl = documentrHost + url.substring(pos + contextPath.length()); } else { UriComponentsBuilder builder; try { builder = UriComponentsBuilder.fromHttpUrl(url); } catch (IllegalArgumentException e) { builder = UriComponentsBuilder.fromUriString(url); } String path = StringUtils.defaultIfBlank(builder.build().getPath(), StringUtils.EMPTY); if (StringUtils.isNotBlank(path)) { int pos = StringUtils.lastIndexOf(url, path); newUrl = documentrHost + url.substring(pos); } else { newUrl = documentrHost; } } return newUrl; }
From source file:net.shibboleth.idp.cas.protocol.ServiceTicketResponse.java
public String getRedirectUrl() { final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(service); if (saml) {/*from ww w . j a va2 s .c om*/ builder.queryParam(SamlParam.SAMLart.name(), ticket); } else { builder.queryParam(ProtocolParam.Ticket.id(), ticket); } return builder.build().toUriString(); }
From source file:cz.cvut.portal.kos.utils.UriBuilder.java
public UriBuilder path(String path) { this.builder = UriComponentsBuilder.fromUriString(path); return this; }
From source file:org.seasar.doma.boot.DomaBootSampleSimpleApplicationTest.java
@Test public void test() { Message message1 = restTemplate.getForObject(UriComponentsBuilder.fromUriString("http://localhost") .port(port).queryParam("text", "hello").build().toUri(), Message.class); assertThat(message1.id, is(1));/*from ww w . ja v a 2s. c om*/ assertThat(message1.text, is("hello")); Message message2 = restTemplate.getForObject(UriComponentsBuilder.fromUriString("http://localhost") .port(port).queryParam("text", "world").build().toUri(), Message.class); assertThat(message2.id, is(2)); assertThat(message2.text, is("world")); { List<Message> messages = restTemplate .exchange(UriComponentsBuilder.fromUriString("http://localhost").port(port).build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference) .getBody(); assertThat(messages.size(), is(2)); assertThat(messages.get(0).id, is(message1.id)); assertThat(messages.get(0).text, is(message1.text)); assertThat(messages.get(1).id, is(message2.id)); assertThat(messages.get(1).text, is(message2.text)); } { List<Message> messages = restTemplate.exchange( UriComponentsBuilder.fromUriString("http://localhost").port(port).queryParam("page", "1") .queryParam("size", "1").build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference).getBody(); assertThat(messages.size(), is(1)); assertThat(messages.get(0).id, is(message2.id)); assertThat(messages.get(0).text, is(message2.text)); } }
From source file:org.kamranzafar.spring.wpapi.client.BaseService.java
protected URI buildUri(String uri, Map<String, String> params) { UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(uri); params.forEach((k, v) -> uriComponentsBuilder.queryParam(k, v)); return uriComponentsBuilder.build().toUri(); }
From source file:net.longfalcon.newsj.service.TmdbService.java
public TmdbFindResults findResultsByImdbId(int imdbId) { try {/* w w w .jav a 2s.c o m*/ String tmdbUrlBase = config.getTmdbApiUrl(); String apiKey = config.getDefaultSite().getTmdbKey(); HttpHeaders httpHeaders = new HttpHeaders(); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder .fromUriString(tmdbUrlBase + "/find/tt" + String.format("%07d", imdbId)) .queryParam("external_source", "imdb_id").queryParam("api_key", apiKey).build(); ResponseEntity<TmdbFindResults> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, TmdbFindResults.class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e.toString(), e); } return null; }
From source file:io.spring.initializr.web.autoconfigure.CloudfoundryEnvironmentPostProcessor.java
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication springApplication) { Map<String, Object> map = new LinkedHashMap<>(); String uri = environment.getProperty("vcap.services.stats-index.credentials.uri"); if (StringUtils.hasText(uri)) { UriComponents uriComponents = UriComponentsBuilder.fromUriString(uri).build(); String userInfo = uriComponents.getUserInfo(); if (StringUtils.hasText(userInfo)) { String[] credentials = userInfo.split(":"); map.put("initializr.stats.elastic.username", credentials[0]); map.put("initializr.stats.elastic.password", credentials[1]); }/* ww w.j a v a 2 s.c o m*/ map.put("initializr.stats.elastic.uri", UriComponentsBuilder.fromUriString(uri).userInfo(null).build().toString()); addOrReplace(environment.getPropertySources(), map); } }
From source file:org.mitre.openid.connect.service.impl.UUIDPairwiseIdentiferService.java
@Override public String getIdentifier(UserInfo userInfo, ClientDetailsEntity client) { String sectorIdentifier = null; if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { UriComponents uri = UriComponentsBuilder.fromUriString(client.getSectorIdentifierUri()).build(); sectorIdentifier = uri.getHost(); // calculate based on the host component only } else {// w w w. j a va2s . c o m Set<String> redirectUris = client.getRedirectUris(); UriComponents uri = UriComponentsBuilder.fromUriString(Iterables.getOnlyElement(redirectUris)).build(); sectorIdentifier = uri.getHost(); // calculate based on the host of the only redirect URI } if (sectorIdentifier != null) { // if there's a sector identifier, use that for the lookup PairwiseIdentifier pairwise = pairwiseIdentifierRepository.getBySectorIdentifier(userInfo.getSub(), sectorIdentifier); if (pairwise == null) { // we don't have an identifier, need to make and save one pairwise = new PairwiseIdentifier(); pairwise.setIdentifier(UUID.randomUUID().toString()); pairwise.setUserSub(userInfo.getSub()); pairwise.setSectorIdentifier(sectorIdentifier); pairwiseIdentifierRepository.save(pairwise); } return pairwise.getIdentifier(); } else { return null; } }
From source file:net.longfalcon.newsj.service.GoogleSearchService.java
public GoogleSearchResponse search(String searchString, String referer) { try {/*from ww w . ja va 2s . c o m*/ if (ValidatorUtil.isNull(referer)) { referer = "http://longfalcon.net"; } String v = "1.0"; String userip = "192.168.0.1"; HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Referer", referer); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder.fromUriString(_SEARCH_URL).queryParam("v", v) .queryParam("q", searchString).queryParam("userip", userip).build(); ResponseEntity<GoogleSearchResponse> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, GoogleSearchResponse.class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e); } return null; }