private ResourceAddress getResourcesAddress(HttpBinding newHttpBinding) { ResourceAddress bindAddress = newHttpBinding.bindAddress(); String location = bindAddress.getExternalURI(); String resourcesURI = URIUtils.resolve(location, "/;resource"); ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT_URI, bindAddress.getOption(TRANSPORT_URI)); options.setOption(TRANSPORT, bindAddress.getOption(TRANSPORT)); options.setOption(TEMP_DIRECTORY, bindAddress.getOption(TEMP_DIRECTORY)); options.setOption(NEXT_PROTOCOL, bindAddress.getOption(NEXT_PROTOCOL)); options.setOption(ORIGIN_SECURITY, bindAddress.getOption(ORIGIN_SECURITY)); options.setOption(GATEWAY_ORIGIN_SECURITY, bindAddress.getOption(GATEWAY_ORIGIN_SECURITY)); options.setOption(BALANCE_ORIGINS, bindAddress.getOption(BALANCE_ORIGINS)); return addressFactory.newResourceAddress(resourcesURI, options); }
String myTransportName = format("%s.", getResource().getScheme()); String transportProtocolName = getTransport() != null ? getTransport().getOption(NEXT_PROTOCOL) : null; List<String> prefixes; if (transportProtocolName != null) { String transportAsProtocolFormat = format("%s[%s].", getResource().getScheme(), transportProtocolName); prefixes = asList(myTransportName, transportAsProtocolFormat); } else { result = getTransport().findTransport(query); if (getTransport() == null) { return null; } else { return getTransport().findTransport(query);
@Override @SuppressWarnings("unchecked") protected <V> V getOption0(ResourceOption<V> option) { if (option instanceof TcpResourceOption) { TcpResourceOption tcpOption = (TcpResourceOption) option; switch (tcpOption.kind) { case BIND_ADDRESS: return (V) bindAddress; case MAXIMUM_OUTBOUND_RATE: return (V) valueOf(maximumOutboundRate); case REALM: return (V) realm; case LOGIN_CONTEXT_FACTORY: return (V) loginContextFactory; } } return super.getOption0(option); }
private IoHandler selectHandler(ResourceAddress address) { ResourceAddress httpTransport = address.getTransport(); String httpNextProtocol = httpTransport.getOption(NEXT_PROTOCOL); if ( PROTOCOL_NAME_WEB_SOCKET_RFC6455.equals(httpNextProtocol)) { return wsnHttpRFC6455BridgeHandler; } else if ( PROTOCOL_NAME_WEB_SOCKET_DRAFT.equals(httpNextProtocol)) { return wsnHttpDelegatingBridgeHandler; } return null; }
public final ResourceAddress resolve(String newPath) { if ( newPath == null ) { throw new NullPointerException(newPath); } URI addressURI = getResource(); return resolve(addressURI.getPath(), newPath); }
private ResourceAddress createWsrCreateAddress(ResourceAddress address) { ResourceAddress wsrTransportAddress = address.getTransport(); URI wsrTransportBindURI = wsrTransportAddress.getResource(); return wsrTransportAddress.resolve(createResolvePath(wsrTransportBindURI, CREATE_SUFFIX)); }
@Override protected <T extends IoFuture> void bindInternal(final ResourceAddress address, IoHandler handler, final BridgeSessionInitializer<T> initializer) { if (logger.isTraceEnabled()) { logger.trace(format("binding: '%s' %s", address.getExternalURI(), address.getOption(NEXT_PROTOCOL))); } // // Bind the transport of the address. // final ResourceAddress transportAddress = address.getTransport(); final URI transportURI = transportAddress.getResource(); final Protocol transportProtocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportURI.getScheme()); final BridgeSessionInitializer<T> sessionInitializer = (initializer != null) ? initializer.getParentInitializer(transportProtocol) : null; BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transportAddress); acceptor.bind(transportAddress, bridgeHandler, sessionInitializer); }
URI remoteLocation = ensureTrailingSlash(modifyURIScheme(remoteBridgeAddress.getResource(), "wse")); ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT, remoteBridgeAddress); long configuredInactivityTimeout = localAddress.getOption(INACTIVITY_TIMEOUT); final long inactivityTimeout = pingEnabled ? configuredInactivityTimeout : DISABLE_INACTIVITY_TIMEOUT; ResourceAddress remoteHttp11Address = remoteAddress.findTransport("http[http/1.1]"); ResourceAddress localHttp11Address = localAddress.findTransport("http[http/1.1]"); if (remoteHttp11Address == null || localHttp11Address == null) { throw new RuntimeException("Cannot construct up- and down- stream urls: no http/1.1 transport found."); String remoteExternalHttp11 = remoteHttp11Address.getExternalURI(); String localExternalHttp11 = localHttp11Address.getExternalURI(); final ResourceAddress httpAddress = localAddress.getTransport(); final ResourceAddress httpxeAddress = localAddress.getTransport().getOption(ALTERNATE); ResourceAddress localDownstream = httpBaseAddress.resolve(createResolvePath(httpBaseAddress.getResource(), downstreamSuffix + sessionIdSuffix)); logger.trace("Binding "+localDownstream.getTransport()+" to downstreamHandler"); httpBaseAddress = httpAddressNoSecurity(httpAddress, httpxeBaseAddress, upstreamResolver); ResourceAddress localUpstream = httpBaseAddress.resolve(createResolvePath(httpBaseAddress.getResource(), upstreamSuffix + sessionIdSuffix)); logger.trace("Binding "+localUpstream.getTransport()+" to upstreamHandler");
@Override public int compare(ResourceAddress addr1, ResourceAddress addr2) { URI location1 = addr1.getResource(); URI location2 = addr2.getResource(); assert (location1 != null); assert (location2 != null); return (location1.compareTo(location2)); }
@Override protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { if (logger.isTraceEnabled()) { logger.trace(format("unbinding: '%s' %s", address.getExternalURI(), address.getOption(NEXT_PROTOCOL))); } ResourceAddress transport = address.getTransport(); BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transport); return acceptor.unbind(transport); }
@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 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); }
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); }
static boolean elevateEmulatedRequestRequired(IoSession session) { if ("httpxe/1.1".equals(BridgeSession.LOCAL_ADDRESS.get(session).getOption(NEXT_PROTOCOL))) { DefaultHttpSession httpSession = (DefaultHttpSession) session; // XDR needs to explicitly envelope the request, so we must not treat this as requiring implicit elevation return !isExplicitEnvelopedContentType(httpSession) && isLegacyClient(httpSession) && (isEmulatedWebSocketRequest(httpSession) || isRevalidateWebSocketRequest(httpSession) || isApiRequest(httpSession)); } return false; }
/** * 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); }
private ResourceAddress createWsrRtmpAddress(ResourceAddress address) { // wsr[wsr/1.0] | tcp or wsr[wsr/1.0] | ssl // so find http[http/1.1] layer's transport either way and you'll get ssl or tcp. ResourceAddress wsrRtmpTransportAddress; wsrRtmpTransportAddress = address.findTransport("http[http/1.1]").getTransport(); ResourceOptions wsrRtmpTransportAddressOptions = ResourceOptions.FACTORY.newResourceOptions(wsrRtmpTransportAddress); wsrRtmpTransportAddressOptions.setOption(NEXT_PROTOCOL, "rtmp/1.0"); wsrRtmpTransportAddressOptions.setOption(ResourceAddress.ALTERNATE, null); wsrRtmpTransportAddress = resourceAddressFactory.newResourceAddress(wsrRtmpTransportAddress.getExternalURI(), wsrRtmpTransportAddressOptions); ResourceOptions wsrRtmpAddressOptions = ResourceOptions.FACTORY.newResourceOptions(address); wsrRtmpAddressOptions.setOption(TRANSPORT, wsrRtmpTransportAddress); return resourceAddressFactory.newResourceAddress(address.getExternalURI(), wsrRtmpAddressOptions); }
@Deprecated // this is only needed to determine external scheme, use ResourceAddress.getExternalURI() instead public static boolean isSecure(IoSession session) { ResourceAddress address = BridgeSession.LOCAL_ADDRESS.get(session); while (address != null && !"ssl".equals(address.getResource().getScheme())) { address = address.getTransport(); } return address != null; }
@Override public String toString() { String nextProtocol = bindAddress.getOption(NEXT_PROTOCOL); nextProtocol = (nextProtocol == null ? "" : " "+nextProtocol); return format("([%s%s],0x%x,0x%x,#%d)", bindAddress.getResource(), nextProtocol, identityHashCode(handler), identityHashCode(initializer), referenceCount()); }
final BridgeSessionInitializer<T> initializer) { try { bindCookiesHandler(address.findTransport("http[http/1.1]")); final ResourceAddress transportAddress = address.getTransport(); Protocol httpProtocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportAddress.getResource().getScheme()); final BridgeSessionInitializer<T> httpInitializer = (initializer != null) ? initializer.getParentInitializer(httpProtocol) : null;
private static ResourceAddress getFloorTransport(ResourceAddress address) { assert address != null; ResourceAddress transport; while((transport = address.getTransport()) != null) { address = transport; } return address; }