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);
}
}
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;
}
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());
}
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);
}
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);
}
Aggregations