List of usage examples for org.springframework.web.util UriComponentsBuilder fromUriString
public static UriComponentsBuilder fromUriString(String uri)
From source file:org.openmhealth.shim.googlefit.GoogleFitShim.java
@Override protected String getAuthorizationUrl(UserRedirectRequiredException exception) { final OAuth2ProtectedResourceDetails resource = getResource(); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(exception.getRedirectUri()) .queryParam("state", exception.getStateKey()).queryParam("client_id", resource.getClientId()) .queryParam("response_type", "code").queryParam("access_type", "offline") .queryParam("approval_prompt", "force") .queryParam("scope", StringUtils.collectionToDelimitedString(resource.getScope(), " ")) .queryParam("redirect_uri", getCallbackUrl()); return uriBuilder.build().encode().toUriString(); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Creates a new node with the given key-value pair under the node with the * given key./*w ww . j a v a2s . com*/ * * @param key * the directory node's key * @param value * the value of the created node * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse create(final String key, final String value) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.POST, payload, EtcdResponse.class); }
From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitBusCleaner.java
@SuppressWarnings("unchecked") private List<String> findExchanges(String adminUri, String vhost, String busPrefix, String entity, RestTemplate restTemplate, ExchangeCandidateCallback callback) { List<String> removedExchanges = new ArrayList<>(); URI uri = UriComponentsBuilder.fromUriString(adminUri + "/api").pathSegment("exchanges", "{vhost}") .buildAndExpand(vhost).encode().toUri(); List<Map<String, Object>> exchanges = restTemplate.getForObject(uri, List.class); for (Map<String, Object> exchange : exchanges) { String exchangeName = (String) exchange.get("name"); if (callback.isCandidate(exchangeName)) { uri = UriComponentsBuilder.fromUriString(adminUri + "/api") .pathSegment("exchanges", "{vhost}", "{name}", "bindings", "source") .buildAndExpand(vhost, exchangeName).encode().toUri(); List<Map<String, Object>> bindings = restTemplate.getForObject(uri, List.class); if (bindings.size() == 0) { uri = UriComponentsBuilder.fromUriString(adminUri + "/api") .pathSegment("exchanges", "{vhost}", "{name}", "bindings", "destination") .buildAndExpand(vhost, exchangeName).encode().toUri(); bindings = restTemplate.getForObject(uri, List.class); if (bindings.size() == 0) { removedExchanges.add((String) exchange.get("name")); } else { throw new RabbitAdminException( "Cannot delete exchange " + exchangeName + "; it is a destination: " + bindings); }/*from w ww .j a v a 2 s. c o m*/ } else { throw new RabbitAdminException( "Cannot delete exchange " + exchangeName + "; it has bindings: " + bindings); } } } return removedExchanges; }
From source file:org.openmhealth.shim.withings.WithingsShim.java
URI createWithingsRequestUri(ShimDataRequest shimDataRequest, String userid, WithingsDataType withingsDataType) { MultiValueMap<String, String> dateTimeMap = new LinkedMultiValueMap<>(); if (withingsDataType.usesUnixEpochSecondsDate || isPartnerAccessActivityMeasure(withingsDataType)) { //the partner access endpoints for activity also use epoch secs dateTimeMap.add("startdate", String.valueOf(shimDataRequest.getStartDateTime().toEpochSecond())); dateTimeMap.add("enddate", String.valueOf(shimDataRequest.getEndDateTime().plusDays(1).toEpochSecond())); } else {//from ww w .jav a 2s.co m dateTimeMap.add("startdateymd", shimDataRequest.getStartDateTime().toLocalDate().toString()); dateTimeMap.add("enddateymd", shimDataRequest.getEndDateTime().toLocalDate().toString()); } UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(DATA_URL) .pathSegment(withingsDataType.getEndpoint()); String measureParameter; if (isPartnerAccessActivityMeasure(withingsDataType)) { // partner level access allows greater detail around activity, but uses a different endpoint measureParameter = PARTNER_ACCESS_ACTIVITY_ENDPOINT; } else { measureParameter = withingsDataType.getMeasureParameter(); } uriComponentsBuilder.queryParam("action", measureParameter).queryParam("userid", userid) .queryParams(dateTimeMap); // if it's a body measure if (Objects.equals(withingsDataType.getMeasureParameter(), "getmeas")) { /* The Withings API allows us to query for single body measures, which we take advantage of to reduce unnecessary data transfer. However, since blood pressure is represented as two separate measures, namely a diastolic and a systolic measure, when the measure type is blood pressure we ask for all measures and then filter out the ones we don't care about. */ if (withingsDataType != WithingsDataType.BLOOD_PRESSURE) { WithingsBodyMeasureType measureType = WithingsBodyMeasureType.valueOf(withingsDataType.name()); uriComponentsBuilder.queryParam("meastype", measureType.getMagicNumber()); } uriComponentsBuilder.queryParam("category", 1); //filter out goal datapoints } UriComponents uriComponents = uriComponentsBuilder.build(); return uriComponents.toUri(); }
From source file:com.nec.harvest.controller.SuihController.java
/** * Render page with path variables mapping suih/{unitLevel}/{unitDept}/{deptCode} * // w ww .j a v a 2s. c o m * @param businessDay * Actual business day * @param proGNo * A path variable user's group code * @param unitLevel * A path variable classify's code * @param unitDept * A path variable department level2's code * @param deptCode * A path variable department selected on page view * @param year * A path variable year * @param quarter * A path variable quarter * @return A redirect URL */ @RequestMapping(value = "/{unitLevel}/{unitDept}/{deptCode}", method = RequestMethod.GET) public String render(@SessionAttribute(Constants.SESS_BUSINESS_DAY) Date businessDay, @PathVariable String proGNo, @PathVariable String unitLevel, @PathVariable String unitDept, @PathVariable String deptCode) { logger.info( "Loading profit quarter data by full path [/suih/{unitLevel}/{unitDept}/{deptCode}/{year}/{quarter}]"); // get year and quarter by business day String yearQuater = StringUtils.EMPTY; try { yearQuater = DateUtil.getCurrentQuarter(businessDay); } catch (IllegalArgumentException ex) { logger.warn(ex.getMessage()); } // build path for redirect UriComponents uriComponents = UriComponentsBuilder .fromUriString(Constants.SUIH_PATH + "/{unitLevel}/{unitDept}/{deptCode}/{currentQuarter}").build(); URI uri = uriComponents.expand(proGNo, unitLevel, unitDept, deptCode, yearQuater).encode().toUri(); logger.info( "Redirect to suih screen with params in path [/suih/{unitLevel}/{unitDept}/{deptCode}/{year}/{quarter}]"); return "redirect:" + uri.toString(); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically creates or updates a key-value pair in etcd. * /*from www .j a v a 2 s. c o m*/ * @param key * the key * @param value * the value * @param prevExist * <code>true</code> if the existing node should be updated, * <code>false</code> of the node should be created * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndSwap(final String key, final String value, boolean prevExist) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("prevExist", prevExist); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:com.ge.predix.uaa.token.lib.FastTokenServices.java
protected String getTokenKeyURL(final String issuer) { if (issuer == null) { return null; }// w ww. java 2 s .c o m String regexPattern = "^(http.*)/oauth/token$"; Pattern pattern = Pattern.compile(regexPattern); Matcher matcher = pattern.matcher(issuer); if (!matcher.matches()) { throw new IllegalStateException("FastRemoteTokenService cannot process token with issuer id '" + issuer + "' because it does not match the regular expression '" + regexPattern + "'."); } String issuerPart = matcher.group(1); String scheme = "https"; if (!this.useHttps) { scheme = "http"; } return UriComponentsBuilder.fromUriString(issuerPart).scheme(scheme).pathSegment("token_key").build() .toUriString(); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically creates or updates a key-value pair in etcd. * /*from www.j a va2 s . c om*/ * @param key * the key * @param value * the value * @param ttl * the time-to-live * @param prevExist * <code>true</code> if the existing node should be updated, * <code>false</code> of the node should be created * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndSwap(final String key, final String value, int ttl, boolean prevExist) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("ttl", ttl == -1 ? "" : ttl); builder.queryParam("prevExist", prevExist); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically updates a key-value pair in etcd. * /*ww w .j a va2s .co m*/ * @param key * the key * @param value * the value * @param prevIndex * the modified index of the key * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndSwap(String key, String value, int prevIndex) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("prevIndex", prevIndex); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:org.joyrest.oauth2.endpoint.AuthorizationEndpoint.java
private String append(String base, Map<String, ?> query, Map<String, String> keys, boolean fragment) { UriComponentsBuilder template = UriComponentsBuilder.newInstance(); UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(base); URI redirectUri;/*from w ww . j a v a2 s .c om*/ try { // assume it's encoded to start with (if it came in over the wire) redirectUri = builder.build(true).toUri(); } catch (Exception e) { // ... but allow client registrations to contain hard-coded non-encoded values redirectUri = builder.build().toUri(); builder = UriComponentsBuilder.fromUri(redirectUri); } template.scheme(redirectUri.getScheme()).port(redirectUri.getPort()).host(redirectUri.getHost()) .userInfo(redirectUri.getUserInfo()).path(redirectUri.getPath()); if (fragment) { StringBuilder values = new StringBuilder(); if (redirectUri.getFragment() != null) { String append = redirectUri.getFragment(); values.append(append); } for (String key : query.keySet()) { if (values.length() > 0) { values.append("&"); } String name = key; if (keys != null && keys.containsKey(key)) { name = keys.get(key); } values.append(name + "={" + key + "}"); } if (values.length() > 0) { template.fragment(values.toString()); } UriComponents encoded = template.build().expand(query).encode(); builder.fragment(encoded.getFragment()); } else { for (String key : query.keySet()) { String name = key; if (nonNull(keys) && keys.containsKey(key)) { name = keys.get(key); } template.queryParam(name, "{" + key + "}"); } template.fragment(redirectUri.getFragment()); UriComponents encoded = template.build().expand(query).encode(); builder.query(encoded.getQuery()); } return builder.build().toUriString(); }