Search in sources :

Example 1 with JmsConfig

use of org.jaffa.modules.messaging.services.configdomain.JmsConfig in project jaffa-framework by jaffa-projects.

the class InitialContextFactrory method createInitialContext.

/**
 * Creates an InitialContext.
 *
 * @throws FrameworkException
 *           in case any internal error occurs.
 * @throws ApplicationExceptions
 *           Indicates application error(s).
 */
private void createInitialContext() throws FrameworkException, ApplicationExceptions {
    try {
        if (context == null) {
            JmsConfig jmsConfig = ConfigurationService.getInstance().getJmsConfig();
            if (jmsConfig != null && jmsConfig.getJndiContext() != null && jmsConfig.getJndiContext().getParam() != null) {
                Properties properties = new Properties();
                for (Param param : jmsConfig.getJndiContext().getParam()) properties.put(param.getName(), obtainParamValue(param));
                context = new InitialContext(properties);
            } else
                context = new InitialContext();
        }
    } catch (NamingException e) {
        LOGGER.error("Error in creating a JNDI InitialContext", e);
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.INITIAL_CONTEXT_ERROR, null, e);
    }
}
Also used : Param(org.jaffa.modules.messaging.services.configdomain.Param) NamingException(javax.naming.NamingException) JmsConfig(org.jaffa.modules.messaging.services.configdomain.JmsConfig) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 2 with JmsConfig

use of org.jaffa.modules.messaging.services.configdomain.JmsConfig in project jaffa-framework by jaffa-projects.

the class JaffaConnectionFactory method getConnectionFactory.

/**
 * Obtains the JMS ConnectionFactory from the JNDI context, as defined in the
 * configuration file.
 *
 * @throws FrameworkException
 *           in case any internal error occurs.
 * @throws ApplicationExceptions
 *           Indicates application error(s).
 * @return the JMS ConnectionFactory from the JNDI context, as defined in the
 *         configuration file.
 */
private ConnectionFactory getConnectionFactory() throws ApplicationExceptions, FrameworkException {
    ConnectionFactory factory = null;
    try {
        final InitialContext context = InitialContextFactrory.obtainInitialContext();
        final JmsConfig jmsConfig = ConfigurationService.getInstance().getJmsConfig();
        if (jmsConfig != null) {
            factory = (ConnectionFactory) context.lookup(jmsConfig.getConnectionFactory());
        }
    } catch (NamingException e) {
        LOGGER.error("Error in locating the JMS ConnectionFactory", e);
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.CONNECTION_FACTORY_NOT_FOUND, null, e);
    }
    return factory;
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) NamingException(javax.naming.NamingException) JmsConfig(org.jaffa.modules.messaging.services.configdomain.JmsConfig) InitialContext(javax.naming.InitialContext)

Example 3 with JmsConfig

use of org.jaffa.modules.messaging.services.configdomain.JmsConfig in project jaffa-framework by jaffa-projects.

the class ConfigurationServiceTest method testGetJmsConfig.

/**
 * Test of getJmsConfig method, of class org.jaffa.modules.messaging.services.ConfigurationService.
 */
public void testGetJmsConfig() {
    ConfigurationService configurationService = ConfigurationService.getInstance();
    assertNotNull("Should have received an instance of the ConfigurationService", configurationService);
    JmsConfig jmsConfig = ConfigurationService.getInstance().getJmsConfig();
    assertNotNull("Should have received an instance of the JmsConfig", jmsConfig);
    assertEquals("ConnectionFactory", jmsConfig.getConnectionFactory());
    assertEquals("someUser", jmsConfig.getUser());
    assertEquals("somePassword", jmsConfig.getPassword());
    JndiContext jndiContext = jmsConfig.getJndiContext();
    assertNotNull("Should have received an instance of the JndiContext", jndiContext);
    assertNotNull("The JndiContext should have a List of param elements", jndiContext.getParam());
    assertEquals("The JndiContext should have a List of 3 param elements", 3, jndiContext.getParam().size());
    assertEquals("java.naming.factory.initial", jndiContext.getParam().get(0).getName());
    assertEquals("org.jnp.interfaces.NamingContextFactory", jndiContext.getParam().get(0).getValue());
    assertEquals("java.naming.factory.url.pkgs", jndiContext.getParam().get(1).getName());
    assertEquals("org.jnp.interfaces", jndiContext.getParam().get(1).getValue());
    assertEquals("java.naming.provider.url", jndiContext.getParam().get(2).getName());
    assertEquals("localhost", jndiContext.getParam().get(2).getValue());
}
Also used : JndiContext(org.jaffa.modules.messaging.services.configdomain.JndiContext) JmsConfig(org.jaffa.modules.messaging.services.configdomain.JmsConfig)

Example 4 with JmsConfig

use of org.jaffa.modules.messaging.services.configdomain.JmsConfig in project jaffa-framework by jaffa-projects.

the class JndiJmsManager method registerResource.

/**
 * Unmarshall the contents of the configuration to create and register
 * JmsConfig objects.
 * @param resource the object that contains the xml config file.
 * @param context key with which config file to be registered.
 * @param variation key with which config file to be registered.
 * @throws JAXBException
 * @throws SAXException
 * @throws IOException
 */
@Override
public void registerResource(Resource resource, String context, String variation) throws JAXBException, SAXException, IOException {
    JndiConfig config = JAXBHelper.unmarshalConfigFile(JndiConfig.class, resource, JMS_JNDI_CONFIGURATION_SCHEMA_FILE);
    JmsConfig jmsConfig = config.getJmsConfig();
    populateJmsConfig(jmsConfig);
    ContextKey contextKey = new ContextKey(jmsConfig.getUser(), resource.getURI().toString(), variation, context);
    jmsRepository.register(contextKey, jmsConfig);
}
Also used : JndiConfig(org.jaffa.modules.messaging.services.configdomain.JndiConfig) ContextKey(org.jaffa.loader.ContextKey) JmsConfig(org.jaffa.modules.messaging.services.configdomain.JmsConfig)

Example 5 with JmsConfig

use of org.jaffa.modules.messaging.services.configdomain.JmsConfig in project jaffa-framework by jaffa-projects.

the class JndiJmsManager method unregisterResource.

/**
 * Unregister the JmsConfig objects defined by a particular resource.
 * @param resource the object that contains the xml config file.
 * @param context key with which config file to be registered.
 * @param variation key with which config file to be registered.
 * @throws JAXBException
 * @throws SAXException
 * @throws IOException
 */
@Override
public void unregisterResource(Resource resource, String context, String variation) throws JAXBException, SAXException, IOException {
    JndiConfig config = JAXBHelper.unmarshalConfigFile(JndiConfig.class, resource, JMS_JNDI_CONFIGURATION_SCHEMA_FILE);
    JmsConfig jmsConfig = config.getJmsConfig();
    ContextKey contextKey = new ContextKey(jmsConfig.getUser(), resource.getURI().toString(), variation, context);
    jmsRepository.unregister(contextKey);
}
Also used : JndiConfig(org.jaffa.modules.messaging.services.configdomain.JndiConfig) ContextKey(org.jaffa.loader.ContextKey) JmsConfig(org.jaffa.modules.messaging.services.configdomain.JmsConfig)

Aggregations

JmsConfig (org.jaffa.modules.messaging.services.configdomain.JmsConfig)6 NamingException (javax.naming.NamingException)3 ConnectionFactory (javax.jms.ConnectionFactory)2 InitialContext (javax.naming.InitialContext)2 ContextKey (org.jaffa.loader.ContextKey)2 JndiConfig (org.jaffa.modules.messaging.services.configdomain.JndiConfig)2 Properties (java.util.Properties)1 Connection (javax.jms.Connection)1 ExceptionListener (javax.jms.ExceptionListener)1 JMSException (javax.jms.JMSException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 JndiContext (org.jaffa.modules.messaging.services.configdomain.JndiContext)1 Param (org.jaffa.modules.messaging.services.configdomain.Param)1