当前位置: 首页>>代码示例>>Java>>正文


Java UriComponents.toUri方法代码示例

本文整理汇总了Java中org.springframework.web.util.UriComponents.toUri方法的典型用法代码示例。如果您正苦于以下问题:Java UriComponents.toUri方法的具体用法?Java UriComponents.toUri怎么用?Java UriComponents.toUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.util.UriComponents的用法示例。


在下文中一共展示了UriComponents.toUri方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replace_path

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
@Test
public void replace_path () {

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setPathInfo("/java/examples");

	UriComponents ucb =
	        ServletUriComponentsBuilder
		        .fromRequest(request)
		        .replacePath("/java/exercises")
		        .build()
	            .encode();
	
	URI uri = ucb.toUri();
	
	assertEquals("http://localhost/java/exercises", uri.toString());
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:18,代码来源:BuildURIFromHttpRequest.java

示例2: intercept

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
									ClientHttpRequestExecution execution) throws
																		  IOException {
	HttpRequest protectedResourceRequest = new HttpRequestDecorator(request) {
		@Override
		public URI getURI() {

			String ts = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
			String hash = DigestUtils.sha1Hex(sharedSecret + ts).toLowerCase();

			UriComponentsBuilder builder = UriComponentsBuilder.fromUri(super.getURI());
			builder.queryParam("api_key", apiKey);
			builder.queryParam("ts", ts);
			builder.queryParam("hash", hash);

			// all params are already encoded at this point
			UriComponents uriComponents = builder.build(true);
			logger.debug("requesting SlideShare API: " + uriComponents.toUriString());

			return uriComponents.toUri();
		}
	};

	return execution.execute(protectedResourceRequest, body);
}
 
开发者ID:ttddyy,项目名称:spring-social-slideshare,代码行数:26,代码来源:SlideShareTemplate.java

示例3: toURI

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
@Deprecated
public static URI toURI(String location) {
    try {
        int ssp = location.indexOf("://");
        int at = location.lastIndexOf("@");
        if (ssp != -1 && at != -1) {
            String userInfo = location.substring(ssp + 3, at);
            int slash = location.indexOf("/", at);
            String hostAndPort = (slash != -1 ? location.substring(at + 1, slash) : location.substring(at + 1));
            int colon = hostAndPort.indexOf(":");
            String host = hostAndPort;
            String port = null;
            if (colon != -1) {
                host = hostAndPort.substring(0, colon);
                port = hostAndPort.substring(colon + 1);
            }
            String path = (slash != -1 ? location.substring(slash) : null);
            UriComponentsBuilder builder = UriComponentsBuilder.newInstance()
                    .scheme(location.substring(0, ssp))
                    .userInfo(userInfo)
                    .host(host);
            if (StringUtils.hasText(port)) {
                builder.port(Integer.parseInt(port));
            }
            builder.path(path);
            UriComponents uri = builder.build();
            return uri.toUri();
        } else {
            return ResourceUtils.toURI(location);
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:35,代码来源:RpcUriUtils.java

示例4: create_URI_from_http_request

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
@Test
public void create_URI_from_http_request () {
	
	MockHttpServletRequest request = new MockHttpServletRequest();
	
	UriComponents ucb =
	        ServletUriComponentsBuilder
		        .fromContextPath(request)
		        .path("/examples/java")
		        .build();

	URI uri = ucb.toUri();
	
	assertEquals("http://localhost/examples/java", uri.toString());
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:16,代码来源:BuildURIFromHttpRequest.java


注:本文中的org.springframework.web.util.UriComponents.toUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。