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; }
ServiceRegistration register(String serviceURI, ServiceContext serviceContext) { String servicePath = getPath(serviceURI); ServiceRegistration oldRegistration = entries.put(servicePath, new ServiceRegistration(serviceURI, serviceContext)); if (oldRegistration != null) { String oldServiceURI = oldRegistration.getURI(); String oldServicePath = getPath(oldServiceURI); index.remove(oldServicePath); } index.add(servicePath); Collections.sort(index); return oldRegistration; }
@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); }
@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); }
private void checkForTrailingSlashes(ServiceContext serviceContext) { Collection<String> acceptURIs = serviceContext.getAccepts(); Collection<String> connectURIs = serviceContext.getConnects(); assert acceptURIs.size() == 1; assert connectURIs.size() == 1; String acceptURI = acceptURIs.iterator().next(); String connectURI = connectURIs.iterator().next(); String acceptPath = URIUtils.getPath(acceptURI); String connectPath = URIUtils.getPath(connectURI); boolean acceptPathIsSlash = acceptPath.endsWith("/"); boolean connectPathIsSlash = connectPath.endsWith("/"); if (!acceptPathIsSlash) { String msg = String.format("The path %s of accept URI %s for service %s needs to end with /", acceptPath, acceptURI, serviceContext.getServiceName()); throw new IllegalArgumentException(msg); } if (!connectPathIsSlash) { String msg = String.format("The path %s of connect URI %s for service %s needs to end with /", connectPath, connectURI, serviceContext.getServiceName()); throw new IllegalArgumentException(msg); } }
private String createResolvePath(String httpUri, final String suffixWithLeadingSlash) { return URIUtils.getPath(appendURI(ensureTrailingSlash(httpUri),suffixWithLeadingSlash)); }
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; } }
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 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 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; } }
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)); }
if (uri != null) { String host = getHost(uri); String path = getPath(uri); final boolean emptyPath = "".equals(path); final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath);
@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 wsBalancerUriScheme = secure ? scheme+"+ssl" : scheme; String httpAuthority = getAuthority(uri); String httpPath = getPath(uri); String httpQuery = getQuery(uri); httpURIs.add(buildURIAsString(wsBalancerUriScheme, httpAuthority, httpPath, httpQuery, null));
break; String balanceePath = getPath(selectedBalanceeURI); String requestPath = requestURI.getPath(); int emIndex = (requestPath != null) ? requestPath.indexOf(WsebAcceptor.EMULATED_SUFFIX) : -1;
private ResourceAddress createApiHttpxeAddress(ResourceAddress httpxeTransport) { String path = URIUtils.getPath(appendURI(ensureTrailingSlash(httpxeTransport.getExternalURI()), HttpProtocolCompatibilityFilter.API_PATH)); httpxeTransport = httpxeTransport.resolve(path); String httpxeLocation = modifyURIPath(httpxeTransport.getExternalURI(), path); ResourceOptions httpxeOptions = ResourceOptions.FACTORY.newResourceOptions(httpxeTransport); httpxeOptions.setOption(NEXT_PROTOCOL, null); // terminal endpoint, so next protocol null return resourceAddressFactory.newResourceAddress(httpxeLocation, httpxeOptions); }
private ResourceAddress createApiHttpAddress(ResourceAddress httpTransport) { String path = URIUtils.getPath(appendURI(ensureTrailingSlash(httpTransport.getExternalURI()), HttpProtocolCompatibilityFilter.API_PATH)); String httpLocation = modifyURIPath(httpTransport.getExternalURI(), path); ResourceOptions httpOptions = ResourceOptions.FACTORY.newResourceOptions(httpTransport); httpOptions.setOption(NEXT_PROTOCOL, null); // terminal endpoint, so next protocol null httpOptions.setOption(ALTERNATE, null); return resourceAddressFactory.newResourceAddress(httpLocation, httpOptions); }
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); }
String uri = appendURI(ensureTrailingSlash(httpxeAddress.getExternalURI()), CREATE_SUFFIX); String query = URIUtils.getQuery(uri); String pathAndQuery = URIUtils.getPath(uri); if (query != null) { pathAndQuery += "?" + URIUtils.getQuery(uri);