Search in sources :

Example 6 with SocketBinding

use of org.jboss.as.network.SocketBinding in project wildfly by wildfly.

the class WebServerService method getPort.

//todo we need to handle cases when deployments reference listeners/server/host directly
@Override
public int getPort(final String protocol, final boolean secure) {
    Map<String, UndertowListener> listeners = getListenerMap();
    UndertowListener listener = null;
    for (String p : listeners.keySet()) {
        if (protocol.toLowerCase().contains(p)) {
            listener = listeners.get(p);
        }
    }
    if (listener != null && listener.getProtocol() == HttpListenerService.PROTOCOL && secure) {
        if (listeners.containsKey(HttpsListenerService.PROTOCOL)) {
            listener = listeners.get(HttpsListenerService.PROTOCOL);
        } else {
            UndertowLogger.ROOT_LOGGER.secureListenerNotAvailableForPort(protocol);
        }
    }
    if (listener != null) {
        SocketBinding binding = listener.getSocketBinding();
        return binding.getAbsolutePort();
    }
    throw UndertowLogger.ROOT_LOGGER.noPortListeningForProtocol(protocol);
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding)

Example 7 with SocketBinding

use of org.jboss.as.network.SocketBinding in project wildfly by wildfly.

the class ModClusterService method start.

@Override
public synchronized void start(StartContext context) throws StartException {
    super.start(context);
    SSLContext sslContext = this.sslContext.getOptionalValue();
    if (sslContext == null) {
        SecurityRealm realm = securityRealm.getOptionalValue();
        if (realm != null) {
            sslContext = realm.getSSLContext();
        }
    }
    //TODO: SSL support for the client
    //TODO: wire up idle timeout when new version of undertow arrives
    final ModCluster.Builder modClusterBuilder;
    final XnioWorker worker = workerInjectedValue.getValue();
    if (sslContext == null) {
        modClusterBuilder = ModCluster.builder(worker);
    } else {
        OptionMap.Builder builder = OptionMap.builder();
        builder.set(Options.USE_DIRECT_BUFFERS, true);
        OptionMap combined = builder.getMap();
        XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
        modClusterBuilder = ModCluster.builder(worker, UndertowClient.getInstance(), xnioSsl);
    }
    modClusterBuilder.setMaxRetries(maxRetries).setClientOptions(clientOptions).setHealthCheckInterval(healthCheckInterval).setMaxRequestTime(maxRequestTime).setCacheConnections(cachedConnections).setQueueNewRequests(requestQueueSize > 0).setRequestQueueSize(requestQueueSize).setRemoveBrokenNodes(removeBrokenNodes).setTtl(connectionIdleTimeout).setMaxConnections(connectionsPerThread).setUseAlias(useAlias);
    if (FailoverStrategy.DETERMINISTIC.equals(failoverStrategy)) {
        modClusterBuilder.setDeterministicFailover(true);
    }
    modCluster = modClusterBuilder.build();
    MCMPConfig.Builder builder = MCMPConfig.builder();
    final SocketBinding advertiseBinding = advertiseSocketBinding.getOptionalValue();
    if (advertiseBinding != null) {
        InetAddress multicastAddress = advertiseBinding.getMulticastAddress();
        if (multicastAddress == null) {
            throw UndertowLogger.ROOT_LOGGER.advertiseSocketBindingRequiresMulticastAddress();
        }
        if (advertiseFrequency > 0) {
            builder.enableAdvertise().setAdvertiseAddress(advertiseBinding.getSocketAddress().getAddress().getHostAddress()).setAdvertiseGroup(multicastAddress.getHostAddress()).setAdvertisePort(advertiseBinding.getMulticastPort()).setAdvertiseFrequency(advertiseFrequency).setPath(advertisePath).setProtocol(advertiseProtocol).setSecurityKey(securityKey);
        }
    }
    builder.setManagementHost(managementSocketBinding.getValue().getSocketAddress().getHostString());
    builder.setManagementPort(managementSocketBinding.getValue().getSocketAddress().getPort());
    config = builder.build();
    if (advertiseBinding != null && advertiseFrequency > 0) {
        try {
            modCluster.advertise(config);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    modCluster.start();
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) XnioWorker(org.xnio.XnioWorker) SecurityRealm(org.jboss.as.domain.management.SecurityRealm) MCMPConfig(io.undertow.server.handlers.proxy.mod_cluster.MCMPConfig) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) OptionMap(org.xnio.OptionMap) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) InetAddress(java.net.InetAddress)

Example 8 with SocketBinding

use of org.jboss.as.network.SocketBinding in project wildfly by wildfly.

the class MulticastTransportConfigurationBuilder method accept.

@Override
public void accept(T protocol) {
    SocketBinding binding = this.getSocketBinding();
    boolean multicast = binding.getMulticastAddress() != null;
    protocol.setMulticast(multicast);
    if (multicast) {
        protocol.setMulticastSocketAddress(binding.getMulticastSocketAddress());
    }
    super.accept(protocol);
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding)

Example 9 with SocketBinding

use of org.jboss.as.network.SocketBinding in project wildfly by wildfly.

the class UndertowConnectorTestCase method getPort.

@Test
public void getPort() throws UnknownHostException {
    int expected = 10;
    NetworkInterfaceBinding interfaceBinding = new NetworkInterfaceBinding(Collections.<NetworkInterface>emptySet(), InetAddress.getLocalHost());
    SocketBindingManager bindingManager = mock(SocketBindingManager.class);
    SocketBinding binding = new SocketBinding("socket", expected, true, null, 0, interfaceBinding, bindingManager, Collections.<ClientMapping>emptyList());
    when(this.listener.getSocketBinding()).thenReturn(binding);
    int result = this.connector.getPort();
    assertSame(expected, result);
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) NetworkInterfaceBinding(org.jboss.as.network.NetworkInterfaceBinding) SocketBindingManager(org.jboss.as.network.SocketBindingManager) Test(org.junit.Test)

Example 10 with SocketBinding

use of org.jboss.as.network.SocketBinding in project wildfly by wildfly.

the class ActiveMQServerService method start.

public synchronized void start(final StartContext context) throws StartException {
    ClassLoader origTCCL = org.wildfly.security.manager.WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    // Validate whether the AIO native layer can be used
    JournalType jtype = configuration.getJournalType();
    if (jtype == JournalType.ASYNCIO) {
        boolean supportsAIO = AIOSequentialFileFactory.isSupported();
        if (supportsAIO == false) {
            String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
            if (osName.contains("nux")) {
                ROOT_LOGGER.aioInfoLinux();
            } else {
                ROOT_LOGGER.aioInfo();
            }
            configuration.setJournalType(JournalType.NIO);
        }
    }
    // Setup paths
    PathManager pathManager = this.pathManager.getValue();
    configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager));
    configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager));
    configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager));
    configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager));
    pathConfig.registerCallbacks(pathManager);
    try {
        // Update the acceptor/connector port/host values from the
        // Map the socket bindings onto the connectors/acceptors
        Collection<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
        Collection<TransportConfiguration> connectors = configuration.getConnectorConfigurations().values();
        Collection<BroadcastGroupConfiguration> broadcastGroups = configuration.getBroadcastGroupConfigurations();
        Map<String, DiscoveryGroupConfiguration> discoveryGroups = configuration.getDiscoveryGroupConfigurations();
        if (connectors != null) {
            for (TransportConfiguration tc : connectors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    String host;
                    int port;
                    OutboundSocketBinding binding = outboundSocketBindings.get(name);
                    if (binding == null) {
                        final SocketBinding socketBinding = socketBindings.get(name);
                        if (socketBinding == null) {
                            throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                        }
                        InetSocketAddress sa = socketBinding.getSocketAddress();
                        port = sa.getPort();
                        // resolve the host name of the address only if a loopback address has been set
                        if (sa.getAddress().isLoopbackAddress()) {
                            host = NetworkUtils.canonize(sa.getAddress().getHostName());
                        } else {
                            host = NetworkUtils.canonize(sa.getAddress().getHostAddress());
                        }
                    } else {
                        port = binding.getDestinationPort();
                        host = NetworkUtils.canonize(binding.getUnresolvedDestinationAddress());
                        if (binding.getSourceAddress() != null) {
                            tc.getParams().put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, NetworkUtils.canonize(binding.getSourceAddress().getHostAddress()));
                        }
                        if (binding.getSourcePort() != null) {
                            // Use absolute port to account for source port offset/fixation
                            tc.getParams().put(TransportConstants.LOCAL_PORT_PROP_NAME, binding.getAbsoluteSourcePort());
                        }
                    }
                    tc.getParams().put(HOST, host);
                    tc.getParams().put(PORT, port);
                }
            }
        }
        if (acceptors != null) {
            for (TransportConfiguration tc : acceptors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    SocketBinding binding = socketBindings.get(name);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    InetSocketAddress socketAddress = binding.getSocketAddress();
                    tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
                    tc.getParams().put(PORT, socketAddress.getPort());
                }
            }
        }
        if (broadcastGroups != null) {
            final List<BroadcastGroupConfiguration> newConfigs = new ArrayList<BroadcastGroupConfiguration>();
            for (final BroadcastGroupConfiguration config : broadcastGroups) {
                final String name = config.getName();
                final String key = "broadcast" + name;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = (JChannel) channelFactory.createChannel(channelName);
                    channels.put(channelName, channel);
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, channel, channelName));
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
                }
            }
            configuration.getBroadcastGroupConfigurations().clear();
            configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
        }
        if (discoveryGroups != null) {
            configuration.setDiscoveryGroupConfigurations(new HashMap<String, DiscoveryGroupConfiguration>());
            for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
                final String name = entry.getKey();
                final String key = "discovery" + name;
                DiscoveryGroupConfiguration config = null;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = channels.get(channelName);
                    if (channel == null) {
                        channel = (JChannel) channelFactory.createChannel(key);
                        channels.put(channelName, channel);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), channel, channelName);
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding);
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                }
                configuration.getDiscoveryGroupConfigurations().put(name, config);
            }
        }
        // security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
        ActiveMQSecurityManager securityManager = null;
        final SecurityDomain elytronDomain = this.elytronSecurityDomain.getOptionalValue();
        if (elytronDomain != null) {
            securityManager = new ElytronSecurityManager(elytronDomain);
        } else {
            securityManager = new WildFlySecurityManager(securityDomainContextValue.getValue());
        }
        // insert possible credential source hold passwords
        setBridgePasswordsFromCredentialSource();
        setClusterPasswordFromCredentialSource();
        DataSource ds = dataSource.getOptionalValue();
        if (ds != null) {
            DatabaseStorageConfiguration dbConfiguration = (DatabaseStorageConfiguration) configuration.getStoreConfiguration();
            dbConfiguration.setDataSource(ds);
            // inject the datasource into the PropertySQLProviderFactory to be able to determine the
            // type of database for the datasource metadata
            PropertySQLProviderFactory sqlProviderFactory = (PropertySQLProviderFactory) dbConfiguration.getSqlProviderFactory();
            sqlProviderFactory.investigateDialect(ds);
            configuration.setStoreConfiguration(dbConfiguration);
            ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
        }
        // Now start the server
        server = new ActiveMQServerImpl(configuration, mbeanServer.getOptionalValue(), securityManager);
        if (ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(server.getConfiguration().getClusterPassword())) {
            server.getConfiguration().setClusterPassword(java.util.UUID.randomUUID().toString());
        }
        for (Interceptor incomingInterceptor : incomingInterceptors) {
            server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor);
        }
        for (Interceptor outgoingInterceptor : outgoingInterceptors) {
            server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
        }
    // the server is actually started by the JMSService.
    } catch (Exception e) {
        throw MessagingLogger.ROOT_LOGGER.failedToStartService(e);
    } finally {
        org.wildfly.security.manager.WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origTCCL);
    }
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) JChannel(org.jgroups.JChannel) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) PathManager(org.jboss.as.controller.services.path.PathManager) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) StartException(org.jboss.msc.service.StartException) DataSource(javax.sql.DataSource) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) JournalType(org.apache.activemq.artemis.core.server.JournalType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SocketBinding (org.jboss.as.network.SocketBinding)13 InetSocketAddress (java.net.InetSocketAddress)3 StartException (org.jboss.msc.service.StartException)3 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 NetworkInterfaceBinding (org.jboss.as.network.NetworkInterfaceBinding)2 OutboundSocketBinding (org.jboss.as.network.OutboundSocketBinding)2 SocketBindingManager (org.jboss.as.network.SocketBindingManager)2 Test (org.junit.Test)2 CoreEnvironmentBean (com.arjuna.ats.arjuna.common.CoreEnvironmentBean)1 CoreEnvironmentBeanException (com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException)1 RecoveryEnvironmentBean (com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean)1 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)1 ExpiredTransactionStatusManagerScanner (com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner)1 UuidProcessId (com.arjuna.ats.internal.arjuna.utils.UuidProcessId)1 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)1 JCAServerTransactionRecoveryModule (com.arjuna.ats.internal.jta.recovery.jts.JCAServerTransactionRecoveryModule)1 ExpiredContactScanner (com.arjuna.ats.internal.jts.recovery.contact.ExpiredContactScanner)1 ExpiredServerScanner (com.arjuna.ats.internal.jts.recovery.transactions.ExpiredServerScanner)1 ExpiredToplevelScanner (com.arjuna.ats.internal.jts.recovery.transactions.ExpiredToplevelScanner)1