當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。