List of usage examples for org.springframework.web.util UriComponentsBuilder build
public UriComponents build()
From source file:org.haiku.haikudepotserver.pkg.PkgServiceImpl.java
@Override public String createHpkgDownloadUrl(PkgVersion pkgVersion) { return pkgVersion.tryGetHpkgURL().filter(u -> ImmutableSet.of("http", "https").contains(u.getProtocol())) .map(URL::toString).orElseGet(() -> { UriComponentsBuilder builder = UriComponentsBuilder.fromPath(URL_SEGMENT_PKGDOWNLOAD); pkgVersion.appendPathSegments(builder); builder.path("package.hpkg"); return builder.build().toUriString(); });/*w w w . j av a 2 s .co m*/ }
From source file:org.opentestsystem.delivery.logging.LoggingConfigRefresher.java
public void refreshLoggerConfig() { final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); if (StringUtils.isBlank(configUrl) || StringUtils.isBlank(appName)) { addProfiles(context);// www . ja v a2s .c om return; } try { final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(configUrl); builder.pathSegment(appName, profiles, configLabel, String.format("logback-%s.xml", appName)); final URL springConfigURL = builder.build().toUri().toURL(); final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); // Call context.reset() to clear any previous configuration, e.g. default // configuration. For multi-step configuration, omit calling context.reset(). context.reset(); configurator.doConfigure(springConfigURL); addProfiles(context); } catch (JoranException je) { logger.warn("Exception occurred while configuring logback", je); } catch (MalformedURLException e) { logger.warn("Exception occurred while building url to spring-boot config server", e); } }
From source file:org.project.openbaton.nubomedia.paas.core.openshift.AuthenticationManager.java
public String authenticate(String baseURL, String username, String password) throws UnauthorizedException { String res = ""; String authBase = username + ":" + password; String authHeader = "Basic " + Base64.encodeBase64String(authBase.getBytes()); logger.debug("Auth header " + authHeader); String url = baseURL + suffix; HttpHeaders authHeaders = new HttpHeaders(); authHeaders.add("Authorization", authHeader); authHeaders.add("X-CSRF-Token", "1"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) .queryParam("client_id", "openshift-challenging-client").queryParam("response_type", "token"); HttpEntity<String> authEntity = new HttpEntity<>(authHeaders); ResponseEntity<String> response = null; try {/*from w w w. j ava2s . c o m*/ response = template.exchange(builder.build().encode().toUriString(), HttpMethod.GET, authEntity, String.class); } catch (ResourceAccessException e) { return "PaaS Missing"; } catch (HttpClientErrorException e) { throw new UnauthorizedException("Username: " + username + " password: " + password + " are invalid"); } logger.debug("Response " + response.toString()); if (response.getStatusCode().equals(HttpStatus.FOUND)) { URI location = response.getHeaders().getLocation(); logger.debug("Location " + location); res = this.getToken(location.toString()); } else if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) { throw new UnauthorizedException("Username: " + username + " password: " + password + " are invalid"); } return res; }
From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java
private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) { CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor(); if (contributor == null) { logger.debug("Using default CompositeUriComponentsContributor"); contributor = defaultUriComponentsContributor; }// w w w .j av a2s . c o m int paramCount = method.getParameterCount(); int argCount = args.length; if (paramCount != argCount) { throw new IllegalArgumentException("Number of method parameters " + paramCount + " does not match number of argument values " + argCount); } final Map<String, Object> uriVars = new HashMap<>(); for (int i = 0; i < paramCount; i++) { MethodParameter param = new SynthesizingMethodParameter(method, i); param.initParameterNameDiscovery(parameterNameDiscoverer); contributor.contributeMethodArgument(param, args[i], builder, uriVars); } // We may not have all URI var values, expand only what we have return builder.build().expand(new UriComponents.UriTemplateVariables() { @Override public Object getValue(@Nullable String name) { return uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE; } }); }
From source file:ru.org.linux.topic.TagTopicListController.java
private static String buildTagUri(String tag, int section, int offset) { UriComponentsBuilder builder = UriComponentsBuilder.fromUri(TAG_URI_TEMPLATE.expand(tag)); if (section != 0) { builder.queryParam("section", section); }// w w w. ja v a2 s . c o m if (offset != 0) { builder.queryParam("offset", offset); } return builder.build().toUriString(); }
From source file:tds.student.web.backing.DialogFrameBacking.java
private String getContent(long bankKey, long itemKey) { try {/*w w w . ja v a 2s .c o m*/ HttpServletRequest request = HttpContext.getCurrentContext().getRequest(); final UriComponentsBuilder uriBuilder = UriComponentsBuilder .fromHttpUrl(request.getRequestURL().toString().replace("DialogFrame.aspx", "API/DialogFrame.axd/getContent")) .queryParam("language", StudentContext.getLanguage()).queryParam("bankKey", bankKey) .queryParam("itemKey", itemKey); if (isNotBlank(request.getHeader(X_FORWARDED_HOST))) { uriBuilder.host(request.getHeader(X_FORWARDED_HOST)); } if (isNotBlank(request.getHeader(X_FORWARDED_PORT))) { uriBuilder.port(Integer.valueOf(request.getHeader(X_FORWARDED_PORT), 10)); } if (isNotBlank(request.getHeader(X_FORWARDED_PROTOCOL))) { uriBuilder.scheme(request.getHeader(X_FORWARDED_PROTOCOL)); } if (_logger.isDebugEnabled()) { _logger.debug( "REST API URL for getting Dialog Frame Content :: " + uriBuilder.build().toUriString()); } HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML)); HttpEntity<Object> httpEntity = new HttpEntity<Object>(headers); GenericRestAPIClient restApiClient = new GenericRestAPIClient(uriBuilder.build().toUriString()); ResponseEntity<String> responseEntity = restApiClient.exchange(HttpMethod.GET, httpEntity, String.class); if (responseEntity.getStatusCode() != HttpStatus.OK) { throw new RuntimeException("Failed : HTTP error code : " + responseEntity.getStatusCode()); } if (_logger.isDebugEnabled()) { _logger.debug("DialogFrame Content :: " + responseEntity.getBody()); } return responseEntity.getBody().trim(); } catch (Exception e) { _logger.error(e.getMessage(), e); return "Error while getting Content"; } }