Search in sources :

Example 6 with MessageInfo

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

the class LockingService method deleteLockingMessages.

/**
 * Browses all messages in all the queues looking for the locks, as specified in the messageInfo for the input payload.
 * Deletes the matching messages.
 * @param payload Any serializable object.
 * @throws FrameworkException Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public static void deleteLockingMessages(Object payload) throws FrameworkException, ApplicationExceptions {
    try {
        // Reads the MessageConfig for the className of the input payload
        MessageInfo messageInfo = ConfigurationService.getInstance().getMessageInfo(payload.getClass().getName());
        if (messageInfo == null)
            throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() });
        // Obtain the messages
        deleteLockingMessages(payload, messageInfo);
    } catch (ClassNotFoundException e) {
        log.error("Error in locating the Message info for " + payload.getClass().getName(), e);
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() }, e);
    }
}
Also used : MessageInfo(org.jaffa.modules.messaging.services.configdomain.MessageInfo)

Example 7 with MessageInfo

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

the class LockingService method checkLock.

/**
 * Browses all messages in all the queues looking for the locks, as specified in the messageInfo for the input payload.
 * Throws an ApplicationException, if any matching message is found.
 * @param payload Any serializable object.
 * @throws FrameworkException Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public static void checkLock(Object payload) throws FrameworkException, ApplicationExceptions {
    try {
        // Reads the MessageConfig for the className of the input payload
        MessageInfo messageInfo = ConfigurationService.getInstance().getMessageInfo(payload.getClass().getName());
        if (messageInfo == null)
            throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() });
        // Perform the check
        checkLock(payload, messageInfo);
    } catch (ClassNotFoundException e) {
        log.error("Error in locating the Message info for " + payload.getClass().getName(), e);
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { payload.getClass().getName() }, e);
    }
}
Also used : MessageInfo(org.jaffa.modules.messaging.services.configdomain.MessageInfo)

Example 8 with MessageInfo

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

the class JmsBrowser method invokeHandler.

/**
 * Invokes the intended handler. This Handler must implement the IMessageHandler Interface in order to be invoked.
 *
 * @param message
 * @param methodName
 * @throws JaffaMessagingFrameworkException
 */
private static void invokeHandler(Message message, String methodName) throws JaffaMessagingFrameworkException {
    UOW uow = null;
    try {
        // Reads the MessageConfig from the ConfigurationService, based on the dataBeanClassName
        String dataBeanClassName = message.getStringProperty(JmsBrowser.HEADER_DATA_BEAN_CLASS_NAME);
        MessageInfo messageInfo = ConfigurationService.getInstance().getMessageInfo(dataBeanClassName);
        if (messageInfo == null)
            throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, new Object[] { dataBeanClassName });
        // Obtain the handlerClass
        Class handlerClass = Class.forName(messageInfo.getToClass());
        if (IMessageHandler.class.isAssignableFrom(handlerClass)) {
            // Unmarshals the Message payload into a dataBean using the dataBeanClassName
            Object payload = JAXBHelper.unmarshalPayload(obtainMessageContents(message), dataBeanClassName);
            if (log.isDebugEnabled())
                log.debug("Obtained payload for the dataBean " + dataBeanClassName + '\n' + payload);
            Method handlerMethod = null;
            Object handlerObject = null;
            // Obtain the handler method
            try {
                handlerMethod = handlerClass.getMethod(methodName, new Class[] { UOW.class, Map.class, Object.class });
            } catch (NoSuchMethodException e) {
                // Hence use the dataBeanClass specified in the messageInfo to get the appropriate handlerMethod
                if (log.isDebugEnabled())
                    log.debug(methodName + " method not found in " + handlerClass.getName());
                return;
            }
            handlerObject = handlerClass.newInstance();
            uow = new UOW();
            Map<String, String> headerMap = new HashMap<String, String>();
            // Sets the header elements as defined in the configuration file.
            if (messageInfo.getHeader() != null && messageInfo.getHeader().getParam() != null) {
                for (Param param : messageInfo.getHeader().getParam()) {
                    String headerValue = (String) message.getObjectProperty(param.getName());
                    headerMap.put(param.getName(), headerValue);
                }
            }
            handlerMethod.invoke(handlerObject, new Object[] { uow, headerMap, payload });
            uow.commit();
        }
    } catch (Exception e) {
        // Just log the error
        log.error("Exception thrown while deleting the message. Message was: " + message, e);
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.DELETE_ERROR, null, e);
    } finally {
        if (uow != null) {
            try {
                uow.rollback();
            } catch (Exception e) {
                throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.DELETE_ERROR, null, e);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) FrameworkException(org.jaffa.exceptions.FrameworkException) JMSException(javax.jms.JMSException) InvalidSelectorException(javax.jms.InvalidSelectorException) MessageInfo(org.jaffa.modules.messaging.services.configdomain.MessageInfo) Param(org.jaffa.modules.messaging.services.configdomain.Param) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MessageInfo (org.jaffa.modules.messaging.services.configdomain.MessageInfo)8 JMSException (javax.jms.JMSException)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 Param (org.jaffa.modules.messaging.services.configdomain.Param)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Connection (javax.jms.Connection)1 InvalidSelectorException (javax.jms.InvalidSelectorException)1 Message (javax.jms.Message)1 ObjectMessage (javax.jms.ObjectMessage)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 MessagingException (javax.mail.MessagingException)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 QueueViewerComponent (org.jaffa.modules.messaging.components.queueviewer.ui.QueueViewerComponent)1 UOW (org.jaffa.persistence.UOW)1 UserSessionSetupException (org.jaffa.presentation.portlet.session.UserSessionSetupException)1 EventMessage (org.jaffa.soa.services.event.EventMessage)1