本文整理汇总了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());
}
示例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);
}
示例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);
}
}
示例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());
}