Search in sources :

Example 1 with PUService

use of com.sun.messaging.portunif.PUService in project openmq by eclipse-ee4j.

the class StompServer method stop.

public synchronized void stop() throws Exception {
    if (!_inited || (_bc.doBind() && _bc.getPUService() == null && _tcpTransport == null && _sslTransport == null) || (_bc.doBind() && _bc.getPUService() != null && _tcppup == null && _sslpup == null)) {
        String emsg = getStompBridgeResources().getKString(StompBridgeResources.X_STOMP_SERVER_NO_INIT);
        _logger.log(Level.SEVERE, emsg);
        throw new IllegalStateException(emsg);
    }
    if (!_bc.doBind()) {
        // to be implemented
        return;
    }
    _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_STOP_STOMP_SERVER));
    PUService pu = (PUService) _bc.getPUService();
    if (pu != null) {
        Exception e = null;
        if (_tcpEnabled) {
            try {
                pu.deregister(_tcppup);
            } catch (Exception ee) {
                e = ee;
            }
        }
        if (_sslEnabled) {
            try {
                pu.deregisterSSL(_sslpup);
            } catch (Exception ee) {
                if (e == null) {
                    e = ee;
                }
            }
        }
        if (e != null) {
            _logger.log(Level.SEVERE, e.getMessage(), e);
            throw e;
        }
    } else {
        Exception e = null;
        if (_tcpEnabled) {
            try {
                _tcpTransport.shutdownNow();
            } catch (Exception ee) {
                e = ee;
            }
        }
        if (_sslEnabled) {
            try {
                _sslTransport.shutdownNow();
            } catch (Exception ee) {
                if (e == null) {
                    e = ee;
                }
            }
        }
        if (e != null) {
            _logger.log(Level.SEVERE, e.getMessage(), e);
            throw e;
        }
    }
    _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_STOMP_SERVER_STOPPED));
}
Also used : PUService(com.sun.messaging.portunif.PUService)

Example 2 with PUService

use of com.sun.messaging.portunif.PUService in project openmq by eclipse-ee4j.

the class StompServer method init.

public synchronized void init(BridgeContext bc) throws Exception {
    _bc = bc;
    Properties props = bc.getConfig();
    String domain = props.getProperty(BridgeContext.BRIDGE_PROP_PREFIX);
    String cn = props.getProperty(domain + PROP_MSGTRANSFORM_SUFFIX);
    if (cn != null) {
        _msgTransformer = (MessageTransformer<Message, Message>) Class.forName(cn).getDeclaredConstructor().newInstance();
    }
    jmsprop = new Properties();
    String flowlimit = props.getProperty(domain + PROP_FLOWLIMIT_SUFFIX);
    if (flowlimit != null) {
        jmsprop.setProperty(com.sun.messaging.ConnectionConfiguration.imqConsumerFlowLimit, String.valueOf(Integer.parseInt(flowlimit)));
    }
    _logger = Logger.getLogger(domain);
    if (bc.isSilentMode()) {
        _logger.setUseParentHandlers(false);
    }
    String var = bc.getRootDir();
    File dir = new File(var);
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            throw new IOException("File.mkdirs(" + var + ")");
        }
    }
    String logfile = var + File.separator + "stomp%g.log";
    int limit = 0, count = 1;
    String limits = props.getProperty(domain + PROP_LOGFILE_LIMIT_SUFFIX);
    if (limits != null) {
        limit = Integer.parseInt(limits);
    }
    String counts = props.getProperty(domain + PROP_LOGFILE_COUNT_SUFFIX);
    if (counts != null) {
        count = Integer.parseInt(counts);
    }
    FileHandler h = new FileHandler(logfile, limit, count, true);
    h.setFormatter(new LogSimpleFormatter(_logger));
    _logger.addHandler(h);
    _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_LOG_DOMAIN, domain));
    _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_LOG_FILE, logfile) + "[" + limit + "," + count + "]");
    String v = props.getProperty(domain + PROP_TCPENABLED_SUFFIX, "true");
    if (v != null && Boolean.parseBoolean(v)) {
        String p = props.getProperty(domain + PROP_TCPPORT_SUFFIX, String.valueOf(DEFAULT_TCPPORT));
        TCPPORT = Integer.parseInt(p);
        _tcpEnabled = true;
    }
    v = props.getProperty(domain + PROP_SSLENABLED_SUFFIX, "false");
    if (v != null && Boolean.parseBoolean(v)) {
        String p = props.getProperty(domain + PROP_SSLPORT_SUFFIX, String.valueOf(DEFAULT_SSLPORT));
        SSLPORT = Integer.parseInt(p);
        _sslEnabled = true;
    }
    if (!_tcpEnabled && !_sslEnabled) {
        throw new IllegalArgumentException(getStompBridgeResources().getKString(StompBridgeResources.X_NO_PROTOCOL));
    }
    v = props.getProperty(domain + PROP_HOSTNAME_SUFFIX);
    if (v == null || v.length() == 0) {
        v = bc.getBrokerHostName();
    }
    String hn = null;
    if (v != null && v.length() > 0) {
        hn = v;
        HOST = InetAddress.getByName(v);
    } else {
        hn = InetAddress.getLocalHost().getCanonicalHostName();
    }
    URL u = new URL("http", hn, TCPPORT, "");
    TCPHOSTNAMEPORT = u.getHost() + ":" + TCPPORT;
    u = new URL("http", hn, SSLPORT, "");
    SSLHOSTNAMEPORT = u.getHost() + ":" + SSLPORT;
    int major = Grizzly.getMajorVersion();
    // int minor = Grizzly.getMinorVersion();
    if (major < 2) {
        String[] params = { String.valueOf(major), Grizzly.getDotedVersion(), String.valueOf(1) };
        String emsg = getStompBridgeResources().getKString(StompBridgeResources.X_INCOMPATIBLE_GRIZZLY_MAJOR_VERSION, params);
        _logger.log(Level.SEVERE, emsg);
        throw new UnsupportedOperationException(emsg);
    }
    _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_INIT_GRIZZLY, Grizzly.getDotedVersion()));
    PUService pu = null;
    if (_bc.doBind() && (_tcpEnabled || _sslEnabled)) {
        pu = (PUService) bc.getPUService();
        if (pu == null) {
            if (_tcpEnabled) {
                FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
                filterChainBuilder.add(new TransportFilter());
                filterChainBuilder.add(new StompMessageFilter(this));
                filterChainBuilder.add(new StompMessageDispatchFilter(this));
                _tcpTransport = TCPNIOTransportBuilder.newInstance().build();
                _tcpTransport.setProcessor(filterChainBuilder.build());
                InetSocketAddress saddr = (HOST == null ? new InetSocketAddress(TCPPORT) : new InetSocketAddress(HOST, TCPPORT));
                _tcpTransport.bind(saddr);
            }
            if (_sslEnabled) {
                final SSLEngineConfigurator serverConfig = initializeSSL(_bc, domain, props, _logger);
                final SSLEngineConfigurator clientConfig = serverConfig.copy().setClientMode(true);
                FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
                filterChainBuilder.add(new TransportFilter());
                filterChainBuilder.add(new SSLFilter(serverConfig, clientConfig));
                filterChainBuilder.add(new StompMessageFilter(this));
                filterChainBuilder.add(new StompMessageDispatchFilter(this));
                _sslTransport = TCPNIOTransportBuilder.newInstance().build();
                _sslTransport.setProcessor(filterChainBuilder.build());
                InetSocketAddress saddr = (HOST == null ? new InetSocketAddress(SSLPORT) : new InetSocketAddress(HOST, SSLPORT));
                _sslTransport.bind(saddr);
            }
        } else {
            if (_tcpEnabled) {
                final FilterChain puProtocolFilterChain = pu.getPUFilterChainBuilder().add(new StompMessageFilter(this)).add(new StompMessageDispatchFilter(this)).build();
                StompProtocolFinder pf = new StompProtocolFinder();
                _tcppup = new PUProtocol(pf, puProtocolFilterChain);
            }
            if (_sslEnabled) {
                Properties sslprops = bc.getDefaultSSLContextConfig();
                boolean reqcauth = false;
                v = props.getProperty(domain + PROP_SSL_REQUIRE_CLIENTAUTH_SUFFIX, "false");
                if (v != null && Boolean.parseBoolean(v)) {
                    reqcauth = true;
                }
                if (!pu.initializeSSL(sslprops, reqcauth, null, _bc.getPoodleFixEnabled(), _bc.getKnownSSLEnabledProtocols())) {
                    if (pu.getSSLClientAuthRequired() != reqcauth) {
                        _logger.log(Level.WARNING, getStompBridgeResources().getString(StompBridgeResources.W_PROPERTY_SETTING_OVERRIDE_BY_BROKER, domain + PROP_SSL_REQUIRE_CLIENTAUTH_SUFFIX + "=" + reqcauth, domain + PROP_SSL_REQUIRE_CLIENTAUTH_SUFFIX + "=" + pu.getSSLClientAuthRequired()));
                    }
                }
                final FilterChain puProtocolFilterChain = pu.getSSLPUFilterChainBuilder().add(new StompMessageFilter(this)).add(new StompMessageDispatchFilter(this)).build();
                StompProtocolFinder pf = new StompProtocolFinder();
                _sslpup = new PUProtocol(pf, puProtocolFilterChain);
            }
        }
    }
    if (_bc.doBind() && _tcpEnabled && pu == null) {
        _bc.registerService("stomp[TCP]", "stomp", TCPPORT, null);
    }
    if (_bc.doBind() && _sslEnabled && pu == null) {
        _bc.registerService("stomp[SSL/TLS]", "stomp", SSLPORT, null);
    }
    _inited = true;
}
Also used : Message(jakarta.jms.Message) InetSocketAddress(java.net.InetSocketAddress) StompProtocolFinder(com.sun.messaging.portunif.StompProtocolFinder) FilterChain(org.glassfish.grizzly.filterchain.FilterChain) Properties(java.util.Properties) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter) PUProtocol(org.glassfish.grizzly.portunif.PUProtocol) URL(java.net.URL) FileHandler(java.util.logging.FileHandler) LogSimpleFormatter(com.sun.messaging.bridge.api.LogSimpleFormatter) PUService(com.sun.messaging.portunif.PUService) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) FilterChainBuilder(org.glassfish.grizzly.filterchain.FilterChainBuilder) SSLFilter(org.glassfish.grizzly.ssl.SSLFilter)

Example 3 with PUService

use of com.sun.messaging.portunif.PUService in project openmq by eclipse-ee4j.

the class StompServer method start.

public synchronized void start() throws Exception {
    if (!_inited || (_bc.doBind() && _bc.getPUService() == null && _tcpTransport == null && _sslTransport == null) || (_bc.doBind() && _bc.getPUService() != null && _tcppup == null && _sslpup == null)) {
        String emsg = getStompBridgeResources().getKString(StompBridgeResources.X_STOMP_SERVER_NO_INIT);
        _logger.log(Level.SEVERE, emsg);
        throw new IllegalStateException(emsg);
    }
    if (!_bc.doBind()) {
        // to be implemented
        return;
    }
    PUService pu = (PUService) _bc.getPUService();
    if (pu != null) {
        try {
            if (_tcpEnabled) {
                pu.register(_tcppup, null);
                _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_START_TRANSPORT, "TCP", pu.getBindSocketAddress()));
            }
            if (_sslEnabled) {
                pu.registerSSL(_sslpup, null);
                _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_START_TRANSPORT, "SSL/TLS", pu.getBindSocketAddress()));
            }
        } catch (Exception e) {
            _logger.log(Level.SEVERE, e.getMessage(), e);
            try {
                stop();
            } catch (Exception ee) {
            }
            throw e;
        }
    } else {
        try {
            if (_tcpEnabled) {
                _tcpTransport.start();
                _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_START_TRANSPORT, "TCP", TCPHOSTNAMEPORT));
            }
            if (_sslEnabled) {
                _sslTransport.start();
                _logger.log(Level.INFO, getStompBridgeResources().getString(StompBridgeResources.I_START_TRANSPORT, "SSL/TLS", SSLHOSTNAMEPORT));
            }
        } catch (Exception e) {
            _logger.log(Level.SEVERE, e.getMessage(), e);
            try {
                stop();
            } catch (Exception ee) {
            }
            throw e;
        }
    }
}
Also used : PUService(com.sun.messaging.portunif.PUService)

Example 4 with PUService

use of com.sun.messaging.portunif.PUService in project openmq by eclipse-ee4j.

the class PortMapper method startPUService.

public synchronized void startPUService() throws Exception {
    PUService pu = Globals.getPUService();
    if (pu == null) {
        return;
    }
    if (sslEnabled) {
        List hosts = Globals.getConfig().getList(TCP_ALLOWED_HOSTNAMES_PROPERTY);
        if (hosts != null) {
            Iterator itr = hosts.iterator();
            while (itr.hasNext()) {
                String host = (String) itr.next();
                allowedHosts.add(BrokerMQAddress.createAddress(host, 7676).getHost());
            }
        }
    }
    pu.start();
}
Also used : PUService(com.sun.messaging.portunif.PUService) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with PUService

use of com.sun.messaging.portunif.PUService in project openmq by eclipse-ee4j.

the class PortMapper method bind.

/**
 * Bind the portmapper to the port unless we have configured the portmapper to expect some other component to do this on
 * our behalf
 */
public synchronized void bind() throws Exception {
    PUService pu = Globals.getPUService();
    if (sslEnabled && pu == null) {
        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.E_PROPERTY_SETTING_REQUIRES_PROPERTY, SSL_ENABLED_PROPERTY + "=true", Globals.PUSERVICE_ENABLED_PROP + "=true"));
    }
    if (doBind) {
        if (pu == null) {
            serverSocket = createPortMapperServerSocket(this.port, this.bindAddr);
        } else {
            try {
                pu.register(PortMapperMessageFilter.configurePortMapperProtocol(pu, this), this);
                if (sslEnabled) {
                    Properties props = KeystoreUtil.getDefaultSSLContextConfig("Broker[portpapper]", null);
                    pu.registerSSL(PortMapperMessageFilter.configurePortMapperSSLProtocol(pu, this, props, true), this);
                }
                pu.bind(new InetSocketAddress(this.bindAddr, this.port), backlog);
                logger.logToAll(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_PU_SERVICE_READY, "[" + (this.bindAddr == null ? "" : this.bindAddr) + ":" + this.port + "]" + (sslEnabled ? "TCP/SSL/TLS" : "TCP")));
            } catch (Exception e) {
                String emsg = "PU service failed to init";
                logger.logStack(logger.ERROR, emsg, e);
                throw new BrokerException(emsg);
            }
        }
    } else if (pu != null) {
        throw new BrokerException(Globals.PUSERVICE_ENABLED_PROP + "=true setting not allowed if nobind");
    }
}
Also used : PUService(com.sun.messaging.portunif.PUService) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Properties(java.util.Properties) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

PUService (com.sun.messaging.portunif.PUService)8 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 LockFile (com.sun.messaging.jmq.jmsserver.util.LockFile)2 Properties (java.util.Properties)2 LogSimpleFormatter (com.sun.messaging.bridge.api.LogSimpleFormatter)1 MQAddress (com.sun.messaging.jmq.io.MQAddress)1 BrokerMQAddress (com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)1 StompProtocolFinder (com.sun.messaging.portunif.StompProtocolFinder)1 Message (jakarta.jms.Message)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 FileHandler (java.util.logging.FileHandler)1 FilterChain (org.glassfish.grizzly.filterchain.FilterChain)1 FilterChainBuilder (org.glassfish.grizzly.filterchain.FilterChainBuilder)1 TransportFilter (org.glassfish.grizzly.filterchain.TransportFilter)1 PUProtocol (org.glassfish.grizzly.portunif.PUProtocol)1 SSLEngineConfigurator (org.glassfish.grizzly.ssl.SSLEngineConfigurator)1