本文整理汇总了Java中org.springframework.http.HttpRequest.getURI方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.getURI方法的具体用法?Java HttpRequest.getURI怎么用?Java HttpRequest.getURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.getURI方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interceptInner
import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
private void interceptInner(HttpHeaders headers, HttpRequest httpRequest) {
URI uri = httpRequest.getURI();
String host = uri.getHost();
int port = uri.getPort();
String url = host + (port == -1 ? "" : ":" + port);
String name = registryName.get();
log.debug("try to auth request to registry: {}", name);
RegistryService registry = registryRepository.getByName(name);
if (registry == null) {
log.debug("auth : none due to unknown registry \"{}\"", name);
return;
}
RegistryCredentials credentials = registry.getCredentials();
if (credentials == null || !StringUtils.hasText(credentials.getPassword())) {
log.debug("auth : none due to unknown registry \"{}\"", name);
return;
}
String result = format("'{'\"username\":\"{0}\",\"password\":\"{1}\",\"email\":\"[email protected]\",\"serveraddress\":\"{2}\",\"auth\":\"\"'}'",
credentials.getUsername(), credentials.getPassword(), url);
log.debug("auth : {}", result);
String xRegistryAuth = new String(Base64.encode(result.getBytes()));
log.debug("X-Registry-Auth : [{}]", xRegistryAuth);
headers.add("X-Registry-Auth", xRegistryAuth);
}
示例2: publishStartEvent
import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
/**
* Enriches the request with proper headers and publishes
* the client sent event
*/
protected void publishStartEvent(HttpRequest request) {
URI uri = request.getURI();
String spanName = uriScheme(uri) + ":" + uri.getPath();
Span newSpan = this.tracer.createSpan(spanName);
this.spanInjector.inject(newSpan, request);
addRequestTags(request);
newSpan.logEvent(Span.CLIENT_SEND);
if (log.isDebugEnabled()) {
log.debug("Starting new client span [" + newSpan + "]");
}
}
示例3: fromHttpRequest
import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
/**
* Create a new {@code UriComponents} object from the URI associated with
* the given HttpRequest while also overlaying with values from the headers
* "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>, or
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if "Forwarded" is
* not found.
* @param request the source request
* @return the URI components of the URI
* @since 4.1.5
*/
public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
URI uri = request.getURI();
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uri);
String scheme = uri.getScheme();
String host = uri.getHost();
int port = uri.getPort();
String forwardedHeader = request.getHeaders().getFirst("Forwarded");
if (StringUtils.hasText(forwardedHeader)) {
String forwardedToUse = StringUtils.commaDelimitedListToStringArray(forwardedHeader)[0];
Matcher m = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
if (m.find()) {
host = m.group(1).trim();
}
m = FORWARDED_PROTO_PATTERN.matcher(forwardedToUse);
if (m.find()) {
scheme = m.group(1).trim();
}
}
else {
String hostHeader = request.getHeaders().getFirst("X-Forwarded-Host");
if (StringUtils.hasText(hostHeader)) {
String[] hosts = StringUtils.commaDelimitedListToStringArray(hostHeader);
String hostToUse = hosts[0];
if (hostToUse.contains(":")) {
String[] hostAndPort = StringUtils.split(hostToUse, ":");
host = hostAndPort[0];
port = Integer.parseInt(hostAndPort[1]);
}
else {
host = hostToUse;
port = -1;
}
}
String portHeader = request.getHeaders().getFirst("X-Forwarded-Port");
if (StringUtils.hasText(portHeader)) {
String[] ports = StringUtils.commaDelimitedListToStringArray(portHeader);
port = Integer.parseInt(ports[0]);
}
String protocolHeader = request.getHeaders().getFirst("X-Forwarded-Proto");
if (StringUtils.hasText(protocolHeader)) {
String[] protocols = StringUtils.commaDelimitedListToStringArray(protocolHeader);
scheme = protocols[0];
}
}
builder.scheme(scheme);
builder.host(host);
builder.port(null);
if (scheme.equals("http") && port != 80 || scheme.equals("https") && port != 443) {
builder.port(port);
}
return builder;
}