當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequest.getURI方法代碼示例

本文整理匯總了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);
}
 
開發者ID:codeabovelab,項目名稱:haven-platform,代碼行數:25,代碼來源:HttpAuthInterceptor.java

示例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 + "]");
	}
}
 
開發者ID:reshmik,項目名稱:Zipkin,代碼行數:16,代碼來源:AbstractTraceHttpRequestInterceptor.java

示例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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:68,代碼來源:UriComponentsBuilder.java


注:本文中的org.springframework.http.HttpRequest.getURI方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。