@Override public DefaultUriBuilder port(int port) { this.uriComponentsBuilder.port(port); return this; }
@Override public DefaultUriBuilder port(@Nullable String port) { this.uriComponentsBuilder.port(port); return this; }
@Override public DefaultUriBuilder port(int port) { this.uriComponentsBuilder.port(port); return this; }
@Override public DefaultUriBuilder port(@Nullable String port) { this.uriComponentsBuilder.port(port); return this; }
private void adaptForwardedHost(String hostToUse) { int portSeparatorIdx = hostToUse.lastIndexOf(':'); if (portSeparatorIdx > hostToUse.lastIndexOf(']')) { host(hostToUse.substring(0, portSeparatorIdx)); port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1))); } else { host(hostToUse); port(null); } }
private void adaptForwardedHost(String hostToUse) { int portSeparatorIdx = hostToUse.lastIndexOf(':'); if (portSeparatorIdx > hostToUse.lastIndexOf(']')) { host(hostToUse.substring(0, portSeparatorIdx)); port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1))); } else { host(hostToUse); port(null); } }
/** * Create an instance by parsing the "Origin" header of an HTTP request. * @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454</a> */ public static UriComponentsBuilder fromOriginHeader(String origin) { Matcher matcher = URI_PATTERN.matcher(origin); if (matcher.matches()) { UriComponentsBuilder builder = new UriComponentsBuilder(); String scheme = matcher.group(2); String host = matcher.group(6); String port = matcher.group(8); if (StringUtils.hasLength(scheme)) { builder.scheme(scheme); } builder.host(host); if (StringUtils.hasLength(port)) { builder.port(port); } return builder; } else { throw new IllegalArgumentException("[" + origin + "] is not a valid \"Origin\" header value"); } }
public B uri(URI uri) { this.uri = uri; String scheme = this.uri.getScheme(); Assert.hasText(scheme, "The parameter [" + this.uri + "] format is incorrect, scheme can not be empty"); if (this.uri.getPort() < 0 && scheme.startsWith("http")) { // default known http ports int port = this.uri.getScheme().equals("https") ? 443 : 80; this.uri = UriComponentsBuilder.fromUri(this.uri) .port(port) .build(false) .toUri(); } return getThis(); }
String port = matcher.group(7); if (StringUtils.hasLength(port)) { builder.port(port);
if (matcher.find()) { scheme(matcher.group(1).trim()); port(null); port(null); if (StringUtils.hasText(protocolHeader)) { scheme(StringUtils.tokenizeToStringArray(protocolHeader, ",")[0]); port(null); port(null); port(Integer.parseInt(StringUtils.tokenizeToStringArray(portHeader, ",")[0])); port(null);
builder.host(host); if (StringUtils.hasLength(port)) { builder.port(port);
/** * Create an instance by parsing the "Origin" header of an HTTP request. * @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454</a> */ public static UriComponentsBuilder fromOriginHeader(String origin) { Matcher matcher = URI_PATTERN.matcher(origin); if (matcher.matches()) { UriComponentsBuilder builder = new UriComponentsBuilder(); String scheme = matcher.group(2); String host = matcher.group(6); String port = matcher.group(8); if (StringUtils.hasLength(scheme)) { builder.scheme(scheme); } builder.host(host); if (StringUtils.hasLength(port)) { builder.port(port); } return builder; } else { throw new IllegalArgumentException("[" + origin + "] is not a valid \"Origin\" header value"); } }
String port = matcher.group(7); if (StringUtils.hasLength(port)) { builder.port(port);
protected String getServiceBaseUrl() { String baseUrl = instance.getServiceBaseUrl(); if (!StringUtils.isEmpty(baseUrl)) { return baseUrl; } return UriComponentsBuilder.newInstance() .scheme(getScheme(server.getSsl())) .host(getServiceHost()) .port(getLocalServerPort()) .toUriString(); }
@Test // SPR-12123 public void port() { UriComponents uri1 = fromUriString("http://example.com:8080/bar").build(); UriComponents uri2 = fromUriString("http://example.com/bar").port(8080).build(); UriComponents uri3 = fromUriString("http://example.com/bar").port("{port}").build().expand(8080); UriComponents uri4 = fromUriString("http://example.com/bar").port("808{digit}").build().expand(0); assertEquals(8080, uri1.getPort()); assertEquals("http://example.com:8080/bar", uri1.toUriString()); assertEquals(8080, uri2.getPort()); assertEquals("http://example.com:8080/bar", uri2.toUriString()); assertEquals(8080, uri3.getPort()); assertEquals("http://example.com:8080/bar", uri3.toUriString()); assertEquals(8080, uri4.getPort()); assertEquals("http://example.com:8080/bar", uri4.toUriString()); }
protected String getManagementBaseUrl() { String baseUrl = instance.getManagementBaseUrl(); if (!StringUtils.isEmpty(baseUrl)) { return baseUrl; } if (isManagementPortEqual()) { return this.getServiceUrl(); } Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl(); return UriComponentsBuilder.newInstance() .scheme(getScheme(ssl)) .host(getManagementHost()) .port(getLocalManagementPort()) .toUriString(); }
@Override protected Observable<Void> resumeWithFallback() { if (this.fallbackUri == null) { return super.resumeWithFallback(); } //TODO: copied from RouteToRequestUrlFilter URI uri = exchange.getRequest().getURI(); //TODO: assume always? boolean encoded = containsEncodedParts(uri); URI requestUrl = UriComponentsBuilder.fromUri(uri) .host(null) .port(null) .uri(this.fallbackUri) .build(encoded) .toUri(); exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl); addExceptionDetails(); ServerHttpRequest request = this.exchange.getRequest().mutate().uri(requestUrl).build(); ServerWebExchange mutated = exchange.mutate().request(request).build(); DispatcherHandler dispatcherHandler = HystrixGatewayFilterFactory.this.dispatcherHandler.getIfAvailable(); return RxReactiveStreams.toObservable(dispatcherHandler.handle(mutated)); }
@Override protected void copyToUriComponentsBuilder(UriComponentsBuilder builder) { if (getScheme() != null) { builder.scheme(getScheme()); } if (getUserInfo() != null) { builder.userInfo(getUserInfo()); } if (getHost() != null) { builder.host(getHost()); } // Avoid parsing the port, may have URI variable.. if (this.port != null) { builder.port(this.port); } this.path.copyToUriComponentsBuilder(builder); if (!getQueryParams().isEmpty()) { builder.queryParams(getQueryParams()); } if (getFragment() != null) { builder.fragment(getFragment()); } }
@Override protected String getManagementBaseUrl() { String baseUrl = instance.getManagementBaseUrl(); if (!StringUtils.isEmpty(baseUrl)) { return baseUrl; } if (isManagementPortEqual()) { return UriComponentsBuilder.fromHttpUrl(getServiceUrl()) .path("/") .path(getDispatcherServletPrefix()) .path(getManagementContextPath()) .toUriString(); } Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl(); return UriComponentsBuilder.newInstance() .scheme(getScheme(ssl)) .host(getManagementHost()) .port(getLocalManagementPort()) .path(getManagementContextPath()) .toUriString(); }
@Override protected void copyToUriComponentsBuilder(UriComponentsBuilder builder) { if (getScheme() != null) { builder.scheme(getScheme()); } if (getUserInfo() != null) { builder.userInfo(getUserInfo()); } if (getHost() != null) { builder.host(getHost()); } // Avoid parsing the port, may have URI variable.. if (this.port != null) { builder.port(this.port); } this.path.copyToUriComponentsBuilder(builder); if (!getQueryParams().isEmpty()) { builder.queryParams(getQueryParams()); } if (getFragment() != null) { builder.fragment(getFragment()); } }