From: <rk...@us...> - 2011-11-22 16:42:54
|
Revision: 5742 http://jaffa.svn.sourceforge.net/jaffa/?rev=5742&view=rev Author: rkisson Date: 2011-11-22 16:42:47 +0000 (Tue, 22 Nov 2011) Log Message: ----------- Added in a plug able interface to intercept and perform an operation during the deletion of a transaction Modified Paths: -------------- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsClientHelper.java branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/scheduler/services/quartz/JaffaTransactionInvokerJob.java branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/TransactionAdmin.java Added Paths: ----------- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/common/ branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/common/IMessageHandler.java branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/JaffaTransactionFrameworkException.java Added: branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/common/IMessageHandler.java =================================================================== --- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/common/IMessageHandler.java (rev 0) +++ branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/common/IMessageHandler.java 2011-11-22 16:42:47 UTC (rev 5742) @@ -0,0 +1,73 @@ +/* + * ==================================================================== + * JAFFA - Java Application Framework For All + * + * Copyright (C) 2002 JAFFA Development Group + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Redistribution and use of this software and associated documentation ("Software"), + * with or without modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain copyright statements and notices. + * Redistributions must also contain a copy of this document. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name "JAFFA" must not be used to endorse or promote products derived from + * this Software without prior written permission. For written permission, + * please contact mail to: jaf...@ya.... + * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" + * appear in their names without prior written permission. + * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ + +package org.jaffa.modules.common; + +import java.util.Map; + +import org.jaffa.exceptions.ApplicationExceptions; +import org.jaffa.exceptions.FrameworkException; +import org.jaffa.persistence.UOW; + +/** A interface to plug in to events of a message. + */ +public interface IMessageHandler { + + + /** + * Provides a plug able method during the deletion of a message + * @param uow + * @param messageHeaders + * @param payload + * @throws ApplicationExceptions + * @throws FrameworkException + */ + public void onDelete(UOW uow, Map<String,String> messageHeaders, Object payload) throws ApplicationExceptions, FrameworkException; + +} Modified: branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsClientHelper.java =================================================================== --- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsClientHelper.java 2011-11-21 20:27:49 UTC (rev 5741) +++ branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/messaging/services/JmsClientHelper.java 2011-11-22 16:42:47 UTC (rev 5742) @@ -398,27 +398,7 @@ } } - /** Returns the value from the input Param object. - * Uses BSF to evaluate the value, in case its an expression. - * @param param the Param object. - * @param bean the bean to be used in the context of BSF. - * @return the value from the input Param object. - * @throws FrameworkException in case any internal error occurs. - * @throws ApplicationExceptions Indicates application error(s). - */ - static Object obtainParamValue(Param param, Object bean) throws FrameworkException, ApplicationExceptions { - Object value = param.getValue(); - if (param.isExpression()) { - try { - value = ScriptHelper.instance(param.getLanguage()).evaluate(null, param.getValue(), bean, null, 0, 0); - if (log.isDebugEnabled()) - log.debug("Evaluation of the expression '" + param.getValue() + "' is: " + value); - } catch (Exception e) { - throw ExceptionHelper.throwAFR(e); - } - } - return value; - } + /** Throws an UnsupportedOperationException if this instance is reused after a commit/rollback. */ @@ -809,4 +789,26 @@ throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.PAYLOAD_ERROR, null, e); } } + + /** Returns the value from the input Param object. + * Uses BSF to evaluate the value, in case its an expression. + * @param param the Param object. + * @param bean the bean to be used in the context of BSF. + * @return the value from the input Param object. + * @throws FrameworkException in case any internal error occurs. + * @throws ApplicationExceptions Indicates application error(s). + */ + static Object obtainParamValue(Param param, Object bean) throws FrameworkException, ApplicationExceptions { + Object value = param.getValue(); + if (param.isExpression()) { + try { + value = ScriptHelper.instance(param.getLanguage()).evaluate(null, param.getValue(), bean, null, 0, 0); + if (log.isDebugEnabled()) + log.debug("Evaluation of the expression '" + param.getValue() + "' is: " + value); + } catch (Exception e) { + throw ExceptionHelper.throwAFR(e); + } + } + return value; + } } Modified: branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/scheduler/services/quartz/JaffaTransactionInvokerJob.java =================================================================== --- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/scheduler/services/quartz/JaffaTransactionInvokerJob.java 2011-11-21 20:27:49 UTC (rev 5741) +++ branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/modules/scheduler/services/quartz/JaffaTransactionInvokerJob.java 2011-11-22 16:42:47 UTC (rev 5742) @@ -62,7 +62,7 @@ import org.quartz.JobExecutionException; /** - * The JmsInvokerJob will be called by the Quartz scheduler + * The JaffaTransactionInvokerJob will be called by the Quartz scheduler * It will then determine use the JobDataMap to retrieve the job information * and send an appropriate JMS message. */ Added: branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/JaffaTransactionFrameworkException.java =================================================================== --- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/JaffaTransactionFrameworkException.java (rev 0) +++ branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/JaffaTransactionFrameworkException.java 2011-11-22 16:42:47 UTC (rev 5742) @@ -0,0 +1,84 @@ +/* + * ==================================================================== + * JAFFA - Java Application Framework For All + * + * Copyright (C) 2002 JAFFA Development Group + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Redistribution and use of this software and associated documentation ("Software"), + * with or without modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain copyright statements and notices. + * Redistributions must also contain a copy of this document. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name "JAFFA" must not be used to endorse or promote products derived from + * this Software without prior written permission. For written permission, + * please contact mail to: jaf...@ya.... + * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" + * appear in their names without prior written permission. + * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ +package org.jaffa.transaction.services; + +import org.jaffa.exceptions.FrameworkException; + +/** This FrameworkException will be thrown by the JaffaMessaging module for various internal error conditions. + */ +public class JaffaTransactionFrameworkException extends FrameworkException { + + private static final String BASE_CODE = "exception.org.jaffa.transaction.services.JaffaTransactionFrameworkException."; + public static final String TRANSACTION_INFO_MISSING = BASE_CODE+"transactionInfoMissing"; + + + /** Constructs a new Exception. + * @param errorCode the errorCode. + */ + public JaffaTransactionFrameworkException(String errorCode) { + this(errorCode, null); + } + + /** Constructs a new Exception. + * @param errorCode the errorCode. + * @param arguments the arguments, if any, that need to be merged into the error message from the resource bundle. + */ + public JaffaTransactionFrameworkException(String errorCode, Object[] arguments) { + this(errorCode, arguments, null); + } + + /** Constructs a new Exception. + * @param errorCode the errorCode. + * @param arguments the arguments, if any, that need to be merged into the error message from the resource bundle. + * @param cause the cause. + */ + public JaffaTransactionFrameworkException(String errorCode, Object[] arguments, Throwable cause) { + super(errorCode, arguments); + } +} Modified: branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/TransactionAdmin.java =================================================================== --- branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/TransactionAdmin.java 2011-11-21 20:27:49 UTC (rev 5741) +++ branches/JAFFA_5_10_FEATURE/JaffaSOA/source/java/org/jaffa/transaction/services/TransactionAdmin.java 2011-11-22 16:42:47 UTC (rev 5742) @@ -48,12 +48,15 @@ */ package org.jaffa.transaction.services; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; + import org.apache.log4j.Logger; import org.jaffa.components.finder.FinderTx; import org.jaffa.components.finder.StringCriteriaField; @@ -61,6 +64,8 @@ import org.jaffa.exceptions.ApplicationException; import org.jaffa.exceptions.ApplicationExceptions; import org.jaffa.exceptions.FrameworkException; +import org.jaffa.modules.common.IMessageHandler; +import org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException; import org.jaffa.modules.messaging.services.JmsBrowser; import org.jaffa.persistence.Criteria; import org.jaffa.persistence.UOW; @@ -85,7 +90,9 @@ import org.jaffa.transaction.domain.TransactionField; import org.jaffa.transaction.domain.TransactionFieldMeta; import org.jaffa.transaction.domain.TransactionMeta; +import org.jaffa.transaction.domain.TransactionPayload; import org.jaffa.transaction.services.configdomain.DisplayParam; +import org.jaffa.transaction.services.configdomain.TransactionInfo; import org.jaffa.transaction.services.configdomain.TypeInfo; import org.jaffa.util.ExceptionHelper; import org.jaffa.util.MessageHelper; @@ -391,6 +398,8 @@ return output != null && output.size() > 0 ? output.toArray(new QueueAdminResponse[output.size()]) : null; } + + /////////////////////////////////// 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. */ @@ -417,6 +426,8 @@ Transaction transaction = (Transaction) i.next(); if (!TransactionEngine.getInstance().hasAdminAccess(transaction.getType())) throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[]{transaction.getType()})); + //Invoke Message Handler class to perform onDelete process + invokeHandler(uow,transaction,"onDelete"); if (log.isDebugEnabled()) log.debug("Deleting message " + graph.getMessageId()); uow.delete(transaction); @@ -730,4 +741,68 @@ transactionStatusCriteriaField = messageStatusCriteriaField; return transactionStatusCriteriaField; } + + + /** + * 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(UOW uow, Transaction transaction, String methodName) throws Exception { + + try { + TransactionPayload tp = transaction.getTransactionPayloadObject(); + Object dataBean = tp != null ? tp.moldInternalPayload() : null; + if (dataBean != null) { + //Load transaction configuration + + TransactionInfo transactionInfo = ConfigurationService.getInstance().getTransactionInfo(tp.getInternalMessageClass()); + if (transactionInfo == null) + throw new JaffaMessagingFrameworkException(JaffaTransactionFrameworkException.TRANSACTION_INFO_MISSING, new Object[]{tp.getInternalMessageClass()}); + + // Obtain the handlerClass + Class handlerClass = Class.forName(transactionInfo.getToClass()); + //Class dataBeanClass = Class.forName(transactionInfo.getDataBean()); + if(IMessageHandler.class.isAssignableFrom(handlerClass)) { + // Unmarshals the Message payload into a dataBean using the dataBeanClassName + + 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) { + // Note that the payload could be a subclass of the argument that the handler method expects + // 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(); + + Map<String,String> headerMap = new HashMap<String,String>(); + // Sets the transactionField elements as defined in the configuration file. + + TransactionField[] fields = transaction.getTransactionFieldArray(); + if(fields!=null) { + for (TransactionField field : fields) { + headerMap.put(field.getFieldName(), field.getValue()); + } + } + // Invoke the handler + if (log.isDebugEnabled()) + log.debug("Invoking the handler " + handlerMethod); + handlerMethod.invoke(handlerObject, new Object[]{uow, headerMap, dataBean}); + } + } + } + catch (Exception e) { + // Just log the error + log.error("Exception thrown while deleting the transaction. Transaction was: " + transaction, e); + throw e; + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |