/** * Create a descriptive string for the type of connection that this session has been created on. This is generally just used * in the Command Center. The following is the same as the insides of ResourceAddress.getProtocol(), which is private. NOTE: * we're using BridgeSession.LOCAL_ADDRESS.get(session) to retrieve the address to send to management. */ public static String getSessionTypeName(ResourceAddress address) { String externalURI = address.getExternalURI(); return URIUtils.getScheme(externalURI); }
/** * Return the URIs organized by transport. * <p/> * NOTE: because this relies on gatewayContext, we cannot call it until after the service context has been completely set up * (and in fact not until GatewayContextResolver has constructed, as it doesn't create the DefaultGatewayContext until the * last step in construction. * * @param uris * @return */ private Map<Transport, List<String>> getURIsByTransport(Collection<String> uris) { Map<Transport, List<String>> urisByTransport = new HashMap<>(); // iterate over URIs and group them by transport for (String uri : uris) { String uriScheme = getScheme(uri); Transport transport = transportFactory.getTransportForScheme(uriScheme); List<String> list = urisByTransport.get(transport); if (list == null) { list = new ArrayList<>(); urisByTransport.put(transport, list); } list.add(uri); } return urisByTransport; }
/** * Creates a new resource address for the given location and options * * @param options cannot be null, otherwise NullPointerException is thrown * @return resource address */ public ResourceAddress newResourceAddress(String location, ResourceOptions options, Object qualifier) { Objects.requireNonNull(options, "options cannot be null"); ResourceAddressFactorySpi<?> resourceAddressFactory = findResourceAddressFactory(getScheme(location)); return resourceAddressFactory.newResourceAddress(location, options, qualifier); }
public ResourceAddress newResourceAddress(String location, Map<String, Object> options) { ResourceAddressFactorySpi<?> resourceAddressFactory = findResourceAddressFactory(getScheme(location)); return resourceAddressFactory.newResourceAddress(location, options, ResourceOptions.FACTORY); }
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; } }
@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; }
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)); }
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; } }
String scheme = getScheme(uri); if ((scheme.equals("tcp")) || scheme.equals("udp") || scheme.equals("aws")) { int port = getPort(uri); 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);
final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath); final boolean trailingSlashPath = "/".equals(path); final String scheme = getScheme(uri); final boolean pathlessScheme = "ssl".equals(scheme) || "tcp".equals(scheme) || "pipe".equals(scheme) || "udp".equals(scheme) || "mux".equals(scheme);
@Override public void bind(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { // bind only address with matching scheme URI location = address.getResource(); String schemeName = location.getScheme(); if (!canBind(schemeName)) { throw new IllegalArgumentException(format("Unexpected scheme \"%s\" for URI: %s", schemeName, location)); } // note: ignore BIND_ALTERNATE (used by delegate acceptors) do { BridgeAcceptor bridgeAcceptor = selectWsAcceptor(address); if ( bridgeAcceptor != null ) { bridgeAcceptor.bind(address, handler, initializer); } else { if (logger.isDebugEnabled()) { String format = "No bridge acceptor found for address '%s'. Is the %s transport enabled?"; logger.warn(format(format, address.getExternalURI(), URIUtils.getScheme(address.getExternalURI()))); } } address = address.getOption(ALTERNATE); } while (address != null); }
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; }
@Override protected void setAlternateOption(final String location, ResourceOptions options, Map<String, Object> optionsByName) { String key = options.getOption(HttpResourceAddress.NEXT_PROTOCOL); String scheme = URIUtils.getScheme(location); final boolean secureScheme = "https".equals(scheme) || scheme.contains("+ssl"); if (key != null && secureScheme) { key = key + " secure"; } List<ResourceFactory> resourceFactories = RESOURCE_FACTORIES_BY_KEY.get(key); if (resourceFactories != null && !resourceFactories.isEmpty() && getResourceAddressFactory() != null) { // create alternate addresses HttpResourceAddress alternateAddress = null; for (ResourceFactory resourceFactory: resourceFactories) { alternateAddress = newResourceAddressWithAlternate( resourceFactory.createURI(location), getNewOptionsByName(options, optionsByName), alternateAddress); } // save the alternate chain into this address. options.setOption(ResourceAddress.ALTERNATE, alternateAddress); } }
public ResourceAddress newResourceAddress(final String location, final Map<String, Object> options, final String nextProtocol) { ResourceAddressFactorySpi<?> resourceAddressFactory = findResourceAddressFactory(getScheme(location)); if (nextProtocol != null) { return resourceAddressFactory.newResourceAddress(location, options, new ResourceOptions.Factory() { @Override public ResourceOptions newResourceOptions(ResourceOptions defaults) { ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(defaults); newOptions.setOption(NEXT_PROTOCOL, nextProtocol); return newOptions; } @Override public ResourceOptions newResourceOptions() { ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(); newOptions.setOption(NEXT_PROTOCOL, nextProtocol); return newOptions; } }); } else { return resourceAddressFactory.newResourceAddress(location, options, ResourceOptions.FACTORY); } }
@Override public ConnectFuture connect(ResourceAddress address, final IoHandler connectHandler, final IoSessionInitializer<ConnectFuture> connectSessionInitializer) { String uriScheme = getScheme(address.getExternalURI()); Transport transport = transportFactory.getTransportForScheme(uriScheme); BridgeConnector connector = transport.getConnector(address); return connector.connect(address, connectHandler, new IoSessionInitializer<ConnectFuture>() { @Override public void initializeSession(IoSession session, ConnectFuture future) { sessionInitializer.initializeSession(session, future); if (connectSessionInitializer != null) { connectSessionInitializer.initializeSession(session, future); } } }); }
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; }
List<String> httpURIs = new ArrayList<>(uris.size()); for (String uri : uris) { Protocol protocol = transportFactory.getProtocol(getScheme(uri)); boolean secure = protocol.isSecure();