public static String appendURI(String uri, String postfix) { String scheme = URIUtils.getScheme(uri); String authority = URIUtils.getAuthority(uri); String path = URIUtils.getPath(uri); String query = URIUtils.getQuery(uri); String fragment = URIUtils.getFragment(uri); try { return URIUtils.buildURIAsString(scheme, authority, MULTIPLE_SLASHES.matcher(path + postfix).replaceAll(SINGLE_SLASH), query, fragment); } catch (URISyntaxException x) { IllegalArgumentException y = new IllegalArgumentException(); y.initCause(x); throw y; } }
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; }
public static String modifyURIPath(String uri, String newPath) { String path = URIUtils.getPath(uri); if (newPath.equals(path)) { return uri; } String scheme = URIUtils.getScheme(uri); String authority = URIUtils.getAuthority(uri); String query = URIUtils.getQuery(uri); String fragment = URIUtils.getFragment(uri); try { return URIUtils.buildURIAsString(scheme, authority, newPath, query, fragment); } catch (URISyntaxException x) { IllegalArgumentException y = new IllegalArgumentException(); y.initCause(x); throw y; } }
public static String mergeQueryParameters(URI from, String into) throws URISyntaxException { if (into == null) { throw new URISyntaxException("<null>", "Cannot merge into a null URI"); } if (from == null) { return into; } final String fromQuery = from.getQuery(); final String intoQuery = URIUtils.getQuery(into); String query; if (intoQuery == null) { query = from.getQuery(); } else if (fromQuery == null) { query = intoQuery; } else { query = intoQuery; if (fromQuery.length() > 0) { query += '&' + fromQuery; } } return URIUtils.buildURIAsString(URIUtils.getScheme(into), URIUtils.getAuthority(into), URIUtils.getPath(into), query, URIUtils.getFragment(into)); }
private Collection<String> toHttpBalanceOriginURIs(Collection<String> balances) { if (balances == null || balances.isEmpty()) { return balances; } List<String> result = new ArrayList<>(balances.size()); for (String uri : balances) { if (uri != null) { try { final String scheme = getScheme(uri); if ("ws".equals(scheme)) { result.add(buildURIAsString("http", getAuthority(uri), getPath(uri), getQuery(uri), getFragment(uri))); } else if ("wss".equals(scheme)) { result.add(buildURIAsString("https", getAuthority(uri), getPath(uri), getQuery(uri), getFragment(uri))); } else { result.add(uri); } } catch (URISyntaxException e) { if (logger.isDebugEnabled()) { logger.warn(String.format("Cannot translate balanc uri '%s' into a http balance origin.", uri)); } } } } return result; }
public static String ensureTrailingSlash(String uri) { String newPath = URIUtils.getPath(uri); if ( newPath == null || newPath.equals("")) { newPath = "/"; } try { String scheme = URIUtils.getScheme(uri); String authority = URIUtils.getAuthority(uri); String query = URIUtils.getQuery(uri); String fragment = URIUtils.getFragment(uri); return URIUtils.buildURIAsString(scheme, authority, newPath, query, fragment); } catch (URISyntaxException x) { IllegalArgumentException y = new IllegalArgumentException(); y.initCause(x); throw y; } }
try { canonicalURI = buildURIAsString(scheme, getUserInfo(uri), host == null ? null : host.toLowerCase(), getPort(uri), path, getQuery(uri), getFragment(uri)); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URI: " + uri + " in Gateway configuration file", ex);
@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; }
String httpAuthority = getAuthority(uri); String httpPath = getPath(uri); String httpQuery = getQuery(uri); httpURIs.add(buildURIAsString(wsBalancerUriScheme, httpAuthority, httpPath, httpQuery, null));
String httpAuthority = getAuthority(uri); String httpPath = getPath(uri); String httpQuery = getQuery(uri); if (WsProtocol.WS.equals(protocol) || WsProtocol.WSS.equals(protocol)) { httpURIs.add(buildURIAsString(httpScheme, httpAuthority,
if (getPath(allowOriginURI) != null && getQuery(allowOriginURI) != null || getFragment(allowOriginURI) != null) { throw new IllegalArgumentException(
URIUtils.getPort(remoteExternalHttp11), createResolvePath(localExternalHttp11, downstreamSuffix + sessionIdSuffix), URIUtils.getQuery(remoteExternalHttp11), URIUtils.getFragment(remoteExternalHttp11)); URIUtils.getPort(remoteExternalHttp11), createResolvePath(localExternalHttp11, upstreamSuffix + sessionIdSuffix), URIUtils.getQuery(remoteExternalHttp11), URIUtils.getFragment(remoteExternalHttp11));