@Override public String getInternalURI(String externalURI) { String authority = getAuthority(externalURI); String internalAuthority = binds.get(getScheme(externalURI)); if (internalAuthority != null) { if (!internalAuthority.equals(authority)) { try { return buildURIAsString(getScheme(externalURI), internalAuthority, getPath(externalURI), getQuery(externalURI), getFragment(externalURI)); } catch (URISyntaxException e) { // ignore } } return externalURI; } // there's no binding for this URI, return null return null; }
private String resolveURI(String uri) throws URISyntaxException { String schemeName = getScheme(uri); SchemeConfig schemeConfig = supplySchemeConfig(schemeName); int defaultPort = schemeConfig.getDefaultPort(); if (getPort(uri) == -1) { if (defaultPort == -1) { LOGGER.error("Missing port number in URI \"" + uri + "\". You must include an explicit port number in this URI in your gateway configuration file."); throw new IllegalArgumentException("Missing port for URI \"" + uri + "\""); } if (defaultPort != 0) { String host = getHost(uri); String path = getPath(uri); String query = getQuery(uri); String fragment = getFragment(uri); uri = buildURIAsString(schemeName, null, host, defaultPort, path, query, fragment); } } else { if (defaultPort == 0) { LOGGER.error("Port number not allowed in URI \"" + uri + "\". You must remove the port number from this URI in your gateway configuration file."); throw new IllegalArgumentException("Port not allowed in URI \"" + uri + "\""); } } return uri; }
protected ResourceAddress(ResourceAddressFactorySpi factory, URI resourceURI) { this(factory, URIUtils.uriToString(resourceURI), resourceURI); }
public ServiceContext register(String serviceURI, ServiceContext serviceContext) { if (getQuery(serviceURI) != null || getFragment(serviceURI) != null) { throw new IllegalArgumentException("Service URI query and fragment must be null"); } ServiceAuthority serviceAuthority = entries.get(getAuthority(serviceURI)); if (serviceAuthority == null) { serviceAuthority = new ServiceAuthority(); entries.put(getAuthority(serviceURI), serviceAuthority); } ServiceRegistration serviceRegistration = serviceAuthority.register(serviceURI, serviceContext); return (serviceRegistration != null) ? serviceRegistration.getServiceContext() : null; }
if (acceptProperty != null) { acceptProperty = acceptProperty.trim(); acceptProperty = resolveURI(getCanonicalURI(acceptProperty, false)); properties.put("accept", acceptProperty); connectProperty = connectProperty.trim(); properties.remove("connect"); connectURIs.add(resolveURI(getCanonicalURI(connectProperty, true))); wildcardOriginCount++; } else { String allowOriginURI = getCanonicalURI(allowOrigin, false); allowOrigin = allowOriginURI; String allowOriginScheme = getScheme(allowOriginURI); if (getPath(allowOriginURI) != null && getQuery(allowOriginURI) != null || getFragment(allowOriginURI) != null) { throw new IllegalArgumentException( "Cross-site allow-origin must have URI syntax without path, query or fragment"); if (getPort(allowOriginURI) == -1) { String host = getHost(acceptURI); if (host == null || host.isEmpty()) { throw new IllegalArgumentException("Host is required for service \"" + acceptURI + "\"."); String authority = getAuthority(acceptURI); if (authority.indexOf(':') == -1) { SchemeConfig schemeConfig = supplySchemeConfig(getScheme(acceptURI));
String uri; try { uri = getCanonicalURI(member, true); } catch (IllegalArgumentException ex) { GL.error("ha", "Unrecognized {} url {} resulted in exception {}", processing, member, ex); String scheme = getScheme(uri); if ((scheme.equals("tcp")) || scheme.equals("udp") || scheme.equals("aws")) { int port = getPort(uri); if (port == -1) { GL.error("ha", "Port number is missing while processing {} for {}", processing, member); throw new IllegalArgumentException("Invalid port number specified for " + processing + ": " + member); String host = getHost(uri); if (scheme.equals("aws")) { memberIds.add(new MemberId(scheme, host, port, getPath(uri))); } else { GL.error("ha", "Unrecognized scheme {} for {} in {}", getScheme(uri), processing, member); throw new IllegalArgumentException("Invalid scheme " + getScheme(uri) + " in the URL for " + processing + " in " + member);
ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT, remoteBridgeAddress); final ResourceAddress remoteAddress = resourceAddressFactory.newResourceAddress(URIUtils.uriToString(remoteLocation), options, sessionId); URI remoteExternalDownstream = new URI(URIUtils.getScheme(remoteExternalHttp11), URIUtils.getUserInfo(remoteExternalHttp11), URIUtils.getHost(remoteExternalHttp11), URIUtils.getPort(remoteExternalHttp11), createResolvePath(localExternalHttp11, downstreamSuffix + sessionIdSuffix), URIUtils.getQuery(remoteExternalHttp11), URIUtils.getFragment(remoteExternalHttp11)); URI remoteExternalUpstream = new URI(URIUtils.getScheme(remoteExternalHttp11), URIUtils.getUserInfo(remoteExternalHttp11), URIUtils.getHost(remoteExternalHttp11), URIUtils.getPort(remoteExternalHttp11), createResolvePath(localExternalHttp11, upstreamSuffix + sessionIdSuffix), URIUtils.getQuery(remoteExternalHttp11), URIUtils.getFragment(remoteExternalHttp11));
@Override protected HttpResourceAddress newResourceAddress0(String original, String location) { String host = URIUtils.getHost(location); int port = URIUtils.getPort(location); String path = URIUtils.getPath(location); if (host == null) { throw new IllegalArgumentException(format("Missing host in URI: %s", location)); } if (port == -1) { throw new IllegalArgumentException(format("Missing port in URI: %s", location)); } if (path == null || path.length() == 0) { throw new IllegalArgumentException(format("Missing path in URI: %s", location)); } URI uriLocation = URI.create(location); return new HttpResourceAddress(this, original, uriLocation); }
if (getPath(transportURI) != null && getPath(transportURI).endsWith("/;e")) { transportURI = resolve(transportURI, getPath(transportURI). substring(0, getPath(transportURI).length() - "/;e".length())); acceptConstraints = acceptConstraintsByURI.get(modifyURIScheme(transportURI, "ws")); if (acceptConstraints == null && transportFactory.getProtocol(getScheme(transportURI)).isSecure()) { acceptConstraints = acceptConstraintsByURI.get(modifyURIScheme(transportURI, "wss"));
if (!AwsUtils.isDeployedToAWS() || !processing.equals("<connect>")) { GL.error("ha", "Unrecognized scheme {} for {} in {}", getScheme(uri), processing, uri); throw new IllegalStateException("Invalid scheme " + getScheme(uri) + " in the URL for " + processing + " in " + uri); if (clusterPort != getPort(uri)) { GL.error("ha", "Mismatch in port numbers {} and {}", clusterPort, getPort(uri)); throw new IllegalArgumentException("Port numbers on the network interface in <accept> and the member in <connect> " + "do not match"); String scheme = getScheme(uri); if (!scheme.equalsIgnoreCase("aws")) { throw new IllegalStateException("Invalid scheme '" + scheme + String host = getHost(uri); if (!host.equalsIgnoreCase("security-group")) { throw new IllegalStateException("Invalid host '" + host +
ServiceRegistration unregister(URI serviceURI) { ServiceRegistration oldRegistration = entries.remove(serviceURI.getPath()); if (oldRegistration != null) { String oldServiceURI = oldRegistration.getURI(); String oldServicePath = getPath(oldServiceURI); index.remove(oldServicePath); Collections.sort(index); } return oldRegistration; }
String authorityFormat = (bindAddress instanceof Inet6Address) ? FORMAT_IPV6_AUTHORITY : FORMAT_IPV4_AUTHORITY; String newAuthority = format(authorityFormat, newHost, newPort); location = modifyURIAuthority(location, newAuthority); List<TcpResourceAddress> tcpAddresses = new LinkedList<>(); try { String host = getHost(location); Matcher matcher = PATTERN_IPV6_HOST.matcher(host); if (matcher.matches()) { String ipAddress = inetAddress.getHostAddress(); String addressFormat = (inetAddress instanceof Inet6Address) ? FORMAT_IPV6_AUTHORITY : FORMAT_IPV4_AUTHORITY; String newAuthority = format(addressFormat, ipAddress, getPort(location)); location = modifyURIAuthority(location, newAuthority); TcpResourceAddress tcpAddress = super.newResourceAddress0(original, location, options); String host = getHost(location); Pattern pattern = Pattern.compile(URIUtils.NETWORK_INTERFACE_AUTHORITY); Matcher matcher = pattern.matcher(host);
if (!schemeName.equals(getScheme(location))) { throw new IllegalArgumentException(format("Expected scheme \"%s\" for URI: %s", schemeName, location)); if (getPort(external) == getSchemePort()) { location = modifyURIPort(location, -1); if (getPort(location) == -1) { location = modifyURIPort(location, getSchemePort()); location = modifyURIScheme(location, transportName);
@Override protected PipeResourceAddress newResourceAddress0(String original, String location) { // Unlike a normal-looking URI, our custom "pipe://" does not have // host/port/path components. Instead, the authority component // suffices. String pipeName = URIUtils.getAuthority(location); String pathName = URIUtils.getPath(location); if (pipeName == null) { throw new IllegalArgumentException(String.format("URI %s missing pipe name", location)); } if (pathName != null && !pathName.isEmpty()) { throw new IllegalArgumentException(String.format(PIPE_PATH_ERROR_MESSAGE, pipeName, pipeName, pathName)); } URI uriLocation = URI.create(location); return new PipeResourceAddress(this, original, uriLocation); }
if (balanceOrigins != null && !balanceOrigins.isEmpty()) { for (String targetURI : balanceOrigins) { boolean targetIsSecure = "https".equals(URIUtils.getScheme(targetURI)); String targetScheme = URIUtils.getScheme(targetURI); String targetAuthority = HttpUtils.getHostAndPort(URIUtils.getAuthority(targetURI), targetIsSecure); if ("privileged".equals(originScheme) || ((targetScheme.equals(originScheme) && targetAuthority.equals(originAuthority)))) {
private ResourceAddress createApiAddress(ResourceAddress address) { ResourceAddress transport = address.getTransport(); ResourceOptions apiAddressOptions = ResourceOptions.FACTORY.newResourceOptions(transport); // /;api/operation is a terminal endpoint so next protocol should be null apiAddressOptions.setOption(NEXT_PROTOCOL, null); // even if the address has an alternate, do not bind the alternate apiAddressOptions.setOption(BIND_ALTERNATE, Boolean.FALSE); String path = URIUtils.getPath(appendURI(ensureTrailingSlash(address.getExternalURI()), HttpProtocolCompatibilityFilter.API_PATH)); String apiLocation = URIUtils.modifyURIPath(URIUtils.uriToString(transport.getResource()), path); return resourceAddressFactory.newResourceAddress(apiLocation, apiAddressOptions); }
/** * Throw error on specific circumstances: * - no addresses available for binding * - when PreferedIPv4 flag is true and the host IP is IPV6 * @param location * @param tcpAddresses */ private void throwPreferedIPv4StackIPv6AddressError(String location, List<TcpResourceAddress> tcpAddresses) { try { InetAddress address = InetAddress.getByName(URIUtils.getHost(location)); boolean preferIPv4Stack = Boolean.parseBoolean(System.getProperty(JAVA_NET_PREFER_IPV4_STACK)); if (preferIPv4Stack && (address instanceof Inet6Address)) { throw new IllegalArgumentException(format(PREFER_IPV4_STACK_IPV6_ADDRESS_EXCEPTION_FORMATTER, location)); } } catch (UnknownHostException e) { // InetAddress.getByName(hostAddress) throws an exception (hostAddress may have an // unsupported format, e.g. network interface syntax) } }