public static ProxyConnector createIoProxyConnector(SocketConnector socketConnector, InetSocketAddress address, InetSocketAddress proxyAddress, String proxyType, String proxyVersion, String proxyUser, String proxyPassword, String proxyDomain, String proxyWorkstation ) throws ConfigError { // Create proxy connector. ProxyRequest req; ProxyConnector connector = new ProxyConnector(socketConnector); connector.setConnectTimeoutMillis(5000); if (proxyType.equalsIgnoreCase("http")) { req = createHttpProxyRequest(address, proxyVersion, proxyUser, proxyPassword, proxyDomain, proxyWorkstation); } else if (proxyType.equalsIgnoreCase("socks")) { req = createSocksProxyRequest(address, proxyVersion, proxyUser, proxyPassword); } else { throw new ConfigError("Proxy type must be http or socks"); } ProxyIoSession proxyIoSession = new ProxyIoSession(proxyAddress, req); List<HttpAuthenticationMethods> l = new ArrayList<>(); l.add(HttpAuthenticationMethods.NO_AUTH); l.add(HttpAuthenticationMethods.DIGEST); l.add(HttpAuthenticationMethods.BASIC); proxyIoSession.setPreferedOrder(l); connector.setProxyIoSession(proxyIoSession); return connector; }
/** * Method to reconnect to the proxy when it decides not to maintain the connection * during handshake. * * @param nextFilter the next filter * @param request the http request */ private void reconnect(final NextFilter nextFilter, final HttpProxyRequest request) { LOGGER.debug("Reconnecting to proxy ..."); final ProxyIoSession proxyIoSession = getProxyIoSession(); // Fires reconnection proxyIoSession.getConnector().connect(new IoSessionInitializer<ConnectFuture>() { @Override public void initializeSession(final IoSession session, ConnectFuture future) { LOGGER.debug("Initializing new session: {}", session); session.setAttribute(ProxyIoSession.PROXY_SESSION, proxyIoSession); proxyIoSession.setSession(session); LOGGER.debug(" setting up proxyIoSession: {}", proxyIoSession); // Reconnection is done so we send the // request to the proxy proxyIoSession.setReconnectionNeeded(false); writeRequest0(nextFilter, request); } }); }
/** * Creates a new proxy connector. * * @param connector The Connector used to establish proxy connections. * @param config The session confiugarion to use * @param executor The associated executor */ public ProxyConnector(final SocketConnector connector, IoSessionConfig config, Executor executor) { super(config, executor); setConnector(connector); }
/** * Sets the proxy session object of this connector. * @param proxyIoSession the configuration of this connector. */ public void setProxyIoSession(ProxyIoSession proxyIoSession) { if (proxyIoSession == null) { throw new IllegalArgumentException("proxySession object cannot be null"); } if (proxyIoSession.getProxyAddress() == null) { throw new IllegalArgumentException("proxySession.proxyAddress cannot be null"); } proxyIoSession.setConnector(this); setDefaultRemoteAddress(proxyIoSession.getProxyAddress()); this.proxyIoSession = proxyIoSession; }
/** * Signals that the handshake has finished. */ protected final void setHandshakeComplete() { synchronized (this) { handshakeComplete = true; } ProxyIoSession proxyIoSession = getProxyIoSession(); proxyIoSession.getConnector().fireConnected(proxyIoSession.getSession()).awaitUninterruptibly(); LOGGER.debug(" handshake completed"); // Connected OK try { proxyIoSession.getEventQueue().flushPendingSessionEvents(); flushPendingWriteRequests(); } catch (Exception ex) { LOGGER.error("Unable to flush pending write requests", ex); } }
private void setupIoConnector() throws ConfigError, GeneralSecurityException { final CompositeIoFilterChainBuilder ioFilterChainBuilder = new CompositeIoFilterChainBuilder(userIoFilterChainBuilder); boolean hasProxy = proxyType != null && proxyPort > 0 && socketAddresses[nextSocketAddressIndex] instanceof InetSocketAddress; SSLFilter sslFilter = null; if (sslEnabled) { sslFilter = installSslFilter(ioFilterChainBuilder, !hasProxy); } ioFilterChainBuilder.addLast(FIXProtocolCodecFactory.FILTER_NAME, new ProtocolCodecFilter(new FIXProtocolCodecFactory())); IoConnector newConnector; newConnector = ProtocolFactory.createIoConnector(socketAddresses[nextSocketAddressIndex]); newConnector.setHandler(new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy)); newConnector.setFilterChainBuilder(ioFilterChainBuilder); if (hasProxy) { ProxyConnector proxyConnector = ProtocolFactory.createIoProxyConnector( (SocketConnector) newConnector, (InetSocketAddress) socketAddresses[nextSocketAddressIndex], new InetSocketAddress(proxyHost, proxyPort), proxyType, proxyVersion, proxyUser, proxyPassword, proxyDomain, proxyWorkstation ); proxyConnector.setHandler(new InitiatorProxyIoHandler( new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy), sslFilter )); newConnector = proxyConnector; } if (ioConnector != null) { SessionConnector.closeManagedSessionsAndDispose(ioConnector, true, log); } ioConnector = newConnector; }
if (!proxyIoSession.isReconnectionNeeded()) { IoHandler handler = getHandler(); if (!(handler instanceof AbstractProxyIoHandler)) { throw new IllegalArgumentException("IoHandler must be an instance of AbstractProxyIoHandler");
if (evt.getType() == IoSessionEventType.CLOSED) { if (proxyIoSession.isAuthenticationFailed()) { proxyIoSession.getConnector().cancelConnectFuture(); discardSessionQueueEvents(); evt.deliverEvent();
/** * Sets the proxy session object of this connector. * @param proxyIoSession the configuration of this connector. */ public void setProxyIoSession(ProxyIoSession proxyIoSession) { if (proxyIoSession == null) { throw new IllegalArgumentException("proxySession object cannot be null"); } if (proxyIoSession.getProxyAddress() == null) { throw new IllegalArgumentException("proxySession.proxyAddress cannot be null"); } proxyIoSession.setConnector(this); setDefaultRemoteAddress(proxyIoSession.getProxyAddress()); this.proxyIoSession = proxyIoSession; }
/** * Signals that the handshake has finished. */ protected final void setHandshakeComplete() { synchronized (this) { handshakeComplete = true; } ProxyIoSession proxyIoSession = getProxyIoSession(); proxyIoSession.getConnector().fireConnected(proxyIoSession.getSession()).awaitUninterruptibly(); LOGGER.debug(" handshake completed"); // Connected OK try { proxyIoSession.getEventQueue().flushPendingSessionEvents(); flushPendingWriteRequests(); } catch (Exception ex) { LOGGER.error("Unable to flush pending write requests", ex); } }
private void setupIoConnector() throws ConfigError, GeneralSecurityException { final CompositeIoFilterChainBuilder ioFilterChainBuilder = new CompositeIoFilterChainBuilder(userIoFilterChainBuilder); boolean hasProxy = proxyType != null && proxyPort > 0 && socketAddresses[nextSocketAddressIndex] instanceof InetSocketAddress; SSLFilter sslFilter = null; if (sslEnabled) { sslFilter = installSslFilter(ioFilterChainBuilder, !hasProxy); } ioFilterChainBuilder.addLast(FIXProtocolCodecFactory.FILTER_NAME, new ProtocolCodecFilter(new FIXProtocolCodecFactory())); IoConnector newConnector; newConnector = ProtocolFactory.createIoConnector(socketAddresses[nextSocketAddressIndex]); newConnector.setHandler(new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy)); newConnector.setFilterChainBuilder(ioFilterChainBuilder); if (hasProxy) { ProxyConnector proxyConnector = ProtocolFactory.createIoProxyConnector( (SocketConnector) newConnector, (InetSocketAddress) socketAddresses[nextSocketAddressIndex], new InetSocketAddress(proxyHost, proxyPort), proxyType, proxyVersion, proxyUser, proxyPassword, proxyDomain, proxyWorkstation ); proxyConnector.setHandler(new InitiatorProxyIoHandler( new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy), sslFilter )); newConnector = proxyConnector; } if (ioConnector != null) { ioConnector.dispose(); } ioConnector = newConnector; }
if (!proxyIoSession.isReconnectionNeeded()) { IoHandler handler = getHandler(); if (!(handler instanceof AbstractProxyIoHandler)) { throw new IllegalArgumentException("IoHandler must be an instance of AbstractProxyIoHandler");
if (evt.getType() == IoSessionEventType.CLOSED) { if (proxyIoSession.isAuthenticationFailed()) { proxyIoSession.getConnector().cancelConnectFuture(); discardSessionQueueEvents(); evt.deliverEvent();
public static ProxyConnector createIoProxyConnector(SocketConnector socketConnector, InetSocketAddress address, InetSocketAddress proxyAddress, String proxyType, String proxyVersion, String proxyUser, String proxyPassword, String proxyDomain, String proxyWorkstation ) throws ConfigError { // Create proxy connector. ProxyRequest req; ProxyConnector connector = new ProxyConnector(socketConnector); connector.setConnectTimeoutMillis(5000); if (proxyType.equalsIgnoreCase("http")) { req = createHttpProxyRequest(address, proxyVersion, proxyUser, proxyPassword, proxyDomain, proxyWorkstation); } else if (proxyType.equalsIgnoreCase("socks")) { req = createSocksProxyRequest(address, proxyVersion, proxyUser, proxyPassword); } else { throw new ConfigError("Proxy type must be http or socks"); } ProxyIoSession proxyIoSession = new ProxyIoSession(proxyAddress, req); List<HttpAuthenticationMethods> l = new ArrayList<>(); l.add(HttpAuthenticationMethods.NO_AUTH); l.add(HttpAuthenticationMethods.DIGEST); l.add(HttpAuthenticationMethods.BASIC); proxyIoSession.setPreferedOrder(l); connector.setProxyIoSession(proxyIoSession); return connector; }
/** * Creates a new proxy connector. * @see AbstractIoConnector(IoSessionConfig, Executor). */ public ProxyConnector(final SocketConnector connector, IoSessionConfig config, Executor executor) { super(config, executor); setConnector(connector); }
/** * Sets the proxy session object of this connector. * @param proxyIoSession the configuration of this connector. */ public void setProxyIoSession(ProxyIoSession proxyIoSession) { if (proxyIoSession == null) { throw new NullPointerException("proxySession object cannot be null"); } if (proxyIoSession.getProxyAddress() == null) { throw new NullPointerException( "proxySession.proxyAddress cannot be null"); } proxyIoSession.setConnector(this); setDefaultRemoteAddress(proxyIoSession.getProxyAddress()); this.proxyIoSession = proxyIoSession; }
/** * Signals that the handshake has finished. */ protected final void setHandshakeComplete() { synchronized (this) { handshakeComplete = true; } ProxyIoSession proxyIoSession = getProxyIoSession(); proxyIoSession.getConnector() .fireConnected(proxyIoSession.getSession()) .awaitUninterruptibly(); LOGGER.debug(" handshake completed"); // Connected OK try { proxyIoSession.getEventQueue().flushPendingSessionEvents(); flushPendingWriteRequests(); } catch (Exception ex) { LOGGER.error("Unable to flush pending write requests", ex); } }
/** * Method to reconnect to the proxy when it decides not to maintain the connection * during handshake. * * @param nextFilter the next filter * @param request the http request */ private void reconnect(final NextFilter nextFilter, final HttpProxyRequest request) { LOGGER.debug("Reconnecting to proxy ..."); final ProxyIoSession proxyIoSession = getProxyIoSession(); // Fires reconnection proxyIoSession.getConnector().connect(new IoSessionInitializer<ConnectFuture>() { @Override public void initializeSession(final IoSession session, ConnectFuture future) { LOGGER.debug("Initializing new session: {}", session); session.setAttribute(ProxyIoSession.PROXY_SESSION, proxyIoSession); proxyIoSession.setSession(session); LOGGER.debug(" setting up proxyIoSession: {}", proxyIoSession); // Reconnection is done so we send the // request to the proxy proxyIoSession.setReconnectionNeeded(false); writeRequest0(nextFilter, request); } }); }
private void setupIoConnector() throws ConfigError, GeneralSecurityException { final CompositeIoFilterChainBuilder ioFilterChainBuilder = new CompositeIoFilterChainBuilder(userIoFilterChainBuilder); boolean hasProxy = proxyType != null && proxyPort > 0 && socketAddresses[nextSocketAddressIndex] instanceof InetSocketAddress; SSLFilter sslFilter = null; if (sslEnabled) { sslFilter = installSslFilter(ioFilterChainBuilder, !hasProxy); } ioFilterChainBuilder.addLast(FIXProtocolCodecFactory.FILTER_NAME, new ProtocolCodecFilter(new FIXProtocolCodecFactory())); IoConnector newConnector; newConnector = ProtocolFactory.createIoConnector(socketAddresses[nextSocketAddressIndex]); newConnector.setHandler(new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy)); newConnector.setFilterChainBuilder(ioFilterChainBuilder); if (hasProxy) { ProxyConnector proxyConnector = ProtocolFactory.createIoProxyConnector( (SocketConnector) newConnector, (InetSocketAddress) socketAddresses[nextSocketAddressIndex], new InetSocketAddress(proxyHost, proxyPort), proxyType, proxyVersion, proxyUser, proxyPassword, proxyDomain, proxyWorkstation ); proxyConnector.setHandler(new InitiatorProxyIoHandler( new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy), sslFilter )); newConnector = proxyConnector; } if (ioConnector != null) { SessionConnector.closeManagedSessionsAndDispose(ioConnector, true, log); } ioConnector = newConnector; }
if (!proxyIoSession.isReconnectionNeeded()) { IoHandler handler = getHandler(); if (!(handler instanceof AbstractProxyIoHandler)) { throw new IllegalArgumentException(