Search in sources :

Example 1 with LogSimpleFormatter

use of com.sun.messaging.bridge.api.LogSimpleFormatter 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 2 with LogSimpleFormatter

use of com.sun.messaging.bridge.api.LogSimpleFormatter in project openmq by eclipse-ee4j.

the class JMSBridge method init.

public void init(BridgeContext bc, String name, boolean reset) throws Exception {
    _bc = bc;
    _name = name;
    _reset = reset;
    Properties props = bc.getConfig();
    String domain = props.getProperty(BridgeContext.BRIDGE_PROP_PREFIX);
    _xmlurl = props.getProperty(domain + PROP_XMLURL_SUFFIX);
    if (_xmlurl == null) {
        throw new IllegalArgumentException(_jbr.getKString(_jbr.X_NOT_SPECIFIED, _name, domain + PROP_XMLURL_SUFFIX));
    }
    _logger = Logger.getLogger(domain);
    if (bc.isSilentMode()) {
        _logger.setUseParentHandlers(false);
    }
    String var = bc.getRootDir();
    File dir = new File(var);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    String logfile = var + File.separator + "jms%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, _jbr.getString(_jbr.I_LOG_DOMAIN, _name, domain));
    _logger.log(Level.INFO, _jbr.getString(_jbr.I_LOG_FILE, _name, logfile) + "[" + limit + "," + count + "]");
    String lib = bc.getLibDir();
    if (lib == null) {
        throw new IllegalArgumentException("JMS bridge " + _name + " lib dir not specified");
    }
    String dtdd = lib + File.separator + "dtd" + File.separator;
    File dtddir = new File(dtdd);
    if (!dtddir.exists()) {
        throw new IllegalArgumentException(_jbr.getKString(_jbr.X_NOT_EXIST, _name, dtdd));
    }
    String sysid = dtddir.toURI().toURL().toString();
    String[] param = { _name, _xmlurl, sysid };
    _logger.log(Level.INFO, _jbr.getString(_jbr.I_INIT_JMSBRIDGE_WITH, param));
    JMSBridgeReader reader = new JMSBridgeReader(_xmlurl, sysid, _logger);
    _jmsbridge = reader.getJMSBridgeElement();
    if (!_name.equals(_jmsbridge.getName())) {
        String[] eparam = { _name, _jmsbridge.getName(), _xmlurl };
        throw new IllegalArgumentException(_jbr.getKString(_jbr.X_JMSBRIDGE_NAME_MISMATCH, eparam));
    }
    createBuiltInDMQ(_jmsbridge);
    Map<String, DMQElement> edmqs = _jmsbridge.getDMQs();
    for (Map.Entry<String, DMQElement> pair : edmqs.entrySet()) {
        if (pair.getKey().equals(DMQElement.BUILTIN_DMQ_NAME)) {
            continue;
        }
        createDMQ(pair.getValue(), _jmsbridge);
    }
    boolean xa = false;
    Map<String, LinkElement> elinks = _jmsbridge.getLinks();
    for (Map.Entry<String, LinkElement> pair : elinks.entrySet()) {
        xa |= createLink(pair.getValue(), _jmsbridge);
    }
    if (xa) {
        TransactionManagerAdapter tma = getTransactionManagerAdapter();
        if (tma.registerRM()) {
            Map<String, Refable> xacfs = new LinkedHashMap<>(_localXACFs);
            for (Map.Entry<String, Refable> pair : _allCF.entrySet()) {
                if (xacfs.get(pair.getKey()) != null) {
                    continue;
                }
                if (pair.getValue() instanceof XAConnectionFactory) {
                    xacfs.put(pair.getKey(), pair.getValue());
                }
            }
            String cfref = null;
            Refable cf = null;
            Map<String, ConnectionFactoryElement> cfs = _jmsbridge.getAllCF();
            for (Map.Entry<String, ConnectionFactoryElement> pair : cfs.entrySet()) {
                cfref = pair.getKey();
                if (xacfs.get(cfref) != null) {
                    continue;
                }
                try {
                    cf = createConnectionFactory(pair.getValue(), true);
                } catch (NotXAConnectionFactoryException e) {
                    _logger.log(Level.INFO, _jbr.getString(_jbr.I_CF_NOT_XA_NO_REGISTER, pair.getKey(), "XAConnectionFactory"));
                    continue;
                }
                if (cf == null) {
                    cf = new XAConnectionFactoryImpl(_bc, _jmsbridge.getCF(cfref).getProperties(), _bc.isEmbeded(), cfref, pair.getValue().isMultiRM());
                }
                xacfs.put(cfref, cf);
            }
            registerXAResources(xacfs);
        } else {
            Link link = null;
            for (Map.Entry<String, Link> pair : _links.entrySet()) {
                link = pair.getValue();
                if (link.isTransacted()) {
                    link.registerXAResources();
                }
            }
        }
    }
    _asyncStartExecutor = Executors.newSingleThreadExecutor();
}
Also used : Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap) LogSimpleFormatter(com.sun.messaging.bridge.api.LogSimpleFormatter) TransactionManagerAdapter(com.sun.messaging.bridge.service.jms.tx.TransactionManagerAdapter) FileHandler(java.util.logging.FileHandler) XAConnectionFactory(jakarta.jms.XAConnectionFactory) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with LogSimpleFormatter

use of com.sun.messaging.bridge.api.LogSimpleFormatter in project openmq by eclipse-ee4j.

the class JMSBridge method exportJMSBridgeStoreService.

public static Object exportJMSBridgeStoreService(Properties props) throws Exception {
    String bname = props.getProperty("jmsbridge");
    String instanceRootDir = props.getProperty("instanceRootDir");
    String reset = props.getProperty("reset", "true");
    String logdomain = props.getProperty("logdomain");
    if (instanceRootDir == null) {
        throw new IllegalArgumentException("instanceRootDir not found in " + props);
    }
    if (logdomain == null) {
        throw new IllegalArgumentException("logdomain property not found in " + props);
    }
    String rootDir = instanceRootDir + File.separator + "bridges";
    props.setProperty("txlogDirParent", rootDir);
    boolean doreset = Boolean.parseBoolean(reset);
    File dir = new File(rootDir);
    if (doreset && bname == null) {
        if (dir.exists()) {
            if (!dir.renameTo(new File(rootDir + ".save"))) {
                throw new IOException("Unable to rename existing directory " + rootDir + " to " + rootDir + ".save");
            }
        }
        return null;
    }
    if (bname == null) {
        if (!dir.exists()) {
            return null;
        }
        File[] files = dir.listFiles();
        if (files == null) {
            throw new IOException("Can't list files in " + rootDir);
        }
        if (files.length == 0) {
            return null;
        }
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                bname = files[i].getName();
                break;
            }
        }
        if (bname == null) {
            return null;
        }
        props.setProperty("jmsbridge", bname);
    }
    if (!dir.exists()) {
        dir.mkdirs();
    }
    Logger logger = Logger.getLogger(logdomain);
    props.setProperty("txlogDir", rootDir);
    props.setProperty("tmname", props.getProperty("identityName") + ":" + bname);
    props.setProperty("txlogSuffix", bname);
    String txlogDir = rootDir + File.separator + bname;
    props.setProperty("txlogDir", txlogDir);
    dir = new File(txlogDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    String logfile = dir + File.separator + "jms%g.log";
    FileHandler h = new FileHandler(logfile, true);
    h.setFormatter(new LogSimpleFormatter(logger));
    logger.addHandler(h);
    logger.log(Level.INFO, "Exported JMSBridgeStore txlogDir is " + txlogDir);
    logger.log(Level.INFO, "Exported JMSBridgeStore uses log domain: " + logdomain);
    logger.log(Level.INFO, "Exported JMSBridgeStore uses log file: " + logfile);
    FileTxLogImpl txlog = new FileTxLogImpl();
    txlog.setLogger(logger);
    txlog.init(props, doreset);
    return txlog;
}
Also used : LogSimpleFormatter(com.sun.messaging.bridge.api.LogSimpleFormatter) IOException(java.io.IOException) Logger(java.util.logging.Logger) FileTxLogImpl(com.sun.messaging.bridge.service.jms.tx.log.FileTxLogImpl) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Aggregations

LogSimpleFormatter (com.sun.messaging.bridge.api.LogSimpleFormatter)3 FileHandler (java.util.logging.FileHandler)3 File (java.io.File)2 Properties (java.util.Properties)2 TransactionManagerAdapter (com.sun.messaging.bridge.service.jms.tx.TransactionManagerAdapter)1 FileTxLogImpl (com.sun.messaging.bridge.service.jms.tx.log.FileTxLogImpl)1 PUService (com.sun.messaging.portunif.PUService)1 StompProtocolFinder (com.sun.messaging.portunif.StompProtocolFinder)1 Message (jakarta.jms.Message)1 XAConnectionFactory (jakarta.jms.XAConnectionFactory)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Logger (java.util.logging.Logger)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