private static ResourceAddress getFloorTransport(ResourceAddress address) { assert address != null; ResourceAddress transport; while((transport = address.getTransport()) != null) { address = transport; } return address; }
@Override public void unbind(ResourceAddress resourceAddress) { // Next, check SSL settings. Specifically, the <ssl.ciphers> and // <ssl.verify-client> configurations. List<ResourceAddress> inetAddressResourceAddresses = transportAddressToResourceAddresses.get(resourceAddress.getTransport()); if (inetAddressResourceAddresses != null) { transportAddressToResourceAddresses.remove(resourceAddress.getTransport()); } } }
/** * Method returning lowest transport layer * @param transport * @return */ static ResourceAddress getLowestTransportLayer(ResourceAddress transport) { if (transport.getTransport() != null) { return getLowestTransportLayer(transport.getTransport()); } return transport; }
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; }
private BridgeAcceptor selectWsAcceptor(ResourceAddress bindAddress) { if (wsBridgeAcceptorMap == null) { initWsBridgeAcceptorMap(); } if ( bindAddress.getTransport() == null ) { throw new RuntimeException(format("Cannot select a WebSocket acceptor for address '%s'.", bindAddress)); } String nextProtocol = bindAddress.getTransport().getOption(NEXT_PROTOCOL); if (nextProtocol == null || nextProtocol.isEmpty()) { throw new RuntimeException(format("Cannot find a transport nextProtocol for address '%s'.", bindAddress)); } return wsBridgeAcceptorMap.get(nextProtocol); }
@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 protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { unbindApiPath(address); ResourceAddress transport = address.getTransport(); BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transport); return acceptor.unbind(address.getTransport()); }
private UnbindFuture unbindRtmpAddress(ResourceAddress address) { ResourceAddress wsrRtmpAddress = createWsrRtmpAddress(address); removeWsrRtmpBinding(wsrRtmpAddress); BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(wsrRtmpAddress.getTransport()); return acceptor.unbind(wsrRtmpAddress.getTransport()); }
@Override protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { final ResourceAddress transportBindAddress = address.getTransport(); final BridgeAcceptor transportAcceptor = bridgeServiceFactory.newBridgeAcceptor(transportBindAddress); return transportAcceptor.unbind(transportBindAddress); }
@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); }
public boolean isChunkingNecessary() { // if there is no content length specified, is chunking necessary? // well, yes usually. but if you are a wrapped response at the httpxe layer and a legacy client, then no. // why? because the content is length-encoded already. ResourceAddress address = getLocalAddress().getTransport(); return address != null && ( ! "httpxe/1.1".equals(address.getOption(ResourceAddress.NEXT_PROTOCOL)) && ! conditionallyWrappedResponsesRequired(this)); }
private ResourceAddress createWsrCreateAddress(ResourceAddress address) { ResourceAddress wsrTransportAddress = address.getTransport(); URI wsrTransportBindURI = wsrTransportAddress.getResource(); return wsrTransportAddress.resolve(createResolvePath(wsrTransportBindURI, CREATE_SUFFIX)); }
private <T extends IoFuture> void bindRtmpAddress(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<T> initializer) { // TODO: avoid the global bind for all RTMP streams // instead, dynamically bind RTMP streams, like WSE upstream & downstream // note: may require an RTMP transport ResourceAddress wsrRtmpAddress = createWsrRtmpAddress(address); // add bind mapping for the wsr rtmp address addWsrRtmpBinding(wsrRtmpAddress, handler, initializer); // bind the wsr rtmp address transport BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(wsrRtmpAddress.getTransport()); BridgeSessionInitializer<T> theInitializer = (initializer != null) ? initializer.getParentInitializer(HttpProtocol.HTTP) : null; acceptor.bind(wsrRtmpAddress.getTransport(), ioBridgeHandler, theInitializer); }
private void bindApiPath(ResourceAddress address) { ResourceAddress apiHttpAddress = createApiHttpAddress(address.getTransport()); bridgeServiceFactory.newBridgeAcceptor(apiHttpAddress).bind(apiHttpAddress, WsAcceptor.API_PATH_HANDLER, null); ResourceAddress apiHttpxeAddress = address.getTransport().getOption(ALTERNATE); if (apiHttpxeAddress != null) { apiHttpxeAddress = createApiHttpxeAddress(apiHttpxeAddress); bridgeServiceFactory.newBridgeAcceptor(apiHttpxeAddress).bind(apiHttpxeAddress, WsAcceptor.API_PATH_HANDLER, null); } }
private void unbindApiPath(ResourceAddress address) { ResourceAddress apiHttpAddress = createApiHttpAddress(address.getTransport()); bridgeServiceFactory.newBridgeAcceptor(apiHttpAddress).unbind(apiHttpAddress); ResourceAddress apiHttpxeAddress = address.getTransport().getOption(ALTERNATE); if (apiHttpxeAddress != null) { apiHttpxeAddress = createApiHttpxeAddress(apiHttpxeAddress); bridgeServiceFactory.newBridgeAcceptor(apiHttpxeAddress).unbind(apiHttpxeAddress); } }
@Override protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { unbindApiPath(address); final ResourceAddress transportAddress = address.getTransport(); BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transportAddress); UnbindFuture future = unbindCookiesHandler(address.findTransport("http[http/1.1]")); future = combineFutures(future, acceptor.unbind(transportAddress)); return future; }
private ResourceAddress createCookiesAddress(ResourceAddress httpAddress) { // /;e/cookies is a terminal endpoint so next protocol should == null ResourceOptions cookieOptions = ResourceOptions.FACTORY.newResourceOptions(httpAddress); cookieOptions.setOption(NEXT_PROTOCOL, null); cookieOptions.setOption(TRANSPORT, httpAddress.getTransport()); cookieOptions.setOption(BIND_ALTERNATE, Boolean.FALSE); URI cookiesLocation = appendURI(httpAddress.getResource(), COOKIES_SUFFIX); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(cookiesLocation), cookieOptions); }
private <T extends ConnectFuture> void connectUsingNewTransport(final ConnectFuture connectFuture, ResourceAddress address, HttpConnectSessionFactory httpSessionFactory) { // propagate connection failure, if necessary IoFutureListener<ConnectFuture> parentConnectListener = future -> { // fail bridge connect future if parent connect fails if (!future.isConnected()) { connectFuture.setException(future.getException()); } }; ResourceAddress transportAddress = address.getTransport(); BridgeConnector connector = bridgeServiceFactory.newBridgeConnector(transportAddress); IoSessionInitializer<ConnectFuture> parentInitializer = createParentInitializer(address, connectFuture, httpSessionFactory); connector.connect(transportAddress, bridgeHandler, parentInitializer).addListener(parentConnectListener); }
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); }
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); }