Search in sources :

Example 1 with IOReactorException

use of org.apache.http.nio.reactor.IOReactorException in project uavstack by uavorg.

the class HttpAsyncClient method initCloseableHttpAsyncClient.

private CloseableHttpAsyncClient initCloseableHttpAsyncClient(int maxConnectionPerRoute, int maxTotalConnection, int sockTimeout, int connectTimeout, int requestTimeout) {
    ConnectingIOReactor ioReactor = null;
    try {
        ioReactor = new DefaultConnectingIOReactor();
    } catch (IOReactorException e) {
    // ignore
    }
    /**
     * 增加请求连接的相关超时
     */
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(sockTimeout).setConnectTimeout(connectTimeout).setConnectionRequestTimeout(requestTimeout).build();
    if (maxConnectionPerRoute > 0) {
        this.maxConnectionPerRoute = maxConnectionPerRoute;
    }
    if (maxTotalConnection > 0) {
        this.maxTotalConnection = maxTotalConnection;
    }
    PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(ioReactor);
    cm.setDefaultMaxPerRoute(this.maxConnectionPerRoute);
    cm.setMaxTotal(this.maxTotalConnection);
    return HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).setConnectionManager(cm).build();
}
Also used : ConnectingIOReactor(org.apache.http.nio.reactor.ConnectingIOReactor) DefaultConnectingIOReactor(org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor) DefaultConnectingIOReactor(org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor) IOReactorException(org.apache.http.nio.reactor.IOReactorException) RequestConfig(org.apache.http.client.config.RequestConfig) PoolingNHttpClientConnectionManager(org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager)

Example 2 with IOReactorException

use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.

the class PassThroughHttpSender method init.

public void init(ConfigurationContext configurationContext, TransportOutDescription transportOutDescription) throws AxisFault {
    log.info("Initializing Pass-through HTTP/S Sender...");
    namePrefix = transportOutDescription.getName().toUpperCase(Locale.US);
    scheme = getScheme();
    WorkerPool workerPool = null;
    Object obj = configurationContext.getProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
    if (obj != null) {
        workerPool = (WorkerPool) obj;
    }
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(false, scheme.getName());
    TransportView view = new TransportView(null, this, metrics, null);
    MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-sender");
    proxyConfig = new ProxyConfigBuilder().build(transportOutDescription);
    log.info(proxyConfig.logProxyConfig());
    targetConfiguration = new TargetConfiguration(configurationContext, transportOutDescription, workerPool, metrics, proxyConfig.createProxyAuthenticator());
    targetConfiguration.build();
    PassThroughSenderManager.registerPassThroughHttpSender(this);
    configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, targetConfiguration.getWorkerPool());
    ClientConnFactoryBuilder connFactoryBuilder = initConnFactoryBuilder(transportOutDescription);
    connFactory = connFactoryBuilder.createConnFactory(targetConfiguration.getHttpParams());
    try {
        String prefix = namePrefix + "-Sender I/O dispatcher";
        ioReactor = new DefaultConnectingIOReactor(targetConfiguration.getIOReactorConfig(), new NativeThreadFactory(new ThreadGroup(prefix + " Thread Group"), prefix));
        ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {

            public boolean handle(IOException ioException) {
                log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
                return true;
            }

            public boolean handle(RuntimeException runtimeException) {
                log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
                return true;
            }
        });
    } catch (IOReactorException e) {
        handleException("Error starting " + namePrefix + " ConnectingIOReactor", e);
    }
    ConnectCallback connectCallback = new ConnectCallback();
    targetConnections = new TargetConnections(ioReactor, targetConfiguration, connectCallback);
    targetConfiguration.setConnections(targetConnections);
    // create the delivery agent to hand over messages
    deliveryAgent = new DeliveryAgent(targetConfiguration, targetConnections, proxyConfig);
    // we need to set the delivery agent
    connectCallback.setDeliveryAgent(deliveryAgent);
    handler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
    ioEventDispatch = new ClientIODispatch(handler, connFactory);
    // start the sender in a separate thread
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                ioReactor.execute(ioEventDispatch);
            } catch (Exception ex) {
                log.fatal("Exception encountered in the " + namePrefix + " Sender. " + "No more connections will be initiated by this transport", ex);
            }
            log.info(namePrefix + " Sender shutdown");
        }
    }, "PassThrough" + namePrefix + "Sender");
    t.start();
    state = BaseConstants.STARTED;
    log.info("Pass-through " + namePrefix + " Sender started...");
}
Also used : IOReactorExceptionHandler(org.apache.http.nio.reactor.IOReactorExceptionHandler) ProxyConfigBuilder(org.apache.synapse.transport.nhttp.config.ProxyConfigBuilder) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) ClientConnFactoryBuilder(org.apache.synapse.transport.nhttp.config.ClientConnFactoryBuilder) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeThreadFactory(org.apache.axis2.transport.base.threads.NativeThreadFactory) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) RemoteException(java.rmi.RemoteException) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException) DefaultConnectingIOReactor(org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor) IOReactorException(org.apache.http.nio.reactor.IOReactorException) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) TransportView(org.apache.synapse.transport.passthru.jmx.TransportView) TargetConnections(org.apache.synapse.transport.passthru.connections.TargetConnections)

Example 3 with IOReactorException

use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.

the class PassThroughListeningIOReactorManager method initIOReactor.

/**
 * Create IOReactor with given configuration
 *
 * @param port                                   Port of the Endpoint for axis2 Listener
 * @param nHttpServerEventHandler                Server Handler responsible for handle events of port
 * @param passThroughSharedListenerConfiguration configuration related to create and start IOReactor
 * @return IOReactor
 */
public ListeningIOReactor initIOReactor(int port, NHttpServerEventHandler nHttpServerEventHandler, PassThroughSharedListenerConfiguration passThroughSharedListenerConfiguration) throws IOReactorException {
    ListeningIOReactor defaultListeningIOReactor;
    try {
        ServerIODispatch serverIODispatch;
        // PassThroughListenerConfiguration to be used by Shared IO Reactor
        synchronized (this) {
            if (this.passThroughListenerConfiguration == null && !passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
                this.passThroughListenerConfiguration = passThroughSharedListenerConfiguration;
            }
            if (this.sslPassThroughListenerConfiguration == null && passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
                this.sslPassThroughListenerConfiguration = passThroughSharedListenerConfiguration;
            }
        }
        // If IOReactor is in shared mode and if it is  not initialized, initialize it for HTTP Protocol
        if (ioReactorSharingMode == IOReactorSharingMode.SHARED && !isSharedIOReactorInitiated.get() && !passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
            synchronized (this) {
                portServerHandlerMapper.put(port, nHttpServerEventHandler);
                serverIODispatch = new MultiListenerServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, passThroughSharedListenerConfiguration.getServerConnFactory());
                // Create IOReactor for Listener make it shareable with Inbounds
                defaultListeningIOReactor = createListeningIOReactor(passThroughSharedListenerConfiguration);
                log.info("IO Reactor for port " + port + " initiated on shared mode which will be used by non axis2 " + "Transport Listeners ");
                sharedListeningIOReactor = defaultListeningIOReactor;
                isSharedIOReactorInitiated.compareAndSet(false, true);
            }
        } else if (ioReactorSharingMode == IOReactorSharingMode.SHARED && !isSharedSSLIOReactorInitiated.get() && passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
            synchronized (this) {
                serverConnectionFactoryMapper.put(port, passThroughSharedListenerConfiguration.getServerConnFactory());
                portServerHandlerMapper.put(port, nHttpServerEventHandler);
                serverIODispatch = new MultiListenerSSLServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, serverConnectionFactoryMapper);
                // Create IOReactor for Listener make it shareable with Inbounds
                defaultListeningIOReactor = createListeningIOReactor(passThroughSharedListenerConfiguration);
                log.info("IO Reactor for port " + port + " initiated on shared mode which will be used by non axis2 " + "Transport SSL Listeners ");
                sharedSSLListeningIOReactor = defaultListeningIOReactor;
                isSharedSSLIOReactorInitiated.compareAndSet(false, true);
            }
        } else {
            // Create un shareable IOReactors for axis2 Listeners and assign IOReactor Config for later
            // create IOReactor for Inbounds
            serverIODispatch = new ServerIODispatch(nHttpServerEventHandler, passThroughSharedListenerConfiguration.getServerConnFactory());
            defaultListeningIOReactor = createListeningIOReactor(passThroughSharedListenerConfiguration);
        }
        passThroughListenerServerIODispatchMapper.put(port, serverIODispatch);
        passThroughListenerIOReactorMapper.put(port, defaultListeningIOReactor);
    } catch (IOReactorException e) {
        throw new IOReactorException("Error occurred when trying to init IO Reactor", e);
    }
    return defaultListeningIOReactor;
}
Also used : IOReactorException(org.apache.http.nio.reactor.IOReactorException) ServerIODispatch(org.apache.synapse.transport.passthru.ServerIODispatch) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch) ListeningIOReactor(org.apache.http.nio.reactor.ListeningIOReactor) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch)

Example 4 with IOReactorException

use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.

the class PassThroughListeningIOReactorManager method getSharedSSLIOReactor.

private ListeningIOReactor getSharedSSLIOReactor(NHttpServerEventHandler nHttpServerEventHandler, String endpointName, int port, SSLConfiguration sslConfiguration) throws Exception {
    if (!isSharedSSLIOReactorInitiated.get()) {
        if (sslPassThroughListenerConfiguration != null) {
            try {
                synchronized (this) {
                    sharedSSLListeningIOReactor = createListeningIOReactor(sslPassThroughListenerConfiguration);
                    ServerIODispatch serverIODispatch = new MultiListenerSSLServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, serverConnectionFactoryMapper);
                    startIOReactor(sharedSSLListeningIOReactor, serverIODispatch, "HTTPS");
                    isSharedSSLIOReactorInitiated.compareAndSet(false, true);
                }
            } catch (IOReactorException e) {
                throw new IOReactorException("Error occurred when creating shared IO Reactor for non axis2 Listener " + endpointName, e);
            }
        } else {
            throw new Exception("Cannot start Endpoint for" + endpointName + "Axis2 SSL Transport Listeners for PassThrough transport" + " not started correctly or not created the " + "IOReactor Configuration");
        }
    }
    ServerConnFactory serverConnFactory = SSLConnectionUtils.getServerConnectionFactory(endpointName, sslPassThroughListenerConfiguration, sslConfiguration);
    if (serverConnectionFactoryMapper.get(port) != null) {
        throw new Exception("Cannot create ServerConnectionFactory for " + endpointName + "in port " + port + "already registered a server connection factory ");
    } else {
        serverConnectionFactoryMapper.put(port, serverConnFactory);
    }
    return sharedSSLListeningIOReactor;
}
Also used : IOReactorException(org.apache.http.nio.reactor.IOReactorException) ServerIODispatch(org.apache.synapse.transport.passthru.ServerIODispatch) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch) ServerConnFactory(org.apache.synapse.transport.http.conn.ServerConnFactory) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException)

Example 5 with IOReactorException

use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.

the class PassThroughListeningIOReactorManager method getSharedIOReactor.

private ListeningIOReactor getSharedIOReactor(NHttpServerEventHandler nHttpServerEventHandler, String endpointName) throws Exception {
    if (!isSharedIOReactorInitiated.get()) {
        if (passThroughListenerConfiguration != null) {
            try {
                synchronized (this) {
                    sharedListeningIOReactor = createListeningIOReactor(passThroughListenerConfiguration);
                    ServerIODispatch serverIODispatch = new MultiListenerServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, passThroughListenerConfiguration.getServerConnFactory());
                    startIOReactor(sharedListeningIOReactor, serverIODispatch, "HTTP");
                    isSharedIOReactorInitiated.compareAndSet(false, true);
                }
            } catch (IOReactorException e) {
                throw new IOReactorException("Error occurred when creating shared IO Reactor for non axis2 Listener " + endpointName, e);
            }
        } else {
            throw new Exception("Cannot start Endpoint for" + endpointName + "Axis2 Transport Listeners for PassThrough transport" + " not started correctly or not created the " + "IOReactor Configuration");
        }
    }
    return sharedListeningIOReactor;
}
Also used : IOReactorException(org.apache.http.nio.reactor.IOReactorException) ServerIODispatch(org.apache.synapse.transport.passthru.ServerIODispatch) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException)

Aggregations

IOReactorException (org.apache.http.nio.reactor.IOReactorException)6 IOException (java.io.IOException)3 ServerIODispatch (org.apache.synapse.transport.passthru.ServerIODispatch)3 MultiListenerSSLServerIODispatch (org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch)3 NativeThreadFactory (org.apache.axis2.transport.base.threads.NativeThreadFactory)2 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)2 DefaultConnectingIOReactor (org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor)2 PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)2 TransportView (org.apache.synapse.transport.passthru.jmx.TransportView)2 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 AxisService (org.apache.axis2.description.AxisService)1 Parameter (org.apache.axis2.description.Parameter)1 AxisServiceFilter (org.apache.axis2.transport.base.tracker.AxisServiceFilter)1 AxisServiceTracker (org.apache.axis2.transport.base.tracker.AxisServiceTracker)1 AxisServiceTrackerListener (org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener)1 HttpException (org.apache.http.HttpException)1 HttpHost (org.apache.http.HttpHost)1