Search in sources :

Example 1 with MessageAdminResponse

use of org.jaffa.qm.apis.data.MessageAdminResponse in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method deleteMessage.

/**
 * NOTE: Each graph is expected to contain type, messageId and status. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
 */
public MessageAdminResponse[] deleteMessage(MessageGraph[] graphs) {
    if (log.isDebugEnabled())
        log.debug("Input to deleteMessage: " + Arrays.toString(graphs));
    Collection<MessageAdminResponse> output = null;
    String[] queueNames = null;
    for (MessageGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            // Initialize and sort the queueNames array; if not already done
            if (queueNames == null) {
                queueNames = ConfigurationService.getInstance().getQueueNames();
                Arrays.sort(queueNames);
            }
            if (Arrays.binarySearch(queueNames, graph.getType()) >= 0) {
                try {
                    if (graph.getStatus() == MessageGraph.Status.OPEN) {
                        if (log.isDebugEnabled())
                            log.debug("Deleting OPEN message " + graph.getMessageId());
                        JmsBrowser.deleteMessage(graph.getType(), graph.getMessageId());
                    } else if (graph.getStatus() == MessageGraph.Status.ERROR) {
                        if (log.isDebugEnabled())
                            log.debug("Deleting ERROR message " + graph.getMessageId());
                        JmsBrowser.deleteMessage(graph.getType(), graph.getMessageId());
                    } else {
                        if (log.isDebugEnabled())
                            log.debug("Message cannnot be deleted since unsupported status " + graph.getStatus() + " has been passed");
                    }
                } catch (Exception e) {
                    MessageAdminResponse response = new MessageAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled())
                            log.debug("Error while deleting Message " + graph, appExps);
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while deleting Message " + graph, e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null)
                        output = new LinkedList<MessageAdminResponse>();
                    output.add(response);
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Message " + graph + " will not be deleted by this implementation, since the queue does not belong to this implementation");
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("Message " + graph + " will not be deleted by this implementation, since the input queueSystemId does not match this system");
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from deleteMessage: " + output);
    return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException)

Example 2 with MessageAdminResponse

use of org.jaffa.qm.apis.data.MessageAdminResponse in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method resubmitMessage.

/**
 * NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
 */
public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) {
    if (log.isDebugEnabled()) {
        log.debug("Input to resubmitMessage: " + Arrays.toString(graphs));
    }
    Collection<MessageAdminResponse> output = null;
    String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
    Arrays.sort(types);
    for (MessageGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
                UOW uow = null;
                try {
                    String graphType = graph.getType();
                    String messageId = graph.getMessageId();
                    if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
                    }
                    uow = new UOW();
                    Transaction transaction = transactionDAO.getTransaction(messageId);
                    if (transaction != null) {
                        if (!TransactionEngine.getInstance().hasAdminAccess(transaction.getType())) {
                            throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transaction.getType() }));
                        }
                        if (Transaction.Status.E.toString().equals(transaction.getStatus())) {
                            if (log.isDebugEnabled()) {
                                log.debug("Resubmitting ERROR message " + messageId);
                            }
                            transaction.setStatus(Transaction.Status.O.toString());
                            transaction.setErrorMessage(null);
                            transactionDAO.save(uow, transaction);
                            uow.commit();
                        } else {
                            if (log.isDebugEnabled()) {
                                log.debug("Resubmission cannot be performed since message " + messageId + " is not in ERROR status anymore");
                            }
                        }
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Resubmission cannot be performed since message " + messageId + " not found");
                        }
                    }
                } catch (Exception e) {
                    MessageAdminResponse response = new MessageAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Error while resubmitting Message " + graph, appExps);
                        }
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while resubmitting Message " + graph, e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null) {
                        output = new LinkedList<MessageAdminResponse>();
                    }
                    output.add(response);
                } finally {
                    if (uow != null) {
                        try {
                            uow.rollback();
                        } catch (Exception ignore) {
                        }
                    }
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Message " + graph + " will not be resubmitted by this implementation, since the queue does not belong to this implementation");
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Message " + graph + " will not be resubmitted by this implementation, since the input queueSystemId does not match this system");
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from resubmitMessage: " + output);
    }
    return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) Transaction(org.jaffa.transaction.domain.Transaction) MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) UOW(org.jaffa.persistence.UOW) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) LinkedList(java.util.LinkedList)

Example 3 with MessageAdminResponse

use of org.jaffa.qm.apis.data.MessageAdminResponse in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method deleteMessage.

// ///////////////////////////////// Add in intercept for delete
/**
 * NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
 */
public MessageAdminResponse[] deleteMessage(MessageGraph[] graphs) {
    if (log.isDebugEnabled()) {
        log.debug("Input to deleteMessage: " + Arrays.toString(graphs));
    }
    Collection<MessageAdminResponse> output = null;
    String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
    Arrays.sort(types);
    for (MessageGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
                UOW uow = null;
                try {
                    String graphType = graph.getType();
                    String messageId = graph.getMessageId();
                    if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
                    }
                    uow = new UOW();
                    Transaction transaction = transactionDAO.getTransaction(messageId);
                    if (!TransactionEngine.getInstance().hasAdminAccess(transaction.getType())) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transaction.getType() }));
                    }
                    if (transaction != null) {
                        // Invoke Message Handler class to perform onDelete process
                        invokeHandler(uow, transaction, "onDelete");
                        if (log.isDebugEnabled()) {
                            log.debug("Deleting message " + messageId);
                        }
                        transactionDAO.delete(uow, transaction);
                        uow.commit();
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Delete cannot be performed since message " + messageId + " not found");
                        }
                    }
                } catch (Exception e) {
                    MessageAdminResponse response = new MessageAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Error while deleting Message " + graph, appExps);
                        }
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while deleting Message " + graph, e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null) {
                        output = new LinkedList<MessageAdminResponse>();
                    }
                    output.add(response);
                } finally {
                    if (uow != null) {
                        try {
                            uow.rollback();
                        } catch (Exception ignore) {
                        }
                    }
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Message " + graph + " will not be deleted by this implementation, since the queue does not belong to this implementation");
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Message " + graph + " will not be deleted by this implementation, since the input queueSystemId does not match this system");
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from deleteMessage: " + output);
    }
    return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) Transaction(org.jaffa.transaction.domain.Transaction) MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) UOW(org.jaffa.persistence.UOW) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) LinkedList(java.util.LinkedList)

Example 4 with MessageAdminResponse

use of org.jaffa.qm.apis.data.MessageAdminResponse in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method resubmitMessage.

/**
 * NOTE: Each graph is expected to contain type, messageId and status. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
 */
public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) {
    if (log.isDebugEnabled())
        log.debug("Input to resubmitMessage: " + Arrays.toString(graphs));
    Collection<MessageAdminResponse> output = null;
    String[] queueNames = null;
    for (MessageGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            // Initialize and sort the queueNames array; if not already done
            if (queueNames == null) {
                queueNames = ConfigurationService.getInstance().getQueueNames();
                Arrays.sort(queueNames);
            }
            if (Arrays.binarySearch(queueNames, graph.getType()) >= 0) {
                try {
                    if (graph.getStatus() == MessageGraph.Status.ERROR) {
                        if (log.isDebugEnabled())
                            log.debug("Resubmitting ERROR message " + graph.getMessageId());
                        JmsBrowser.resubmitMessage(graph.getType(), graph.getMessageId());
                    } else {
                        if (log.isDebugEnabled())
                            log.debug("Message cannnot be resubmitted since unsupported status " + graph.getStatus() + " has been passed");
                    }
                } catch (Exception e) {
                    MessageAdminResponse response = new MessageAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled())
                            log.debug("Error while resubmitting Message " + graph, appExps);
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while resubmitting Message " + graph, e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null)
                        output = new LinkedList<MessageAdminResponse>();
                    output.add(response);
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Message " + graph + " will not be resubmitted by this implementation, since the queue does not belong to this implementation");
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("Message " + graph + " will not be resubmitted by this implementation, since the input queueSystemId does not match this system");
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from resubmitMessage: " + output);
    return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException)

Example 5 with MessageAdminResponse

use of org.jaffa.qm.apis.data.MessageAdminResponse in project jaffa-framework by jaffa-projects.

the class QueueManager method resubmitMessage.

public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) {
    try {
        if (log.isDebugEnabled())
            log.debug("Input to resubmitMessage: " + graphs);
        MessageAdminResponse[] aggregateResponse = null;
        IQueueAdmin[] implementations = findImplementations();
        if (implementations != null && implementations.length > 0) {
            for (IQueueAdmin implementation : implementations) {
                MessageAdminResponse[] response = implementation.resubmitMessage(graphs);
                if (response != null && response.length > 0)
                    aggregateResponse = concatenate(aggregateResponse, response);
            }
        }
        if (log.isDebugEnabled())
            log.debug("Response from resubmitMessage: " + aggregateResponse);
        return aggregateResponse;
    } catch (Exception e) {
        log.error("Error in obtaining IQueueAdmin implementations", e);
        return new MessageAdminResponse[] { new MessageAdminResponse(null, ServiceError.generate(e)) };
    }
}
Also used : MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse)

Aggregations

MessageAdminResponse (org.jaffa.qm.apis.data.MessageAdminResponse)6 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)4 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)4 IntrospectionException (java.beans.IntrospectionException)2 LinkedList (java.util.LinkedList)2 JMSException (javax.jms.JMSException)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)2 UOW (org.jaffa.persistence.UOW)2 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)2 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)2 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)2 Transaction (org.jaffa.transaction.domain.Transaction)2