String schemeName = getSchemeName(); if (schemeName == null) { throw new NullPointerException("schemeName"); String transportName = getTransportName(); if (transportName == null) { throw new NullPointerException("transportName"); setAlternateOption(location, options, optionsByName); stripOptionPrefixes(optionsByName); if (getPort(external) == getSchemePort()) { location = modifyURIPort(location, -1); location = modifyURIPort(location, getSchemePort()); if (!transportName.equals(getSchemeName())) { location = modifyURIScheme(location, transportName); parseNamedOptions(location, options, optionsByName); List<T> addresses = newResourceAddresses0(external, location, options); ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(options); newOptions.setOption(ALTERNATE, alternate); setOptions(address, location, newOptions, null); setOptions(address, location, options, null);
protected abstract T newResourceAddress0(String original, String location);
String schemeName = resourceAddressFactorySpi.getSchemeName(); ResourceAddressFactorySpi<?> oldResourceAddressFactorySpi = addressFactories.put(schemeName, resourceAddressFactorySpi); if (oldResourceAddressFactorySpi != null) { String alternateToScheme = resourceAddressFactorySpi.getRootSchemeName(); if (alternateToScheme != null) { Map<String, ResourceAddressFactorySpi<?>> alternates = alternateAddressFactories.get(alternateToScheme); resourceAddressFactorySpi.setResourceAddressFactory(resourceAddressFactory);
protected void stripOptionPrefixes(Map<String, Object> optionsByName) { String transportName = getTransportName(); String protocolName = getProtocolName(); String transportFormat = format("%s.", transportName); List<String> prefixes; if (protocolName != null) { String transportAsProtocolFormat = format("%s[%s].", transportName, protocolName); prefixes = asList(transportFormat, transportAsProtocolFormat); } else { prefixes = Collections.singletonList(transportFormat); } // TODO: scheme-prefixed option names? // strip off current transport prefix for option names for (String prefix : prefixes) { Collection<String> prefixedOptionNames = new HashSet<>(); final Set<Map.Entry<String,Object>> entrySet = optionsByName.entrySet(); for (Map.Entry<String, Object> entry : entrySet) { String optionName = entry.getKey(); if (optionName.startsWith(prefix)) { prefixedOptionNames.add(optionName); } } int prefixLength = prefix.length(); for (String prefixedOptionName : prefixedOptionNames) { Object optionValue = optionsByName.remove(prefixedOptionName); String newOptionName = prefixedOptionName.substring(prefixLength); optionsByName.put(newOptionName, optionValue); } } }
location = modifyURIPort(location, getSchemePort()); String transportName = getTransportName(); if (!transportName.equals(getSchemeName())) { location = modifyURIScheme(location, transportName); List<T> addresses = newResourceAddresses0(external, location, options); ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(options); newOptions.setOption(ALTERNATE, alternate); setOptions(address, location, newOptions, qualifier); setOptions(address, location, options, qualifier); throwNoAddressesToBindError(location);
@Override protected void setOptions(UdpResourceAddress address, ResourceOptions options, Object qualifier) { super.setOptions(address, options, qualifier); // note: no need to propagate bind address and network context, // already handled during address creation address.setOption0(MAXIMUM_OUTBOUND_RATE, options.getOption(MAXIMUM_OUTBOUND_RATE)); address.setOption0(INTERFACE, options.getOption(INTERFACE)); address.setOption0(PADDING_ALIGNMENT, options.getOption(PADDING_ALIGNMENT)); }
private void setOptions(T address, String location, ResourceOptions options, Object qualifier) { // default the transport ResourceAddress transport = options.getOption(TRANSPORT); String transportURI = options.getOption(TRANSPORT_URI); if (transport == null && addressFactory != null) { ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(options); if (transportURI == null) { ResourceFactory factory = getTransportFactory(); if (factory != null) { transportURI = factory.createURI(location); newOptions.setOption(TRANSPORT_URI, transportURI); } } if (transportURI != null) { // TODO: make ResourceOptions hierarchical to provide options here? ResourceOptions transportOptions = ResourceOptions.FACTORY.newResourceOptions(); transportOptions.setOption(NEXT_PROTOCOL, getProtocolName()); URI locationURI = URI.create(location); transportOptions.setOption(TRANSPORTED_URI, locationURI); transport = addressFactory.newResourceAddress(transportURI, transportOptions); } newOptions.setOption(TRANSPORT, transport); options = newOptions; } setOptions(address, options, qualifier); }
protected List<T> newResourceAddresses0(String original, String location, ResourceOptions options) { return singletonList(newResourceAddress0(original, location, options)); }
ResourceFactory factory = getTransportFactory(); if (factory != null) { transportURI = factory.createURI(location); parseNamedOptions0(location, options, optionsByName); String protocolName = getProtocolName(); if (optionsByName == Collections.<String,Object>emptyMap()) { optionsByName = new HashMap<>();
@Override public void setResourceAddressFactory(ResourceAddressFactory addressFactory) { super.setResourceAddressFactory(addressFactory); Map<String, ResourceAddressFactorySpi<?>> alternateAddressFactories = addressFactory.getAlternateAddressFactories(getSchemeName()); alternateAddressFactories = new HashMap<>(alternateAddressFactories); List<ResourceFactory> alternateResourceFactories = new ArrayList<>(); // Create an ordered list of resource factories for the available alternate address factories for(String scheme : WS_ALTERNATE_SCHEMES) { if (alternateAddressFactories.get(scheme) != null) { alternateResourceFactories.add(changeSchemeOnly(scheme)); alternateAddressFactories.remove(scheme); } } // Remaining ones don't have any order for(String scheme : alternateAddressFactories.keySet()) { alternateResourceFactories.add(changeSchemeOnly(scheme)); } this.alternateResourceFactories = Collections.unmodifiableList(alternateResourceFactories); }
@SuppressWarnings("unchecked") protected T newResourceAddressWithAlternate(String location, Map<String, Object> optionsByName, ResourceAddress alternateAddress) { optionsByName.put(ALTERNATE.name(), alternateAddress); return (T) getResourceAddressFactory().newResourceAddress(location, optionsByName); }
@Override protected void setOptions(TcpResourceAddress address, ResourceOptions options, Object qualifier) { super.setOptions(address, options, qualifier); address.setOption0(BIND_ADDRESS, options.getOption(BIND_ADDRESS)); address.setOption0(MAXIMUM_OUTBOUND_RATE, options.getOption(MAXIMUM_OUTBOUND_RATE)); address.setOption0(REALM, options.getOption(REALM)); address.setOption0(LOGIN_CONTEXT_FACTORY, options.getOption(LOGIN_CONTEXT_FACTORY)); }
protected final ResourceAddress resolve(String oldPath, String newPath) { URI addressURI = getResource(); String externalURI = getExternalURI(); boolean newPathDiffersFromOld = !oldPath.equals(newPath); if ( !newPathDiffersFromOld ) { return this; } boolean shouldResolveNewPath = oldPath.equals(addressURI.getPath()); if (!shouldResolveNewPath) { return this; } URI newResourceURI = addressURI.resolve(newPath); String newExternalURI = URIUtils.resolve(externalURI, newPath); ResourceOptions newOptions = FACTORY.newResourceOptions(this); resolve(oldPath, newPath, newOptions); String externalUriToString = newExternalURI; String newResourceUriToString = URIUtils.uriToString(newResourceURI); return factory.newResourceAddress0(externalUriToString, newResourceUriToString, newOptions); }
@Override protected void setOptions(SslResourceAddress address, ResourceOptions options, Object qualifier) { super.setOptions(address, options, qualifier); address.setOption0(CIPHERS, options.getOption(CIPHERS)); address.setOption0(ENCRYPTION_ENABLED, options.getOption(ENCRYPTION_ENABLED)); address.setOption0(WANT_CLIENT_AUTH, options.getOption(WANT_CLIENT_AUTH)); address.setOption0(NEED_CLIENT_AUTH, options.getOption(NEED_CLIENT_AUTH)); address.setOption0(KEY_SELECTOR, options.getOption(KEY_SELECTOR)); address.setOption0(PROTOCOLS, options.getOption(PROTOCOLS)); }
return Collections.singletonList(super.newResourceAddress0(original, location, options)); String newAuthority = format(addressFormat, ipAddress, getPort(location)); location = modifyURIAuthority(location, newAuthority); TcpResourceAddress tcpAddress = super.newResourceAddress0(original, location, options);
@Override protected void setOptions(WsResourceAddress address, ResourceOptions options, Object qualifier) { // WsAcceptor will handle this options.setOption(BIND_ALTERNATE, Boolean.FALSE); super.setOptions(address, options, qualifier); // Mid-level websocket sessions are lightweight in the sense they // pass up decoded message payload and pass down encoded message payload. if ( "x-kaazing-handshake".equals(address.getOption(ResourceAddress.NEXT_PROTOCOL)) ) { options.setOption(WsResourceAddress.LIGHTWEIGHT, Boolean.TRUE); } address.setOption0(CODEC_REQUIRED, options.getOption(CODEC_REQUIRED)); address.setOption0(LIGHTWEIGHT, options.getOption(LIGHTWEIGHT)); address.setOption0(MAX_MESSAGE_SIZE, options.getOption(MAX_MESSAGE_SIZE)); address.setOption0(INACTIVITY_TIMEOUT, options.getOption(INACTIVITY_TIMEOUT)); address.setOption0(SUPPORTED_PROTOCOLS, options.getOption(SUPPORTED_PROTOCOLS)); address.setOption0(REQUIRED_PROTOCOLS, options.getOption(REQUIRED_PROTOCOLS)); } }
return Collections.singletonList(super.newResourceAddress0(original, location, options)); String newAuthority = format(addressFormat, ipAddress, getPort(location)); location = modifyURIAuthority(location, newAuthority); UdpResourceAddress udpAddress = super.newResourceAddress0(original, location, options); udpAddresses.add(udpAddress);
@Override protected void setOptions(HttpResourceAddress address, ResourceOptions options, Object qualifier) { super.setOptions(address, options, qualifier);