本文整理汇总了Java中org.springframework.web.util.UriComponents类的典型用法代码示例。如果您正苦于以下问题:Java UriComponents类的具体用法?Java UriComponents怎么用?Java UriComponents使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UriComponents类属于org.springframework.web.util包,在下文中一共展示了UriComponents类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: confirmEmail
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
/**
* This method activates the e-mail change using a token
* @param token E-mail change activation token
* @param uriComponentsBuilder {@link UriComponentsBuilder}
* @return The ModelAndView for sign in
*/
@PreAuthorize("permitAll()")
@GetMapping(value = "changeEmail/thanks")
public
ModelAndView confirmEmail(
@RequestParam final String token,
final UriComponentsBuilder uriComponentsBuilder
) {
SSLContextHelper.disable();
final RestTemplate restTemplate = new RestTemplate();
final HttpEntity<Object> entity = new HttpEntity<>(new HttpHeaders());
final UriComponents uriComponents
= uriComponentsBuilder.path("/api/v1.0/settings/changeEmail/token/{token}").buildAndExpand(token);
ResponseEntity<Void> response;
try {
response = restTemplate
.exchange(uriComponents.toUri(),
HttpMethod.PUT,
entity,
Void.class);
} catch (HttpClientErrorException e) /* IF 404 */ {
return new ModelAndView("tokenNotFound");
}
/* IF 200 */
return new ModelAndView("redirect:/signIn");
}
示例2: createServiceInfo
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
@Override
public VaultServiceInfo createServiceInfo(String id, String uri) {
UriComponents uriInfo = UriComponentsBuilder.fromUriString(uri).build();
String address = UriComponentsBuilder.newInstance() //
.scheme(uriInfo.getScheme()) //
.host(uriInfo.getHost()) //
.port(uriInfo.getPort()) //
.build().toString();
MultiValueMap<String, String> queryParams = uriInfo.getQueryParams();
String token = queryParams.getFirst("token");
Assert.hasText(token, "Token (token=…) must not be empty");
Map<String, String> backends = getBackends(queryParams, backendPattern);
Map<String, String> sharedBackends = getBackends(queryParams,
sharedBackendPattern);
return new VaultServiceInfo(id, address, token.toCharArray(), backends,
sharedBackends);
}
示例3: info
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
/**
* Return a {@link ResourceSupport} object containing the resources
* served by the Data Flow server.
*
* @return {@code ResourceSupport} object containing the Data Flow server's resources
*/
@RequestMapping("/")
public ResourceSupport info() {
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link(dashboard(""), "dashboard"));
resourceSupport.add(entityLinks.linkToCollectionResource(AppRegistrationResource.class).withRel("apps"));
resourceSupport.add(entityLinks.linkToCollectionResource(AppStatusResource.class).withRel("runtime/apps"));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkForSingleResource(AppStatusResource.class, "{appId}").withRel("runtime/apps/app")));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkFor(AppInstanceStatusResource.class, UriComponents.UriTemplateVariables.SKIP_VALUE).withRel("runtime/apps/instances")));
resourceSupport.add(entityLinks.linkToCollectionResource(ApplicationDefinitionResource.class).withRel("applications/definitions"));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(ApplicationDefinitionResource.class, "{name}").withRel("applications/definitions/definition")));
resourceSupport.add(entityLinks.linkToCollectionResource(ApplicationDeploymentResource.class).withRel("applications/deployments"));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(ApplicationDeploymentResource.class, "{name}").withRel("applications/deployments/deployment")));
String completionStreamTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/stream{?start,detailLevel}");
resourceSupport.add(new Link(completionStreamTemplated).withRel("completions/stream"));
String completionTaskTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/task{?start,detailLevel}");
resourceSupport.add(new Link(completionTaskTemplated).withRel("completions/task"));
return resourceSupport;
}
示例4: applyContributors
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
private UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
CompositeUriComponentsContributor contributor = defaultUriComponentsContributor;
int paramCount = method.getParameterTypes().length;
int argCount = args.length;
if (paramCount != argCount) {
throw new IllegalArgumentException("方法参数量为" + paramCount + " 与真实参数量不匹配,真实参数量为" + argCount);
}
final Map<String, Object> uriVars = new HashMap<>(8);
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(name -> uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE);
}
示例5: createUriComponents
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
/**
* Create Uri Components
* @param path for uri
* @param queryParams for uri
* @param pathParams for uri
* @return UriComponents from supplied path, queryParams and pathParams
*/
public UriComponents createUriComponents(String path, MultiValueMap<String, String> queryParams,
Object... pathParams) {
UriComponents uriComponentsWithOutQueryParams = UriComponentsBuilder.newInstance()
.scheme(config.getScheme())
.host(config.getHost())
.port(config.getPort())
.path(path)
.buildAndExpand(pathParams);
// Have to build UriComponents for query parameters separately as Expand interprets braces in JSON query string
// values as URI template variables to be replaced.
UriComponents uriComponents = UriComponentsBuilder.newInstance()
.uriComponents(uriComponentsWithOutQueryParams)
.queryParams(queryParams)
.build()
.encode();
return uriComponents;
}
示例6: renderMergedOutputModel
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
/**
* Convert model to request parameters and redirect to the given URL.
* @see #appendQueryProperties
* @see #sendRedirect
*/
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws IOException {
String targetUrl = createTargetUrl(model, request);
targetUrl = updateTargetUrl(targetUrl, model, request, response);
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
if (!CollectionUtils.isEmpty(flashMap)) {
UriComponents uriComponents = UriComponentsBuilder.fromUriString(targetUrl).build();
flashMap.setTargetRequestPath(uriComponents.getPath());
flashMap.addTargetRequestParams(uriComponents.getQueryParams());
FlashMapManager flashMapManager = RequestContextUtils.getFlashMapManager(request);
if (flashMapManager == null) {
throw new IllegalStateException("FlashMapManager not found despite output FlashMap having been set");
}
flashMapManager.saveOutputFlashMap(flashMap, request, response);
}
sendRedirect(request, response, targetUrl, this.http10Compatible);
}
示例7: isFlashMapForRequest
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
/**
* Whether the given FlashMap matches the current request.
* Uses the expected request path and query parameters saved in the FlashMap.
*/
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) {
String expectedPath = flashMap.getTargetRequestPath();
if (expectedPath != null) {
String requestUri = getUrlPathHelper().getOriginatingRequestUri(request);
if (!requestUri.equals(expectedPath) && !requestUri.equals(expectedPath + "/")) {
return false;
}
}
UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(request).build();
MultiValueMap<String, String> actualParams = uriComponents.getQueryParams();
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
if (actualValues == null) {
return false;
}
for (String expectedValue : expectedParams.get(expectedName)) {
if (!actualValues.contains(expectedValue)) {
return false;
}
}
}
return true;
}
示例8: initFromRequest
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
/**
* Initialize a builder with a scheme, host,and port (but not path and query).
*/
private static ServletUriComponentsBuilder initFromRequest(HttpServletRequest request) {
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
String scheme = uriComponents.getScheme();
String host = uriComponents.getHost();
int port = uriComponents.getPort();
ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder();
builder.scheme(scheme);
builder.host(host);
if (("http".equals(scheme) && port != 80) || ("https".equals(scheme) && port != 443)) {
builder.port(port);
}
return builder;
}
示例9: fromRequestWithForwardedHostAndPort
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
@Test
public void fromRequestWithForwardedHostAndPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(80);
request.setRequestURI("/mvc-showcase");
request.addHeader("X-Forwarded-Proto", "https");
request.addHeader("X-Forwarded-Host", "84.198.58.199");
request.addHeader("X-Forwarded-Port", "443");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
}
示例10: contextPath
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
private void contextPath(MockHttpServletRequest request, UriComponents uriComponents) {
if (this.contextPath == null) {
List<String> pathSegments = uriComponents.getPathSegments();
if (pathSegments.isEmpty()) {
request.setContextPath("");
}
else {
request.setContextPath("/" + pathSegments.get(0));
}
}
else {
if (!uriComponents.getPath().startsWith(this.contextPath)) {
throw new IllegalArgumentException(uriComponents.getPath() + " should start with contextPath "
+ this.contextPath);
}
request.setContextPath(this.contextPath);
}
}
示例11: params
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
private void params(MockHttpServletRequest request, UriComponents uriComponents) {
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
String name = entry.getKey();
for (String value : entry.getValue()) {
try {
value = (value != null ? URLDecoder.decode(value, "UTF-8") : "");
request.addParameter(name, value);
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
for (NameValuePair param : this.webRequest.getRequestParameters()) {
request.addParameter(param.getName(), param.getValue());
}
}
示例12: requiresAuthenticationAndCreatesValidOAuthTokenRequest
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
@Test
public void requiresAuthenticationAndCreatesValidOAuthTokenRequest() throws Exception {
String redirect = mockMvc.perform(get("/sign/pivotal"))
.andExpect(status().is3xxRedirection())
.andReturn().getResponse().getRedirectedUrl();
UriComponents redirectComponent = UriComponentsBuilder.fromHttpUrl(redirect).build();
assertThat(redirectComponent.getScheme()).isEqualTo("https");
assertThat(redirectComponent.getHost()).isEqualTo("github.com");
MultiValueMap<String, String> params = redirectComponent.getQueryParams();
assertThat(params.getFirst("client_id")).isEqualTo(config.getMain().getClientId());
assertThat(urlDecode(params.getFirst("redirect_uri"))).isEqualTo("http://localhost/login/oauth2/github");
assertThat(params.getFirst("state")).isNotNull();
String[] scopes = urlDecode(params.getFirst("scope")).split(",");
assertThat(scopes).containsOnly("user:email");
}
示例13: adminRequiresAuthenticationAndCreatesValidOAuthTokenRequest
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
@Test
public void adminRequiresAuthenticationAndCreatesValidOAuthTokenRequest() throws Exception {
String redirect = mockMvc.perform(get("/admin/cla/link")).andExpect(status().is3xxRedirection()).andReturn()
.getResponse().getRedirectedUrl();
UriComponents redirectComponent = UriComponentsBuilder.fromHttpUrl(redirect).build();
assertThat(redirectComponent.getScheme()).isEqualTo("https");
assertThat(redirectComponent.getHost()).isEqualTo("github.com");
MultiValueMap<String, String> params = redirectComponent.getQueryParams();
assertThat(params.getFirst("client_id")).isEqualTo(config.getMain().getClientId());
assertThat(urlDecode(params.getFirst("redirect_uri"))).isEqualTo("http://localhost/login/oauth2/github");
assertThat(params.getFirst("state")).isNotNull();
String[] scopes = urlDecode(params.getFirst("scope")).split(",");
assertThat(scopes).containsOnly("user:email", "repo:status", "admin:repo_hook", "admin:org_hook", "read:org");
}
示例14: populateContextPath
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
private void populateContextPath( Model model, HttpServletRequest request )
{
UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
String contextPathString = contextPath.toString();
String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
if ( xForwardedProto != null )
{
if ( contextPathString.contains( "http://" ) && xForwardedProto.equalsIgnoreCase( "https" ) )
{
contextPathString = contextPathString.replace( "http://", "https://" );
}
else if ( contextPathString.contains( "https://" ) && xForwardedProto.equalsIgnoreCase( "http" ) )
{
contextPathString = contextPathString.replace( "https://", "http://" );
}
}
model.addAttribute( "contextPath", contextPathString );
}
示例15: copyQueryParams
import org.springframework.web.util.UriComponents; //导入依赖的package包/类
void copyQueryParams(UriComponents uriComponents, MockHttpServletRequest servletRequest){
try {
if (uriComponents.getQuery() != null) {
String query = UriUtils.decode(uriComponents.getQuery(), UTF_8);
servletRequest.setQueryString(query);
}
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
for (String value : entry.getValue()) {
servletRequest.addParameter(
UriUtils.decode(entry.getKey(), UTF_8),
UriUtils.decode(value, UTF_8));
}
}
}
catch (UnsupportedEncodingException ex) {
// shouldn't happen
}
}