Search in sources :

Example 1 with QueueInfo

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

the class MessageViewerTx method buildDto.

/**
 * Obtains the Message based on the messageMode and creates the output.
 */
private MessageViewerOutDto buildDto(MessageViewerInDto input) throws FrameworkException, ApplicationExceptions {
    try {
        Message message = findMessage(input);
        MessageViewerOutDto output = new MessageViewerOutDto();
        output.setJMSMessageID(input.getJMSMessageID());
        output.setError(message.getStringProperty(JmsBrowser.HEADER_ERROR_DETAILS));
        output.setPriority(new Long(message.getJMSPriority()));
        output.setHasPriorityAccess(JmsBrowser.hasChangePriorityAccess(message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_QUEUE_NAME)));
        output.setJMSDestination(message.getJMSDestination());
        output.setJMSDeliveryMode(message.getJMSDeliveryMode());
        output.setJMSTimestamp(message.getJMSTimestamp() != 0 ? new DateTime(message.getJMSTimestamp()) : null);
        output.setJMSCorrelationID(message.getJMSCorrelationID());
        output.setJMSReplyTo(message.getJMSReplyTo());
        try {
            output.setJMSRedelivered(message.getJMSRedelivered());
        } catch (Exception e) {
        // JBossMessaging throws "java.lang.IllegalStateException: This should never be called directly". Do nothing
        }
        output.setJMSType(message.getJMSType());
        output.setJMSExpiration(message.getJMSExpiration());
        if (message instanceof TextMessage)
            output.setPayLoad(((TextMessage) message).getText());
        // Generate a Map of header elements, keyed by the name of each header element
        // Ignore Error Details as we are showing it in a separate section
        Map<String, HeaderElementDto> headerElements = new LinkedHashMap<String, HeaderElementDto>();
        for (Enumeration e = message.getPropertyNames(); e.hasMoreElements(); ) {
            String name = (String) e.nextElement();
            if (!JmsBrowser.HEADER_ERROR_DETAILS.equals(name)) {
                String value = Formatter.format(message.getObjectProperty(name));
                HeaderElementDto headerElement = headerElements.get(name);
                if (headerElement == null) {
                    headerElement = new HeaderElementDto();
                    headerElement.setName(name);
                    headerElements.put(name, headerElement);
                }
                headerElement.setValue(value);
            }
        }
        // Add labels to the header-elements based on the QueueInfo
        // It is possible that a display-param points to a property on the Message (eg. JMSMessageID, JMSPriority etc.)
        // Use bean intropsection to extract the value of that property
        QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_QUEUE_NAME));
        if (queueInfo != null && queueInfo.getDisplayParam() != null) {
            for (DisplayParam displayParam : queueInfo.getDisplayParam()) {
                HeaderElementDto headerElement = headerElements.get(displayParam.getName());
                if (headerElement == null) {
                    try {
                        headerElement = new HeaderElementDto();
                        headerElement.setName(displayParam.getName());
                        headerElement.setLabel(displayParam.getLabel());
                        headerElements.put(displayParam.getName(), headerElement);
                        if (displayParam.getName().equals("JMSTimestamp")) {
                            String value = message.getJMSTimestamp() != 0 ? Formatter.format(new DateTime(message.getJMSTimestamp())) : null;
                            headerElement.setValue(value);
                        } else {
                            String value = Formatter.format(BeanHelper.getField(message, displayParam.getName()));
                            headerElement.setValue(value);
                        }
                    } catch (Exception e) {
                    // do nothing
                    }
                } else {
                    headerElement.setLabel(displayParam.getLabel());
                }
            }
        }
        output.setHeaderElements(headerElements.values().toArray(new HeaderElementDto[headerElements.values().size()]));
        buildBusinessEventLogDto(input, output, message);
        return output;
    } catch (JMSException e) {
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, null, e);
    }
}
Also used : MessageViewerOutDto(org.jaffa.modules.messaging.components.messageviewer.dto.MessageViewerOutDto) QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) Enumeration(java.util.Enumeration) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) JMSException(javax.jms.JMSException) DateTime(org.jaffa.datatypes.DateTime) FrameworkException(org.jaffa.exceptions.FrameworkException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) JMSException(javax.jms.JMSException) LinkedHashMap(java.util.LinkedHashMap) HeaderElementDto(org.jaffa.modules.messaging.components.messageviewer.dto.HeaderElementDto) DisplayParam(org.jaffa.modules.messaging.services.configdomain.DisplayParam) TextMessage(javax.jms.TextMessage)

Example 2 with QueueInfo

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

the class JmsQueueAdmin method createMessageGraph.

/**
 * Molds the input JMS Message into a MessageGraph.
 */
private static MessageGraph createMessageGraph(Message message, String queueName, PropertyFilter pf) throws JMSException, IntrospectionException {
    MessageGraph graph = new MessageGraph();
    graph.setQueueMetaData(createQueueMetaData(queueName, pf));
    if (pf.isFieldIncluded("type"))
        graph.setType(queueName);
    if (pf.isFieldIncluded("messageId"))
        graph.setMessageId(message.getJMSMessageID());
    if (pf.isFieldIncluded("priority"))
        graph.setPriority(new Long(message.getJMSPriority()));
    if (pf.isFieldIncluded("createdOn"))
        graph.setCreatedOn(message.getJMSTimestamp() != 0 ? new DateTime(message.getJMSTimestamp()) : null);
    if (pf.isFieldIncluded("createdBy"))
        graph.setCreatedBy(message.getStringProperty(JmsBrowser.HEADER_USER_ID));
    if (pf.isFieldIncluded("errorMessage"))
        graph.setErrorMessage(message.getStringProperty(JmsBrowser.HEADER_ERROR_DETAILS));
    if (pf.isFieldIncluded("payload") && message instanceof TextMessage)
        graph.setPayload(((TextMessage) message).getText());
    if (pf.isFieldIncluded("hasAdminAccess"))
        graph.setHasAdminAccess(JmsBrowser.hasAdminMessageAccess(queueName));
    if (pf.isFieldIncluded("applicationFields") || pf.isFieldIncluded("technicalFields")) {
        // Generate a Map of header elements, keyed by the name of each header element
        // Names beginning with JMS and jaffa_ will be treated as techincal, while the rest will be assumed to be application-specific
        Map<String, MessageField> applicationFields = new LinkedHashMap<String, MessageField>();
        Map<String, MessageField> technicalFields = new TreeMap<String, MessageField>();
        for (Enumeration e = message.getPropertyNames(); e.hasMoreElements(); ) {
            String name = (String) e.nextElement();
            String value = Formatter.format(message.getObjectProperty(name));
            MessageField messageField = new MessageField();
            messageField.setName(name);
            messageField.setValue(value);
            if (name.startsWith("JMS") || name.startsWith("jaffa_"))
                technicalFields.put(name, messageField);
            else
                applicationFields.put(name, messageField);
        }
        // Treat all the JMS* properties of the Message as technical
        if (pf.isFieldIncluded("technicalFields")) {
            BeanInfo beanInfo = Introspector.getBeanInfo(Message.class);
            if (beanInfo != null) {
                PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
                if (pds != null) {
                    for (PropertyDescriptor pd : pds) {
                        if (pd.getReadMethod() != null && !pd.getPropertyType().isArray()) {
                            String name = pd.getName();
                            try {
                                Object value = pd.getReadMethod().invoke(message);
                                MessageField messageField = new MessageField();
                                messageField.setName(name);
                                messageField.setValue(Formatter.format(value));
                                technicalFields.put(name, messageField);
                            } catch (Exception e) {
                                if (log.isDebugEnabled())
                                    log.debug("Exception thrown while reading Message property: " + name, e);
                            }
                        }
                    }
                }
            }
            if (!technicalFields.isEmpty())
                graph.setTechnicalFields(technicalFields.values().toArray(new MessageField[technicalFields.size()]));
        }
        // Add labels to the application-fields from the configuration-file
        if (pf.isFieldIncluded("applicationFields")) {
            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
            if (queueInfo != null && queueInfo.getDisplayParam() != null) {
                for (DisplayParam displayParam : queueInfo.getDisplayParam()) {
                    if (displayParam.getLabel() != null && applicationFields.containsKey(displayParam.getName()))
                        applicationFields.get(displayParam.getName()).setLabel(MessageHelper.replaceTokens(displayParam.getLabel()));
                }
            }
            if (!applicationFields.isEmpty())
                graph.setApplicationFields(applicationFields.values().toArray(new MessageField[applicationFields.size()]));
        }
    }
    return graph;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) Enumeration(java.util.Enumeration) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) TreeMap(java.util.TreeMap) DateTime(org.jaffa.datatypes.DateTime) MessageField(org.jaffa.qm.apis.data.MessageField) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) LinkedHashMap(java.util.LinkedHashMap) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) DisplayParam(org.jaffa.modules.messaging.services.configdomain.DisplayParam) TextMessage(javax.jms.TextMessage)

Example 3 with QueueInfo

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

the class JmsBrowser method getAccessibleQueueNames.

/**
 * Returns an array of queue names, as defined in the configuration file.
 * The array will contain the accessible queues only.
 * The error queue will not be included in this list.
 * @return an array of queue names, as defined in the configuration file.
 */
public static String[] getAccessibleQueueNames() {
    String[] queueNames = ConfigurationService.getInstance().getQueueNames();
    if (queueNames != null && queueNames.length > 0) {
        List<String> accessibleQueueNames = new LinkedList<String>();
        for (String queueName : queueNames) {
            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
            if (!queueInfo.isErrorQueue() && hasBrowseQueueAccess(queueInfo))
                accessibleQueueNames.add(queueName);
            else {
                if (log.isDebugEnabled() && !queueInfo.isErrorQueue())
                    log.debug("No browseQueue access to " + queueName);
            }
        }
        queueNames = accessibleQueueNames.toArray(new String[accessibleQueueNames.size()]);
    }
    return queueNames;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) LinkedList(java.util.LinkedList)

Example 4 with QueueInfo

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

the class ConfigurationServiceTest method testGetQueueInfo.

/**
 * Test of getQueueInfo method, of class org.jaffa.modules.messaging.services.ConfigurationService.
 */
public void testGetQueueInfo() {
    ConfigurationService configurationService = ConfigurationService.getInstance();
    assertNotNull("Should have received an instance of the ConfigurationService", configurationService);
    QueueInfo queueInfo = null;
    queueInfo = configurationService.getQueueInfo("jaffa/queue1");
    assertNotNull("Should have received a QueueInfo object for jaffa/queue1", queueInfo);
    assertEquals("jaffa/queue1", queueInfo.getName());
    assertEquals("single", queueInfo.getConsumerPolicy().value());
    assertFalse(queueInfo.isErrorQueue());
    assertNotNull("The queueInfo should have a List of display-param elements", queueInfo.getDisplayParam());
    assertEquals("The queueInfo should have a List of 2 display-param elements", 2, queueInfo.getDisplayParam().size());
    assertEquals("JMSMessageID", queueInfo.getDisplayParam().get(0).getName());
    assertEquals("Message ID", queueInfo.getDisplayParam().get(0).getLabel());
    assertEquals("JMSMessagePriority", queueInfo.getDisplayParam().get(1).getName());
    assertEquals("Message Priority", queueInfo.getDisplayParam().get(1).getLabel());
    queueInfo = configurationService.getQueueInfo("jaffa/queue2");
    assertNotNull("Should have received a QueueInfo object for jaffa/queue2", queueInfo);
    assertEquals("jaffa/queue2", queueInfo.getName());
    assertEquals("multi", queueInfo.getConsumerPolicy().value());
    assertFalse(queueInfo.isErrorQueue());
    assertNotNull("The queueInfo should have a List of display-param elements", queueInfo.getDisplayParam());
    assertEquals("The queueInfo should have a List of 2 display-param elements", 2, queueInfo.getDisplayParam().size());
    assertEquals("JMSMessageID", queueInfo.getDisplayParam().get(0).getName());
    assertEquals("Message ID", queueInfo.getDisplayParam().get(0).getLabel());
    assertEquals("JMSMessagePriority", queueInfo.getDisplayParam().get(1).getName());
    assertEquals("Message Priority", queueInfo.getDisplayParam().get(1).getLabel());
    queueInfo = configurationService.getQueueInfo("jaffa/errorQueue");
    assertNotNull("Should have received a QueueInfo object for jaffa/errorQueue", queueInfo);
    assertEquals("jaffa/errorQueue", queueInfo.getName());
    assertEquals("none", queueInfo.getConsumerPolicy().value());
    assertTrue(queueInfo.isErrorQueue());
    assertNotNull("The queueInfo should have a List of display-param elements", queueInfo.getDisplayParam());
    assertEquals("The queueInfo should have a List of 2 display-param elements", 2, queueInfo.getDisplayParam().size());
    assertEquals("JMSMessageID", queueInfo.getDisplayParam().get(0).getName());
    assertEquals("Message ID", queueInfo.getDisplayParam().get(0).getLabel());
    assertEquals("JMSMessagePriority", queueInfo.getDisplayParam().get(1).getName());
    assertEquals("Message Priority", queueInfo.getDisplayParam().get(1).getLabel());
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo)

Example 5 with QueueInfo

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

the class JmsQueueAdmin method createQueueMetaData.

/**
 * Creates MetaData for the input Queue, based on the available fields in the PropertyFilter.
 */
private static QueueMetaData createQueueMetaData(String queueName, PropertyFilter pf) {
    QueueMetaData qmd = null;
    if (pf.isFieldIncluded("queueMetaData")) {
        qmd = new QueueMetaData();
        if (pf.isFieldIncluded("queueMetaData.queueSystemId"))
            qmd.setQueueSystemId(QUEUE_SYSTEM_ID);
        if (pf.isFieldIncluded("queueMetaData.type"))
            qmd.setType(queueName);
        if (pf.isFieldIncluded("queueMetaData.supportedMessageStatus"))
            qmd.setSupportedMessageStatus(SUPPORTED_MESSAGE_STATUS);
        if (pf.isFieldIncluded("queueMetaData.supportedApplicationFields")) {
            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
            if (queueInfo != null && queueInfo.getDisplayParam() != null) {
                Collection<MessageFieldMetaData> supportedApplicationFields = new LinkedList<MessageFieldMetaData>();
                for (DisplayParam displayParam : queueInfo.getDisplayParam()) {
                    // Ignore fields that are included in the main graph or are part of the technical-details
                    if (displayParam.getName().startsWith("JMS") || displayParam.getName().startsWith("jaffa_"))
                        continue;
                    MessageFieldMetaData supportedApplicationField = new MessageFieldMetaData();
                    if (pf.isFieldIncluded("queueMetaData.supportedApplicationFields.name"))
                        supportedApplicationField.setName(displayParam.getName());
                    if (pf.isFieldIncluded("queueMetaData.supportedApplicationFields.label"))
                        supportedApplicationField.setLabel(MessageHelper.replaceTokens(displayParam.getLabel()));
                    supportedApplicationFields.add(supportedApplicationField);
                }
                if (!supportedApplicationFields.isEmpty())
                    qmd.setSupportedApplicationFields(supportedApplicationFields.toArray(new MessageFieldMetaData[supportedApplicationFields.size()]));
            }
        }
        if (pf.isFieldIncluded("queueMetaData.supportsTechnicalFields"))
            qmd.setSupportsTechnicalFields(SUPPORTS_TECHNICAL_FIELDS);
        if (pf.isFieldIncluded("queueMetaData.supportsBusinessEventLogs"))
            qmd.setSupportsBusinessEventLogs(SUPPORTS_BUSINESS_EVENT_LOGS);
        if (pf.isFieldIncluded("queueMetaData.supportsDependencies"))
            qmd.setSupportsDependencies(SUPPORTS_DEPENDENCIES);
    }
    return qmd;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) MessageFieldMetaData(org.jaffa.qm.apis.data.MessageFieldMetaData) QueueMetaData(org.jaffa.qm.apis.data.QueueMetaData) DisplayParam(org.jaffa.modules.messaging.services.configdomain.DisplayParam) LinkedList(java.util.LinkedList)

Aggregations

QueueInfo (org.jaffa.modules.messaging.services.configdomain.QueueInfo)7 LinkedList (java.util.LinkedList)4 JMSException (javax.jms.JMSException)4 TextMessage (javax.jms.TextMessage)4 Enumeration (java.util.Enumeration)3 Message (javax.jms.Message)3 DisplayParam (org.jaffa.modules.messaging.services.configdomain.DisplayParam)3 IntrospectionException (java.beans.IntrospectionException)2 LinkedHashMap (java.util.LinkedHashMap)2 DateTime (org.jaffa.datatypes.DateTime)2 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)2 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 TreeMap (java.util.TreeMap)1 Connection (javax.jms.Connection)1 InvalidSelectorException (javax.jms.InvalidSelectorException)1 QueueBrowser (javax.jms.QueueBrowser)1 Session (javax.jms.Session)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 HeaderElementDto (org.jaffa.modules.messaging.components.messageviewer.dto.HeaderElementDto)1