/** * Returns {@link Protocol} for an URI * * @param uri resource address URI * @return protocol for the given URI */ public Protocol getProtocol(URI uri) { return getProtocol(uri.getScheme()); }
private IoHandler selectConnectHandler(ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol) { return createHandler; } throw new RuntimeException(getClass()+ ": Cannot select a connect handler for address "+address); }
private IoHandler selectConnectHandler(ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol ) { return httpHandler; } throw new RuntimeException(getClass()+ ": Cannot select a connect handler for address "+address); }
private IoHandler selectTransportHandler(ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol ) { return bridgeHandler; } throw new RuntimeException(getClass()+": Cannot find handler for address "+address); }
private IoHandler selectConnectHandler(ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol ) { return createHandler; } throw new RuntimeException(getClass()+ ": Cannot select a connect handler for address "+address); }
private IoHandler selectConnectHandler(ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol) { return httpBridgeHandler; } throw new RuntimeException(getClass()+ ": Cannot select a connect handler for address "+address); }
private IoHandler selectCreateHandler(ResourceAddress transport) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(transport.getResource()); if ( protocol instanceof HttpProtocol) { return wsrCreateHandler; } throw new RuntimeException("Unable to locate a WSR create handler for address "+transport); }
private IoHandler selectReadHandler(ResourceAddress readAddress, WsebSession session) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(readAddress.getResource()); if ( protocol instanceof HttpProtocol ) { return new ReadHandler(session); } throw new RuntimeException("Cannot select read handler for address "+readAddress); }
private IoFutureListener<ConnectFuture> selectConnectFutureListener(final WsebSession session, ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol ) { return new IoFutureListener<ConnectFuture>() { @Override public void operationComplete(ConnectFuture future) { // attaching the write auto-flushes the processor try { HttpSession writeSession = (HttpSession) future.getSession(); session.attachWriter(writeSession); // implicit call to flush may be gated by semaphore // so force call to flushInternal directly instead flushInternal(session); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception {} on session {} while attaching writer or flushing", e, session); if (logger.isTraceEnabled()) { logger.trace("Exception stack trace: ", e); } } session.close(true); } } }; } throw new RuntimeException("No connect listener available for address "+address); }
public IoSessionInitializer<ConnectFuture> selectTransportSessionInitializer(final WsebSession wsebSession, ResourceAddress address) { Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(address.getResource()); if ( protocol instanceof HttpProtocol ) { return new IoSessionInitializer<ConnectFuture>() { @Override public void initializeSession(IoSession session, ConnectFuture future) { HttpConnectSession writeSession = (HttpConnectSession) session; writeSession.setMethod(HttpMethod.POST); writeSession.setWriteHeader(HEADER_TRANSFER_ENCODING, "chunked"); writeSession.setWriteHeader(HEADER_X_SEQUENCE_NO, Long.toString(wsebSession.nextWriterSequenceNo())); // Avoid default to httpxe for efficiency (single http transport layer at other end) // and to allowed chunking to work (does not currently work with httpxe) writeSession.setWriteHeader(HttpHeaders.HEADER_X_NEXT_PROTOCOL, "wse/1.0"); if (specCompliant) { // WSE specification requires Content-type header on upstream requests writeSession.setWriteHeader(HEADER_CONTENT_TYPE, "application/octet-stream"); } // Note: deferring this to writeHandler.sessionOpened creates a race condition IoFilterChain filterChain = writeSession.getFilterChain(); filterChain.addLast(CODEC_FILTER, wsebFraming); } }; } throw new RuntimeException("No session initializer available for address "+address); }
private URI locateSecureAcceptURI(HttpAcceptSession session) throws Exception { // TODO: same-origin requests must consider cross-origin access control // internal redirect to secure resource should not trigger 403 Forbidden ResourceAddress localAddress = session.getLocalAddress(); URI resource = localAddress.getResource(); Protocol resourceProtocol = bridgeServiceFactory.getTransportFactory().getProtocol(resource); if (WsebProtocol.WSEB_SSL == resourceProtocol || WsProtocol.WSS == resourceProtocol) { return resource; } return null; }
private IoHandler selectUpstreamHandler(ResourceAddress address, WsebSession wsebSession, String upstreamSuffix) { ResourceAddress transportAddress = address.getTransport(); final Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportAddress.getResource()); if (protocol instanceof HttpProtocol) { int wsMaxMessageSize = address.getOption(MAX_MESSAGE_SIZE); if (UPSTREAM_SUFFIX.equals(upstreamSuffix)) { return new WsebUpstreamHandler(address, wsebSession, wsMaxMessageSize); } else if (UPSTREAM_TEXT_SUFFIX.equals(upstreamSuffix)) { return new WsebUpstreamHandler(address, wsebSession, Encoding.UTF8, wsMaxMessageSize); } else if (UPSTREAM_TEXT_ESCAPED_SUFFIX.equals(upstreamSuffix)) { return new WsebUpstreamHandler(address, wsebSession, Encoding.UTF8_ESCAPE_ZERO_AND_NEWLINE, wsMaxMessageSize); } else if (UPSTREAM_MIXED_SUFFIX.equals(upstreamSuffix)) { return new WsebUpstreamHandler(address, wsebSession, wsMaxMessageSize); } else if (UPSTREAM_MIXED_TEXT_SUFFIX.equals(upstreamSuffix)) { return new WsebUpstreamHandler(address, wsebSession, Encoding.UTF8, wsMaxMessageSize); } else if (UPSTREAM_MIXED_TEXT_ESCAPED_SUFFIX.equals(upstreamSuffix)) { return new WsebUpstreamHandler(address, wsebSession, Encoding.UTF8_ESCAPE_ZERO_AND_NEWLINE, wsMaxMessageSize); } } throw new RuntimeException("Cannot locate a upstream handler for transport address "+address); }
@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); }
private IoHandler selectDownstreamHandler(ResourceAddress address, WsebSession wsebSession, String downstreamSuffix) { ResourceAddress transportAddress = address.getTransport(); final Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportAddress.getResource()); if (protocol instanceof HttpProtocol) { // We need a session idle tracker to handle ws close handshake, even if ws.inactivity.timeout is not set IoSessionIdleTracker sesionIdleTracker = currentSessionIdleTracker.get(); if ( DOWNSTREAM_SUFFIX.equals(downstreamSuffix) ) { return new WsebDownstreamHandler(address, wsebSession, scheduler, WsebEncodingStrategy.TEXT_AS_BINARY, sesionIdleTracker, bridgeServiceFactory); } else if (DOWNSTREAM_TEXT_SUFFIX.equals(downstreamSuffix)) { return new WsebDownstreamHandler(address, wsebSession, scheduler, "text/plain; charset=windows-1252", WsebEncodingStrategy.TEXT_AS_BINARY, sesionIdleTracker, bridgeServiceFactory); } else if (DOWNSTREAM_TEXT_ESCAPED_SUFFIX.equals(downstreamSuffix)) { return new WsebDownstreamHandler(address, wsebSession, scheduler, "text/plain; charset=windows-1252", Encoding.ESCAPE_ZERO_AND_NEWLINE, WsebEncodingStrategy.TEXT_AS_BINARY, sesionIdleTracker, bridgeServiceFactory); } else if ( DOWNSTREAM_MIXED_SUFFIX.equals(downstreamSuffix) ) { return new WsebDownstreamHandler(address, wsebSession, scheduler, WsebEncodingStrategy.DEFAULT, sesionIdleTracker, bridgeServiceFactory); } else if (DOWNSTREAM_MIXED_TEXT_SUFFIX.equals(downstreamSuffix)) { return new WsebDownstreamHandler(address, wsebSession, scheduler, "text/plain; charset=windows-1252", WsebEncodingStrategy.DEFAULT, sesionIdleTracker, bridgeServiceFactory); } else if (DOWNSTREAM_MIXED_TEXT_ESCAPED_SUFFIX.equals(downstreamSuffix)) { wsebSession.setEncodeEscapeType(EscapeTypes.ESCAPE_ZERO_AND_NEWLINES); //cache key return new WsebDownstreamHandler(address, wsebSession, scheduler, "text/plain; charset=windows-1252", Encoding.ESCAPE_ZERO_AND_NEWLINE, WsebEncodingStrategy.DEFAULT, sesionIdleTracker, bridgeServiceFactory); } } throw new RuntimeException("Cannot locate a downstream handler for transport address "+address); }
for (String balanceeURI : balanceesForAccept) { Protocol protocol = transportFactory.getProtocol(getScheme(balanceeURI)); if (secure == protocol.isSecure()) { balanceeURIs.add(balanceeURI);
for (String uri : uris) { String schemeFromAcceptURI = uri.substring(0, uri.indexOf(':')); Protocol protocol = transportFactory.getProtocol(schemeFromAcceptURI); if( WsProtocol.WS.equals(protocol) || WsProtocol.WSS.equals(protocol)) { for (String scheme: Arrays.asList("wsn", "wsx")) {
@Override protected <T extends IoFuture> void bindInternal(final ResourceAddress address, IoHandler handler, final BridgeSessionInitializer<T> initializer) { final ResourceAddress transportAddress = address.getTransport(); if (transportAddress != null) { try { URI transportURI = transportAddress.getResource(); Protocol transportProtocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportURI.getScheme()); final BridgeSessionInitializer<T> httpInitializer = (initializer != null) ? initializer.getParentInitializer(transportProtocol) : null; BridgeSessionInitializer<T> wrapper = new BridgeSessionInitializerAdapter<T>() { @Override public void initializeSession(IoSession session, T future) { session.setAttribute(NEXT_PROTOCOL_RESOURCE_ADDRESS, address); if ( httpInitializer != null ) { httpInitializer.initializeSession(session, future); } } }; BridgeAcceptor transportAcceptor = bridgeServiceFactory.newBridgeAcceptor(transportAddress); final IoHandler transportHandler = selectTransportHandler(transportAddress); transportAcceptor.bind(transportAddress, transportHandler, wrapper); } catch (NioBindException e) { throw new RuntimeException("Unable to bind address " + address + ": " + e.getMessage(), e); } } }
List<String> httpURIs = new ArrayList<>(uris.size()); for (String uri : uris) { Protocol protocol = transportFactory.getProtocol(getScheme(uri)); boolean secure = protocol.isSecure();
Protocol httpProtocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportAddress.getResource().getScheme()); final BridgeSessionInitializer<T> httpInitializer = (initializer != null) ? initializer.getParentInitializer(httpProtocol) : null;
Protocol protocol = bridgeServiceFactory.getTransportFactory().getProtocol(URIUtils.getScheme(resource)); String wsScheme = protocol.isSecure() ? "https" : "http"; String origin = wsScheme + "://" + URIUtils.getAuthority(resource);