Search in sources :

Example 1 with ConnectionFactory

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

the class CFObjectFactory method getObjectInstance.

/**
 * Creates an instance of the object represented by a Reference object.
 *
 * @param obj The Reference object.
 *
 * @return an instance of the class named in the Reference object <code>obj</code>,
 *         null if <code>obj</code> is not an instance of a Reference object.
 *
 * @throws MissingVersionNumberException if either <code>obj</code> references an object that is not an instance of a
 * <code>com.sun.messaging.Queue</code> object or the version number is missing from the Reference object.
 * @throws UnsupportedVersionNumberException if an unsupported version number is present in the Reference.
 * @throws CorruptedConfigurationPropertiesException if <code>obj</code> does not have the minimum information
 * neccessary to recreate an instance of a a valid <code>com.sun.messaging.AdministeredObject</code>.
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) throws Exception {
    if (obj instanceof Reference) {
        Reference ref = (Reference) obj;
        String refClassName = ref.getClassName();
        ConnectionFactory cf;
        if (refClassName.equals(com.sun.messaging.QueueConnectionFactory.class.getName())) {
            cf = new QueueConnectionFactory();
        } else {
            if (refClassName.equals(com.sun.messaging.TopicConnectionFactory.class.getName())) {
                cf = new TopicConnectionFactory();
            } else {
                throw new MissingVersionNumberException();
            }
        }
        // version number MUST exist and it MUST be the same as AO_VERSION_STR_JMQ1
        RefAddr versionAddr = ref.get(REF_VERSION);
        if (versionAddr == null) {
            // version number does not exist
            throw new MissingVersionNumberException();
        } else {
            // version number does not match
            String version = null;
            if (!AO_VERSION_STR_JMQ1.equals(version = (String) versionAddr.getContent())) {
                throw new UnsupportedVersionNumberException(version);
            }
            cf.setStoredVersion(version);
        }
        // retreive the security port value from the Reference
        RefAddr securityPortAddr = ref.get(REF_SECURITYPORT);
        if (securityPortAddr != null) {
            securityPortAddr.getContent();
        } else {
            // securityPort is missing - corrupted?
            throw new CorruptedConfigurationPropertiesException();
        }
        /*
             * try { parm = (String) (((RefAddr)ref.get(REF_PARM)).getContent()); host = (String)
             * (((RefAddr)ref.get(REF_HOST)).getContent()); subnet = (String) (((RefAddr)ref.get(REF_SUBNET)).getContent());
             * ackTimeout = (String) (((RefAddr)ref.get(REF_ACKTIMEOUT)).getContent()); } catch (NullPointerException e) { // this
             * should NOT happen under normal operations // this will happen when the object was modified outside // of its intended
             * use throw new CorruptedConfigurationPropertiesException(); }
             */
        recreateConfigurationObject(cf, ref);
        setJMSXProperties(cf, ref);
        return cf;
    }
    return null;
}
Also used : RefAddr(javax.naming.RefAddr) TopicConnectionFactory(com.sun.messaging.TopicConnectionFactory) TopicConnectionFactory(com.sun.messaging.TopicConnectionFactory) ConnectionFactory(com.sun.messaging.ConnectionFactory) QueueConnectionFactory(com.sun.messaging.QueueConnectionFactory) Reference(javax.naming.Reference) QueueConnectionFactory(com.sun.messaging.QueueConnectionFactory)

Example 2 with ConnectionFactory

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

the class ReceiveSOAPMessageWithJMS method init.

/**
 * JMS Connection/Session/Destination/MessageListener set ups.
 */
public void init(String topicName) {
    try {
        /**
         * construct a default SOAP message factory.
         */
        messageFactory = MessageFactory.newInstance();
        /**
         * JMS set up.
         */
        connectionFactory = new com.sun.messaging.ConnectionFactory();
        connection = connectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        topic = session.createTopic(topicName);
        msgConsumer = session.createConsumer(topic);
        msgConsumer.setMessageListener(this);
        connection.start();
        System.out.println("ready to receive SOAP messages ...");
    } catch (Exception jmse) {
        jmse.printStackTrace();
    }
}
Also used : ConnectionFactory(com.sun.messaging.ConnectionFactory)

Example 3 with ConnectionFactory

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

the class BridgeServiceManagerImpl method start.

/**
 * Start the bridge service manager
 */
@Override
public synchronized void start() throws Exception {
    if (_bc == null || _state == State.UNINITIALIZED) {
        throw new BridgeException(_bmr.getString(_bmr.X_BRIDGE_SERVICE_MANAGER_NOT_INITED));
    }
    _state = State.STARTING;
    Properties props = _bc.getBridgeConfig();
    try {
        Bridge b = null;
        String name = null;
        for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
            b = pair.getValue();
            name = b.getName();
            String autostart = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + name + ".autostart", "true");
            boolean doautostart = Boolean.valueOf(autostart);
            try {
                if (doautostart) {
                    String[] args = null;
                    if (_bc.isStartWithReset()) {
                        args = new String[] { "-reset" };
                    }
                    startBridge(b, args);
                }
            } catch (BridgeException e) {
                if (e.getStatus() == Status.CREATED) {
                    continue;
                }
                throw e;
            }
        }
    } catch (Exception e) {
        try {
            stopBridge(null, null, null);
        } catch (Throwable t) {
        }
        throw e;
    }
    try {
        var _cf = new ConnectionFactory();
        _cf.setProperty(com.sun.messaging.ConnectionConfiguration.imqAddressList, _bc.getBrokerServiceAddress("tcp", com.sun.messaging.jmq.ClientConstants.CONNECTIONTYPE_ADMIN));
        _cf.setProperty(com.sun.messaging.ConnectionConfiguration.imqReconnectEnabled, "false");
        _connection = _cf.createConnection(_user, _passwd);
        _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        _adminQueue = _session.createTemporaryQueue();
        MessageConsumer mc = _session.createConsumer(_adminQueue);
        mc.setMessageListener(this);
        _connection.start();
    } catch (Exception e) {
        try {
            stopBridge(null, null, null);
            if (_connection != null) {
                _connection.close();
            }
        } catch (Throwable t) {
        }
        throw e;
    }
    _state = State.STARTED;
}
Also used : Properties(java.util.Properties) BridgeException(com.sun.messaging.bridge.api.BridgeException) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) BridgeException(com.sun.messaging.bridge.api.BridgeException) ConnectionFactory(com.sun.messaging.ConnectionFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Bridge(com.sun.messaging.bridge.api.Bridge)

Aggregations

ConnectionFactory (com.sun.messaging.ConnectionFactory)3 QueueConnectionFactory (com.sun.messaging.QueueConnectionFactory)1 TopicConnectionFactory (com.sun.messaging.TopicConnectionFactory)1 Bridge (com.sun.messaging.bridge.api.Bridge)1 BridgeException (com.sun.messaging.bridge.api.BridgeException)1 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 RefAddr (javax.naming.RefAddr)1 Reference (javax.naming.Reference)1