Search in sources :

Example 1 with PortBindFailureException

use of org.apache.qpid.server.transport.PortBindFailureException in project qpid-broker-j by apache.

the class HttpManagement method createConnector.

private ServerConnector createConnector(final HttpPort<?> port, final Server server) {
    port.setPortManager(this);
    if (port.getState() != State.ACTIVE) {
        // TODO - RG - probably does nothing
        port.startAsync();
    }
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
    httpConnectionFactory.getHttpConfiguration().setSendServerVersion(false);
    httpConnectionFactory.getHttpConfiguration().setSendXPoweredBy(false);
    HttpConfiguration.Customizer requestAttributeCustomizer = (connector, httpConfiguration, request) -> HttpManagementUtil.getPortAttributeAction(port).performAction(request);
    httpConnectionFactory.getHttpConfiguration().addCustomizer(requestAttributeCustomizer);
    httpConnectionFactory.getHttpConfiguration().addCustomizer(new SecureRequestCustomizer());
    ConnectionFactory[] connectionFactories;
    Collection<Transport> transports = port.getTransports();
    SslContextFactory sslContextFactory = null;
    if (!transports.contains(Transport.SSL)) {
        connectionFactories = new ConnectionFactory[] { httpConnectionFactory };
    } else if (transports.contains(Transport.SSL)) {
        sslContextFactory = createSslContextFactory(port);
        ConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, httpConnectionFactory.getProtocol());
        if (port.getTransports().contains(Transport.TCP)) {
            sslConnectionFactory = new OptionalSslConnectionFactory((SslConnectionFactory) sslConnectionFactory, HttpVersion.HTTP_1_1.asString());
        }
        connectionFactories = new ConnectionFactory[] { sslConnectionFactory, httpConnectionFactory };
    } else {
        throw new IllegalArgumentException("Unexpected transport on port " + port.getName() + ":" + transports);
    }
    ServerConnector connector = new ServerConnector(server, new QBBTrackingThreadPool(port.getThreadPoolMaximum(), port.getThreadPoolMinimum()), null, null, port.getDesiredNumberOfAcceptors(), port.getDesiredNumberOfSelectors(), connectionFactories) {

        @Override
        public void open() throws IOException {
            try {
                super.open();
            } catch (BindException e) {
                _sslContextFactoryMap.remove(port);
                InetSocketAddress addr = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
                throw new PortBindFailureException(addr);
            }
        }
    };
    connector.setAcceptQueueSize(port.getAcceptBacklogSize());
    String bindingAddress = port.getBindingAddress();
    if (bindingAddress != null && !bindingAddress.trim().equals("") && !bindingAddress.trim().equals("*")) {
        connector.setHost(bindingAddress.trim());
    }
    connector.setPort(port.getPort());
    if (transports.contains(Transport.SSL)) {
        connector.addBean(new SslHandshakeListener() {

            @Override
            public void handshakeFailed(final Event event, final Throwable failure) {
                SSLEngine sslEngine = event.getSSLEngine();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.info("TLS handshake failed: host='{}', port={}", sslEngine.getPeerHost(), sslEngine.getPeerPort(), failure);
                } else {
                    LOGGER.info("TLS handshake failed: host='{}', port={}: {}", sslEngine.getPeerHost(), sslEngine.getPeerPort(), String.valueOf(failure));
                }
            }
        });
    }
    int acceptors = connector.getAcceptors();
    int selectors = connector.getSelectorManager().getSelectorCount();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Created connector for http port {} with maxThreads={}, minThreads={}, acceptors={}, selectors={}, acceptBacklog={}", port.getName(), port.getThreadPoolMaximum(), port.getThreadPoolMinimum(), acceptors, selectors, port.getAcceptBacklogSize());
    }
    int requiredNumberOfConnections = acceptors + 2 * selectors + 1;
    if (port.getThreadPoolMaximum() < requiredNumberOfConnections) {
        throw new IllegalConfigurationException(String.format("Insufficient number of threads is configured on http port '%s': max=%d < needed(acceptors=%d + selectors=2*%d + request=1)", port.getName(), port.getThreadPoolMaximum(), acceptors, selectors));
    }
    if (sslContextFactory != null) {
        _sslContextFactoryMap.put(port, sslContextFactory);
    }
    return connector;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) PortMessages(org.apache.qpid.server.logging.messages.PortMessages) Arrays(java.util.Arrays) SSLContext(javax.net.ssl.SSLContext) ManagedAttributeField(org.apache.qpid.server.model.ManagedAttributeField) PortManager(org.apache.qpid.server.model.port.PortManager) ContentFactory(org.apache.qpid.server.plugin.ContentFactory) BrokerModel(org.apache.qpid.server.model.BrokerModel) InteractiveAuthenticationFilter(org.apache.qpid.server.management.plugin.filter.InteractiveAuthenticationFilter) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) VirtualHostQueryServlet(org.apache.qpid.server.management.plugin.servlet.rest.VirtualHostQueryServlet) StructureServlet(org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet) Map(java.util.Map) Server(org.eclipse.jetty.server.Server) EnumSet(java.util.EnumSet) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) RestServlet(org.apache.qpid.server.management.plugin.servlet.rest.RestServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Set(java.util.Set) ExceptionHandlingFilter(org.apache.qpid.server.management.plugin.filter.ExceptionHandlingFilter) Transport(org.apache.qpid.server.model.Transport) StateTransition(org.apache.qpid.server.model.StateTransition) QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) KeyStore(org.apache.qpid.server.model.KeyStore) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) Joiner(com.google.common.base.Joiner) FileServlet(org.apache.qpid.server.management.plugin.servlet.FileServlet) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SSLParameters(javax.net.ssl.SSLParameters) MetaDataServlet(org.apache.qpid.server.management.plugin.servlet.rest.MetaDataServlet) AbstractPluginAdapter(org.apache.qpid.server.model.adapter.AbstractPluginAdapter) ArrayList(java.util.ArrayList) JsonValueServlet(org.apache.qpid.server.management.plugin.servlet.rest.JsonValueServlet) ContentServlet(org.apache.qpid.server.management.plugin.servlet.ContentServlet) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) MethodFilter(org.apache.qpid.server.management.plugin.filter.MethodFilter) HttpPort(org.apache.qpid.server.model.port.HttpPort) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) StringWriter(java.io.StringWriter) ManagedObjectFactoryConstructor(org.apache.qpid.server.model.ManagedObjectFactoryConstructor) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool) IOException(java.io.IOException) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) AuthenticationCheckFilter(org.apache.qpid.server.management.plugin.filter.AuthenticationCheckFilter) Futures(com.google.common.util.concurrent.Futures) Connection(org.eclipse.jetty.io.Connection) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DaemonThreadFactory(org.apache.qpid.server.util.DaemonThreadFactory) LoggerFactory(org.slf4j.LoggerFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) TrustStore(org.apache.qpid.server.model.TrustStore) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadFactory(java.util.concurrent.ThreadFactory) SSLSessionContext(javax.net.ssl.SSLSessionContext) OptionalSslConnectionFactory(org.eclipse.jetty.server.OptionalSslConnectionFactory) Port(org.apache.qpid.server.model.Port) LoggingFilter(org.apache.qpid.server.management.plugin.filter.LoggingFilter) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) RedirectFilter(org.apache.qpid.server.management.plugin.filter.RedirectFilter) MultipartConfigElement(javax.servlet.MultipartConfigElement) InetSocketAddress(java.net.InetSocketAddress) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) ManagedObject(org.apache.qpid.server.model.ManagedObject) List(java.util.List) TimeZoneServlet(org.apache.qpid.server.management.plugin.servlet.rest.TimeZoneServlet) Name(org.eclipse.jetty.util.annotation.Name) Writer(java.io.Writer) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) LogoutServlet(org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BrokerQueryServlet(org.apache.qpid.server.management.plugin.servlet.rest.BrokerQueryServlet) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpVersion(org.eclipse.jetty.http.HttpVersion) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) BindException(java.net.BindException) ManagementConsoleMessages(org.apache.qpid.server.logging.messages.ManagementConsoleMessages) SSLEngine(javax.net.ssl.SSLEngine) HashSet(java.util.HashSet) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) RewriteRequestForUncompressedJavascript(org.apache.qpid.server.management.plugin.filter.RewriteRequestForUncompressedJavascript) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) SaslServlet(org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet) Logger(org.slf4j.Logger) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) SSLUtil(org.apache.qpid.server.transport.network.security.ssl.SSLUtil) Broker(org.apache.qpid.server.model.Broker) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) State(org.apache.qpid.server.model.State) Protocol(org.apache.qpid.server.model.Protocol) QueueReportServlet(org.apache.qpid.server.management.plugin.servlet.rest.QueueReportServlet) RootServlet(org.apache.qpid.server.management.plugin.servlet.RootServlet) ServerConnector(org.eclipse.jetty.server.ServerConnector) ApiDocsServlet(org.apache.qpid.server.management.plugin.servlet.rest.ApiDocsServlet) DispatcherType(javax.servlet.DispatcherType) Collections(java.util.Collections) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) OptionalSslConnectionFactory(org.eclipse.jetty.server.OptionalSslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) OptionalSslConnectionFactory(org.eclipse.jetty.server.OptionalSslConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) BindException(java.net.BindException) Transport(org.apache.qpid.server.model.Transport) OptionalSslConnectionFactory(org.eclipse.jetty.server.OptionalSslConnectionFactory)

Example 2 with PortBindFailureException

use of org.apache.qpid.server.transport.PortBindFailureException in project qpid-broker-j by apache.

the class AmqpPortImpl method onActivate.

@Override
protected State onActivate() {
    if (getAncestor(SystemConfig.class).isManagementMode()) {
        return State.QUIESCED;
    } else {
        Collection<Transport> transports = getTransports();
        TransportProvider transportProvider = null;
        final HashSet<Transport> transportSet = new HashSet<>(transports);
        for (TransportProviderFactory tpf : (new QpidServiceLoader()).instancesOf(TransportProviderFactory.class)) {
            if (tpf.getSupportedTransports().contains(transports)) {
                transportProvider = tpf.getTransportProvider(transportSet);
            }
        }
        if (transportProvider == null) {
            throw new IllegalConfigurationException("No transport providers found which can satisfy the requirement to support the transports: " + transports);
        }
        if (transports.contains(Transport.SSL) || transports.contains(Transport.WSS)) {
            _sslContext = createSslContext();
        }
        Protocol defaultSupportedProtocolReply = getDefaultAmqpSupportedReply();
        try {
            _transport = transportProvider.createTransport(transportSet, _sslContext, this, getProtocols(), defaultSupportedProtocolReply);
            _transport.start();
            _boundPort = _transport.getAcceptingPort();
            for (Transport transport : getTransports()) {
                _container.getEventLogger().message(BrokerMessages.LISTENING(String.valueOf(transport), _transport.getAcceptingPort()));
            }
            return State.ACTIVE;
        } catch (PortBindFailureException e) {
            _container.getEventLogger().message(PortMessages.BIND_FAILED(getType().toUpperCase(), getPort()));
            throw e;
        }
    }
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) TransportProviderFactory(org.apache.qpid.server.plugin.TransportProviderFactory) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AcceptingTransport(org.apache.qpid.server.transport.AcceptingTransport) Transport(org.apache.qpid.server.model.Transport) Protocol(org.apache.qpid.server.model.Protocol) TransportProvider(org.apache.qpid.server.transport.TransportProvider) HashSet(java.util.HashSet)

Example 3 with PortBindFailureException

use of org.apache.qpid.server.transport.PortBindFailureException in project qpid-broker-j by apache.

the class HttpManagement method doStart.

@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE)
@SuppressWarnings("unused")
private ListenableFuture<Void> doStart() {
    Collection<HttpPort<?>> httpPorts = getEligibleHttpPorts(getBroker().getPorts());
    if (httpPorts.isEmpty()) {
        LOGGER.warn("HttpManagement plugin is configured but no suitable HTTP ports are available.");
    } else {
        getBroker().getEventLogger().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
        _server = createServer(httpPorts);
        try {
            _server.start();
            logOperationalListenMessages();
        } catch (PortBindFailureException e) {
            getBroker().getEventLogger().message(PortMessages.BIND_FAILED("HTTP", e.getAddress().getPort()));
            throw e;
        } catch (Exception e) {
            throw new ServerScopedRuntimeException("Failed to start HTTP management on ports : " + httpPorts, e);
        }
        getBroker().getEventLogger().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
    }
    setState(State.ACTIVE);
    return Futures.immediateFuture(null);
}
Also used : HttpPort(org.apache.qpid.server.model.port.HttpPort) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) IOException(java.io.IOException) PortBindFailureException(org.apache.qpid.server.transport.PortBindFailureException) BindException(java.net.BindException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) StateTransition(org.apache.qpid.server.model.StateTransition)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)3 PortBindFailureException (org.apache.qpid.server.transport.PortBindFailureException)3 IOException (java.io.IOException)2 BindException (java.net.BindException)2 HashSet (java.util.HashSet)2 Protocol (org.apache.qpid.server.model.Protocol)2 Transport (org.apache.qpid.server.model.Transport)2 QpidServiceLoader (org.apache.qpid.server.plugin.QpidServiceLoader)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Joiner (com.google.common.base.Joiner)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1