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


Java UriComponents.getPort方法代码示例

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


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

示例1: initFromRequest

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
/**
 * Initialize a builder with a scheme, host,and port (but not path and query).
 */
private static ServletUriComponentsBuilder initFromRequest(HttpServletRequest request) {
	HttpRequest httpRequest = new ServletServerHttpRequest(request);
	UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
	String scheme = uriComponents.getScheme();
	String host = uriComponents.getHost();
	int port = uriComponents.getPort();

	ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder();
	builder.scheme(scheme);
	builder.host(host);
	if (("http".equals(scheme) && port != 80) || ("https".equals(scheme) && port != 443)) {
		builder.port(port);
	}
	return builder;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ServletUriComponentsBuilder.java

示例2: obtainUrlLocation

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
private static  String obtainUrlLocation(ServiceInstance instance, UriComponents current, String path, String swaggerHost){
    String managementPath = "";
    if (instance.getMetadata().containsKey("managementPath")) {
        managementPath = instance.getMetadata().get("managementPath");
    }
    String hostUrl;
    if (swaggerHost!=null && swaggerHost.length()>0){
        hostUrl=swaggerHost;
    }else {
        //tries to findout the host
        if (("https".equals(current.getScheme()) && 443 == current.getPort()) || ("http".equals(current.getScheme()) && 80 == current.getPort()) || -1 == current.getPort()) {
            //default ports
            hostUrl = String.format("%s://%s", current.getScheme(), current.getHost());
        } else {
            //custom ports
            hostUrl = String.format("%s://%s:%d", current.getScheme(), current.getHost(), current.getPort());
        }
    }
    return hostUrl + managementPath + path;
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:21,代码来源:EurekaSwaggerResourcesProvider.java

示例3: shouldFilter

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
@Override
public boolean shouldFilter() {
	RequestContext ctx = RequestContext.getCurrentContext();
	boolean isRedirect = ctx.getResponseStatusCode() == 302;
	if (!isRedirect)
		return false;

	boolean hasCorrectLocation = false;

	List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders();
	for (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) {
		if ("Location".equalsIgnoreCase(zuulResponseHeader.first())) {
			HttpServletRequest request = ctx.getRequest();
			String path = urlPathHelper.getPathWithinApplication(request);
			Route route = routeLocator.getMatchingRoute(path);
			UriComponents redirectTo = ServletUriComponentsBuilder
					.fromHttpUrl(zuulResponseHeader.second()).build();
			UriComponents routeLocation = ServletUriComponentsBuilder
					.fromHttpUrl(route.getLocation()).build();

			if (redirectTo.getHost().equalsIgnoreCase(routeLocation.getHost())
					&& redirectTo.getPort() == routeLocation.getPort()) {
				String toLocation = ServletUriComponentsBuilder
						.fromHttpUrl(zuulResponseHeader.second())
						.host(request.getServerName())
						.port(request.getServerPort())
						.replacePath(
								buildRoutePath(route, zuulResponseHeader.second()))
						.build().toUriString();

				ctx.put(REDIRECT_TO_URL, toLocation);
				hasCorrectLocation = true;
				break;
			}
		}
	}

	return hasCorrectLocation;
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:40,代码来源:ProxyRedirectFilter.java

示例4: ports

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
private void ports(UriComponents uriComponents, MockHttpServletRequest request) {
	int serverPort = uriComponents.getPort();
	request.setServerPort(serverPort);
	if (serverPort == -1) {
		int portConnection = this.webRequest.getUrl().getDefaultPort();
		request.setLocalPort(serverPort);
		request.setRemotePort(portConnection);
	}
	else {
		request.setRemotePort(serverPort);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:HtmlUnitRequestBuilder.java

示例5: createHttpServletRequest

import org.springframework.web.util.UriComponents; //导入方法依赖的package包/类
private MockHttpServletRequest createHttpServletRequest(FullHttpRequest fullHttpReq) {
	UriComponents uriComponents = UriComponentsBuilder.fromUriString(fullHttpReq.getUri()).build();

	MockHttpServletRequest servletRequest = new MockHttpServletRequest(this.servletContext);
	servletRequest.setRequestURI(uriComponents.getPath());
	servletRequest.setPathInfo(uriComponents.getPath());
	servletRequest.setMethod(fullHttpReq.getMethod().name());
	servletRequest.setCharacterEncoding(UTF_8);

	if (uriComponents.getScheme() != null) {
		servletRequest.setScheme(uriComponents.getScheme());
	}
	if (uriComponents.getHost() != null) {
		servletRequest.setServerName(uriComponents.getHost());
	}
	if (uriComponents.getPort() != -1) {
		servletRequest.setServerPort(uriComponents.getPort());
	}
	
	copyHttpHeaders(fullHttpReq, servletRequest);
	copyHttpBodyData(fullHttpReq, servletRequest);
	
	copyQueryParams(uriComponents, servletRequest);
	copyToServletCookie(fullHttpReq, servletRequest);
	
	return servletRequest;
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:28,代码来源:ServletNettyChannelHandler.java


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