Java Code Examples for org.springframework.web.util.UriComponentsBuilder#toUriString()
The following examples show how to use
org.springframework.web.util.UriComponentsBuilder#toUriString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HLSController.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
private String createStreamUrl(HttpServletRequest request, Player player, int id, long offset, long duration, Pair<Integer, Dimension> bitRate) { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getContextPath(request) + "ext/stream/stream.ts"); builder.queryParam("id", id); builder.queryParam("hls", "true"); builder.queryParam("timeOffset", offset); builder.queryParam("player", player.getId()); builder.queryParam("duration", duration); if (bitRate != null) { builder.queryParam("maxBitRate", bitRate.getLeft()); Dimension dimension = bitRate.getRight(); if (dimension != null) { builder.queryParam("size", dimension.width); builder.queryParam("x", dimension.height); } } jwtSecurityService.addJWTToken(player.getUsername(), builder); return builder.toUriString(); }
Example 2
Source File: CustomContentDirectory.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
protected Res createResourceForSong(MediaFile song) { Player player = playerService.getGuestPlayer(null); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getBaseUrl() + "/ext/stream") .queryParam("id", song.getId()) .queryParam("player", player.getId()); if (song.isVideo()) { builder.queryParam("format", TranscodingService.FORMAT_RAW); } jwtSecurityService.addJWTToken(User.USERNAME_ANONYMOUS, builder); String url = builder.toUriString(); String suffix = song.isVideo() ? FilenameUtils.getExtension(song.getPath()) : transcodingService.getSuffix(player, song, null); String mimeTypeString = StringUtil.getMimeType(suffix); MimeType mimeType = mimeTypeString == null ? null : MimeType.valueOf(mimeTypeString); Res res = new Res(mimeType, null, url); res.setDuration(formatDuration(song.getDuration())); return res; }
Example 3
Source File: WebController.java From Spring-5.0-Projects with MIT License | 6 votes |
@GetMapping("/customAuth") public String authorizeUser(Model model,@Value("${custom.auth.authorization-uri}") String authorizationUri, @Value("${custom.auth.client-id}") String clientId, @Value("${custom.auth.client-secret}") String clientSecret, @Value("${custom.auth.grant-type}") String grantType, @Value("${custom.auth.response-type}") String responseType) { UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(authorizationUri) .queryParam("username", clientId) .queryParam("password", clientSecret) .queryParam("grant_type", grantType) .queryParam("response_type", responseType) .queryParam("client_id", clientId); return "redirect:"+uriBuilder.toUriString(); }
Example 4
Source File: HLSController.java From airsonic with GNU General Public License v3.0 | 6 votes |
private String createStreamUrl(HttpServletRequest request, Player player, int id, int offset, int duration, Pair<Integer, Dimension> bitRate) { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getContextPath(request) + "ext/stream/stream.ts"); builder.queryParam("id", id); builder.queryParam("hls", "true"); builder.queryParam("timeOffset", offset); builder.queryParam("player", player.getId()); builder.queryParam("duration", duration); if (bitRate != null) { builder.queryParam("maxBitRate", bitRate.getLeft()); Dimension dimension = bitRate.getRight(); if (dimension != null) { builder.queryParam("size", dimension.width); builder.queryParam("x", dimension.height); } } jwtSecurityService.addJWTToken(builder); return builder.toUriString(); }
Example 5
Source File: CustomContentDirectory.java From airsonic with GNU General Public License v3.0 | 6 votes |
protected Res createResourceForSong(MediaFile song) { Player player = playerService.getGuestPlayer(null); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getBaseUrl() + "/ext/stream") .queryParam("id", song.getId()) .queryParam("player", player.getId()); if (song.isVideo()) { builder.queryParam("format", TranscodingService.FORMAT_RAW); } jwtSecurityService.addJWTToken(builder); String url = builder.toUriString(); String suffix = song.isVideo() ? FilenameUtils.getExtension(song.getPath()) : transcodingService.getSuffix(player, song, null); String mimeTypeString = StringUtil.getMimeType(suffix); MimeType mimeType = mimeTypeString == null ? null : MimeType.valueOf(mimeTypeString); Res res = new Res(mimeType, null, url); res.setDuration(formatDuration(song.getDurationSeconds())); return res; }
Example 6
Source File: DockerServiceImpl.java From haven-platform with Apache License 2.0 | 6 votes |
private <T> T postOrNullAction(UriComponentsBuilder ub, Object cmd, Class<T> responseType) { String url = ub.toUriString(); try { ResponseEntity<T> entity = getSlow(() -> { HttpEntity<?> req = null; if(cmd != null) { req = wrapEntity(cmd); } return restTemplate.postForEntity(url, req, responseType); }); return entity.getBody(); } catch (HttpStatusCodeException e) { log.warn("Failed to execute POST on {}, due to {}", url, formatHttpException(e)); if(e.getStatusCode().is4xxClientError()) { return null; } throw e; } }
Example 7
Source File: BirtStatisticsServiceImpl.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
@Override public String generateUrlWithParamsForInternalAccess(Map<String, Object> parameters) { String birtUrl = getBirtUrl(true); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(birtUrl); parameters.forEach(uriBuilder::queryParam); return uriBuilder.toUriString(); }
Example 8
Source File: BirtStatisticsServiceImpl.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
@Override public String generateUrlWithParamsForExternalAccess(Map<String, Object> parameters) { String birtUrl = getBirtUrl(false); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(birtUrl); parameters.forEach(uriBuilder::queryParam); return uriBuilder.toUriString(); }
Example 9
Source File: LoginUrlAuthenticationEntryPoint.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Override protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String url = super.buildRedirectUrlToLoginPage(request, response, authException); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url); String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO); if (scheme != null && !scheme.isEmpty()) { builder.scheme(scheme); } String host = request.getHeader(HttpHeaders.X_FORWARDED_HOST); if (host != null && !host.isEmpty()) { if (host.contains(":")) { // Forwarded host contains both host and port String [] parts = host.split(":"); builder.host(parts[0]); builder.port(parts[1]); } else { builder.host(host); } } // handle forwarded path String forwardedPath = request.getHeader(X_FORWARDED_PREFIX); if (forwardedPath != null && !forwardedPath.isEmpty()) { String path = builder.build().getPath(); // remove trailing slash forwardedPath = forwardedPath.substring(0, forwardedPath.length() - (forwardedPath.endsWith("/") ? 1 : 0)); builder.replacePath(forwardedPath + path); } return builder.toUriString(); }
Example 10
Source File: AviApi.java From sdk with Apache License 2.0 | 5 votes |
public String buildApiParams(String path, Map<String, String> params) { UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(restTemplate.getUriTemplateHandler().expand("/").toString().concat(path)); if (null != params) { for(String key: params.keySet()) { uriBuilder.queryParam(key, params.get(key)); } } return uriBuilder.toUriString(); }
Example 11
Source File: AssetClient.java From mojito with Apache License 2.0 | 5 votes |
/** * Deletes multiple {@link Asset} by the list of {@link Asset#id} of a given branch * @param assetIds * @param branchId */ public PollableTask deleteAssetsInBranch(Set<Long> assetIds, Long branchId) { logger.debug("Deleting assets by asset ids = {} or branch id: {}", assetIds.toString(), branchId); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(getBasePath() + "/assets"); if (branchId != null) { uriComponentsBuilder.queryParam("branchId", branchId).build(); } HttpEntity<Set<Long>> httpEntity = new HttpEntity<>(assetIds); String uriString = uriComponentsBuilder.toUriString(); return authenticatedRestTemplate.deleteForObject(uriString, httpEntity, PollableTask.class); }
Example 12
Source File: NFSService.java From modeldb with Apache License 2.0 | 5 votes |
private String getUrl(String artifactPath, String endpoint, String scheme) { String host = ModelDBAuthInterceptor.METADATA_INFO .get() .get(Metadata.Key.of("x-forwarded-host", Metadata.ASCII_STRING_MARSHALLER)); if (host == null || host.isEmpty() || app.getPickNFSHostFromConfig()) { host = app.getNfsServerHost(); } String[] hostArr = host.split(":"); String finalHost = hostArr[0]; UriComponentsBuilder uriComponentsBuilder = ServletUriComponentsBuilder.newInstance() .scheme(scheme) .host(finalHost) .path(endpoint) .queryParam("artifact_path", artifactPath); if (hostArr.length > 1) { String finalPort = hostArr[1]; uriComponentsBuilder.port(finalPort); } return uriComponentsBuilder.toUriString(); }
Example 13
Source File: DashboardMenu.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
private static String generateLogoutUrl() { final UriComponentsBuilder logout = ServletUriComponentsBuilder.fromCurrentContextPath().path(LOGOUT_BASE); UserDetailsFormatter.getCurrentTenant().ifPresent(tenant -> logout.queryParam("login", UriComponentsBuilder.fromPath(LOGIN_BASE).queryParam("tenant", tenant).build().toUriString())); return logout.toUriString(); }
Example 14
Source File: DiscoveryRegistrationBean.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
private LightminClientApplication getLightminClientApplication(final ServiceInstance serviceInstance) { final URI uri = serviceInstance.getUri(); final UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder .fromUri(uri) .path(this.getContextPath(serviceInstance)) .path("/api/lightminclientapplications"); final String uriString = uriComponentsBuilder.toUriString(); final ResponseEntity<LightminClientApplication> response = this.restTemplate.getForEntity(uriString, LightminClientApplication.class); ResponseUtil.checkHttpOk(response); return response.getBody(); }
Example 15
Source File: PayPalManager.java From alf.io with GNU General Public License v3.0 | 4 votes |
private String createCheckoutRequest(PaymentSpecification spec) throws Exception { TicketReservation reservation = ticketReservationRepository.findReservationById(spec.getReservationId()); String eventName = spec.getEvent().getShortName(); String baseUrl = StringUtils.removeEnd(configurationManager.getFor(ConfigurationKeys.BASE_URL, ConfigurationLevel.event(spec.getEvent())).getRequiredValue(), "/"); String bookUrl = baseUrl+"/event/" + eventName + "/reservation/" + spec.getReservationId() + "/payment/paypal/" + URL_PLACEHOLDER; String hmac = computeHMAC(spec.getCustomerName(), spec.getEmail(), spec.getBillingAddress(), spec.getEvent()); UriComponentsBuilder bookUrlBuilder = UriComponentsBuilder.fromUriString(bookUrl) .queryParam("hmac", hmac); String finalUrl = bookUrlBuilder.toUriString(); ApplicationContext applicationContext = new ApplicationContext() .landingPage("BILLING") .cancelUrl(finalUrl.replace(URL_PLACEHOLDER, "cancel")) .returnUrl(finalUrl.replace(URL_PLACEHOLDER, "confirm")) .userAction("CONTINUE") .shippingPreference("NO_SHIPPING"); OrderRequest orderRequest = new OrderRequest() .applicationContext(applicationContext) .checkoutPaymentIntent("CAPTURE") .purchaseUnits(List.of(new PurchaseUnitRequest().amountWithBreakdown(new AmountWithBreakdown().currencyCode(spec.getCurrencyCode()).value(spec.getOrderSummary().getTotalPrice())))); OrdersCreateRequest request = new OrdersCreateRequest().requestBody(orderRequest); request.header("prefer","return=representation"); request.header("PayPal-Request-Id", reservation.getId()); HttpResponse<Order> response = getClient(spec.getEvent()).execute(request); if(HttpUtils.statusCodeIsSuccessful(response.statusCode())) { Order order = response.result(); var status = order.status(); if("APPROVED".equals(status) || "COMPLETED".equals(status)) { if("APPROVED".equals(status)) { saveToken(reservation.getId(), spec.getEvent(), new PayPalToken(order.payer().payerId(), order.id(), hmac)); } return "/event/"+spec.getEvent().getShortName()+"/reservation/"+spec.getReservationId(); } else if("CREATED".equals(status)) { //add 15 minutes of validity in case the paypal flow is slow ticketReservationRepository.updateValidity(spec.getReservationId(), DateUtils.addMinutes(reservation.getValidity(), 15)); return order.links().stream().filter(l -> l.rel().equals("approve")).map(LinkDescription::href).findFirst().orElseThrow(); } } throw new IllegalStateException(); }
Example 16
Source File: BaseClient.java From mojito with Apache License 2.0 | 3 votes |
/** * Construct a base path for a resource and subresources matching the {@param resourceId} * <p/> * Example 1: * <pre class="code"> * getBasePathForResource(repoId, "repositoryLocales"); * </pre> * will print: <blockquote>{@code /api/entityName/repoId/repositoryLocales/}</blockquote> * Example 2: * <pre class="code"> * getBasePathForResource(repoId, "repositoryLocales", 1); * </pre> * will print: <blockquote>{@code /api/entityName/repoId/repositoryLocales/1}</blockquote> * * @param resourceId The resourceId of the resource * @param pathSegments An undefined number of path segments to concatenate to the URI * @return */ protected String getBasePathForResource(Long resourceId, Object... pathSegments) { UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath(getBasePathForResource(resourceId)); if (!ObjectUtils.isEmpty(pathSegments)) { for (Object pathSegment : pathSegments) { uriBuilder.pathSegment(pathSegment.toString()); } } return uriBuilder.toUriString(); }