Author: ruwan Date: Thu Jan 22 09:21:53 2009 New Revision: 29272 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=29272
Log: XA mediator (modified path from irantha) Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorFactory.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorSerializer.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transaction/ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transaction/TransactionMediator.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfiguration.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfigurationBuilder.java branches/synapse/1.2.wso2v1/modules/core/src/test/java/org/apache/synapse/config/xml/TransactionMediatorSerializationTest.java Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=29272&r1=29271&r2=29272&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Thu Jan 22 09:21:53 2009 @@ -43,6 +43,7 @@ import org.apache.synapse.task.TaskDescriptionRepositoryFactory; import org.apache.synapse.task.TaskScheduler; import org.apache.synapse.task.TaskSchedulerFactory; +import org.apache.ws.commons.transactions.TransactionConfiguration; import javax.xml.namespace.QName; import java.io.IOException; @@ -122,6 +123,11 @@ private Map<String, SynapseEventSource> eventSources = new HashMap<String, SynapseEventSource>(); /** + * Transaction Configuration + */ + private TransactionConfiguration transactionConfiguration = null; + + /** * Add a named sequence into the local registry * * @param key @@ -974,6 +980,14 @@ this.eventSources = eventSources; } + public TransactionConfiguration getTransactionConfiguration(){ + return transactionConfiguration; + } + + public void setTransactionConfiguration(TransactionConfiguration transactionConfiguration){ + this.transactionConfiguration = transactionConfiguration; + } + private void assertAlreadyExists(String key, String type) { if (key == null || "".equals(key)) { Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=29272&r1=29271&r2=29272&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java Thu Jan 22 09:21:53 2009 @@ -24,8 +24,8 @@ import org.apache.axiom.om.OMNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.synapse.SynapseException; import org.apache.synapse.Mediator; +import org.apache.synapse.SynapseException; import org.apache.synapse.config.XMLToObjectMapper; import org.apache.synapse.config.xml.eventing.EventPublisherMediatorFactory; import sun.misc.Service; @@ -49,7 +49,7 @@ private static final Class[] mediatorFactories = { SequenceMediatorFactory.class, LogMediatorFactory.class, - SendMediatorFactory.class, + SendMediatorFactory.class, FilterMediatorFactory.class, SynapseMediatorFactory.class, DropMediatorFactory.class, @@ -59,7 +59,7 @@ SwitchMediatorFactory.class, InMediatorFactory.class, OutMediatorFactory.class, - RMSequenceMediatorFactory.class, + RMSequenceMediatorFactory.class, ClassMediatorFactory.class, ValidateMediatorFactory.class, XSLTMediatorFactory.class, @@ -72,7 +72,8 @@ DBLookupMediatorFactory.class, CacheMediatorFactory.class, CalloutMediatorFactory.class, - EventPublisherMediatorFactory.class + EventPublisherMediatorFactory.class, + TransactionMediatorFactory.class }; private static MediatorFactoryFinder instance = null; Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java?rev=29272&r1=29271&r2=29272&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java Thu Jan 22 09:21:53 2009 @@ -59,7 +59,8 @@ DBReportMediatorSerializer.class, CacheMediatorSerializer.class, CalloutMediatorSerializer.class, - EventPublisherMediatorSerializer.class + EventPublisherMediatorSerializer.class, + TransactionMediatorSerializer.class }; private static MediatorSerializerFinder instance = null; Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorFactory.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorFactory.java?pathrev=29272 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorFactory.java Thu Jan 22 09:21:53 2009 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.synapse.config.xml; + +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.synapse.Mediator; +import org.apache.synapse.mediators.transaction.TransactionMediator; + +import javax.xml.namespace.QName; + +/** + * The Factory for create transaction mediator- InLine XML need to provide + * <p/> + * <pre> + * <transaction action="new|use-existing-or-new|fault-if-no-tx|commit|rollback|suspend|resume" /> + * <p/> + * <p/> + */ +public class TransactionMediatorFactory extends AbstractMediatorFactory { + + private static final Log log = LogFactory.getLog(TransactionMediatorFactory.class); + + private static final QName TAG_NAME = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "transaction"); + + /** + * Create a Transaction mediator instance referring to the bean and configuration given + * by the OMElement declaration + * + * @param elem the OMElement that specifies the Transaction mediator configuration + * @return the Transaction mediator instance created + */ + public Mediator createMediator(OMElement elem) { + + TransactionMediator tm = new TransactionMediator(); + OMAttribute action = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "action")); + + if (action == null) { + handleException("The 'action' attribute is required for Transaction mediator definition"); + } else { + + // after successfully creating the mediator + // set its common attributes such as tracing etc + processTraceState(tm, elem); + tm.setAction(action.getAttributeValue()); + + return tm; + } + + return null; + } + + public QName getTagQName() { + return TAG_NAME; + } + +} Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorSerializer.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorSerializer.java?pathrev=29272 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/TransactionMediatorSerializer.java Thu Jan 22 09:21:53 2009 @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.synapse.config.xml; + +import org.apache.axiom.om.OMElement; +import org.apache.synapse.Mediator; +import org.apache.synapse.config.xml.endpoints.EndpointSerializer; +import org.apache.synapse.endpoints.Endpoint; +import org.apache.synapse.mediators.builtin.SendMediator; +import org.apache.synapse.mediators.transaction.TransactionMediator; + +/** + * Serializer for {...@link org.apache.synapse.mediators.transaction.TransactionMediator} instances. + * + * @see org.apache.synapse.config.xml.TransactionMediatorFactory + */ +public class TransactionMediatorSerializer extends AbstractMediatorSerializer { + + public OMElement serializeMediator(OMElement parent, Mediator m) { + + if (!(m instanceof TransactionMediator)) { + handleException("Unsupported mediator passed in for serialization : " + m.getType()); + } + + TransactionMediator mediator = (TransactionMediator) m; + OMElement transaction = fac.createOMElement("transaction", synNS); + transaction.addAttribute(fac.createOMAttribute("action", nullNS, mediator.getAction())); + + saveTracingState(transaction, mediator); + + if (parent != null) { + parent.addChild(transaction); + } + return transaction; + } + + public String getMediatorClassName() { + return TransactionMediator.class.getName(); + } +} Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java?rev=29272&r1=29271&r2=29272&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java Thu Jan 22 09:21:53 2009 @@ -41,6 +41,8 @@ import org.apache.synapse.eventing.SynapseEventSource; import org.apache.synapse.format.BinaryBuilder; import org.apache.synapse.format.PlainTextBuilder; +import org.apache.ws.commons.transactions.TransactionConfiguration; +import org.apache.ws.commons.transactions.TransactionConfigurationBuilder; import java.net.InetAddress; import java.net.UnknownHostException; @@ -111,9 +113,18 @@ synCfg.addEntry(SynapseConstants.SERVER_IP, entry); } + //init transaction Configuration + AxisConfiguration axisCfg = configurationContext.getAxisConfiguration(); + Parameter txCfgParameter = axisCfg.getParameter("JtaTransactionInfo"); + + if (txCfgParameter != null) { + TransactionConfiguration txCfg = + TransactionConfigurationBuilder.buildConfiguration(txCfgParameter); + synCfg.setTransactionConfiguration(txCfg); + } + log.info("Deploying the Synapse service.."); // Dynamically initialize the Synapse Service and deploy it into Axis2 - AxisConfiguration axisCfg = configurationContext.getAxisConfiguration(); AxisService synapseService = new AxisService(SynapseConstants.SYNAPSE_SERVICE_NAME); AxisOperation mediateOperation = new InOutAxisOperation( SynapseConstants.SYNAPSE_OPERATION_NAME); @@ -169,6 +180,7 @@ for (SynapseEventSource eventSource : synCfg.getEventSources()) { eventSource.buildService(axisCfg); } + synCfg.init(configurationContext); log.info("Synapse initialized successfully...!"); Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java?rev=29272&r1=29271&r2=29272&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java (original) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java Thu Jan 22 09:21:53 2009 @@ -52,9 +52,9 @@ "No rows were inserted for statement : " + stmnt.getRawStatement()); } } - if (!con.getAutoCommit()) { - con.commit(); - } +// if (!con.getAutoCommit()) { +// con.commit(); +// } } catch (SQLException e) { handleException("Error execuring insert statement : " + stmnt.getRawStatement() + Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transaction/TransactionMediator.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transaction/TransactionMediator.java?pathrev=29272 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transaction/TransactionMediator.java Thu Jan 22 09:21:53 2009 @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.synapse.mediators.transaction; + +import org.apache.axis2.AxisFault; +import org.apache.synapse.MessageContext; +import org.apache.synapse.SynapseException; +import org.apache.synapse.mediators.AbstractMediator; + +import javax.transaction.Status; +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; + + +/** + * The Mediator for commit, rollback, suspend, resume jta transactions + */ +public class TransactionMediator extends AbstractMediator { + + public static final String ACTION_COMMIT = "commit"; + public static final String ACTION_ROLLBACK = "rollback"; + public static final String ACTION_SUSPEND = "suspend"; + public static final String ACTION_RESUME = "resume"; + public static final String ACTION_NEW = "new"; + public static final String ACTION_USE_EXISTING_OR_NEW = "use-existing-or-new"; + public static final String ACTION_FAULT_IF_NO_TX = "fault-if-no-tx"; + public static final String SUSPENDED_TRANSACTION = "suspendedTransaction"; + + private String action = ""; + + public boolean mediate(MessageContext synCtx) { + + TransactionManager transactionManager; + + boolean traceOn = isTraceOn(synCtx); + boolean traceOrDebugOn = isTraceOrDebugOn(traceOn); + + if (traceOrDebugOn) { + traceOrDebug(traceOn, "Start : Transaction mediator (" + action + ")"); + + if (traceOn && trace.isTraceEnabled()) { + trace.trace("Message : " + synCtx.getEnvelope()); + } + } + + transactionManager = getTransactionManager(synCtx); + + if (action.equals(ACTION_COMMIT)) { + + try { + transactionManager.commit(); + } catch (Exception e) { + handleException("Unable to commit transaction", e, synCtx); + } + + } else if (action.equals(ACTION_ROLLBACK)) { + + try { + transactionManager.rollback(); + } catch (Exception e) { + handleException("Unable to rollback transaction", e, synCtx); + } + + } else if (action.equals(ACTION_NEW)) { + + int status = Status.STATUS_UNKNOWN; + try { + status = transactionManager.getStatus(); + } catch (Exception e) { + handleException("Unable to query transaction status", e, synCtx); + } + + if (status != Status.STATUS_NO_TRANSACTION) { + throw new SynapseException("Require to begin a new transaction, but a tansaction already exist"); + } + + try { + transactionManager.begin(); + } catch (Exception e) { + handleException("Unable to begin a new transaction", e, synCtx); + } + + } else if (action.equals(ACTION_USE_EXISTING_OR_NEW)) { + + int status = Status.STATUS_UNKNOWN; + try { + status = transactionManager.getStatus(); + } catch (Exception e) { + handleException("Unable to query transaction status", e, synCtx); + } + + try { + if (status == Status.STATUS_NO_TRANSACTION) { + transactionManager.begin(); + } + } catch (Exception e) { + handleException("Unable to begin a new transaction", e, synCtx); + } + + } else if (action.equals(ACTION_FAULT_IF_NO_TX)) { + + int status = Status.STATUS_UNKNOWN; + try { + status = transactionManager.getStatus(); + } catch (Exception e) { + handleException("Unable to query transaction status", e, synCtx); + } + + if (status != Status.STATUS_ACTIVE) + throw new SynapseException("No active transaction. Require an active transaction"); + + } else if (action.equals(ACTION_SUSPEND)) { + + try { + Transaction tx = transactionManager.suspend(); + synCtx.setProperty(SUSPENDED_TRANSACTION, tx); + } catch (Exception e) { + handleException("Unable to suspend transaction", e, synCtx); + } + + } else if (action.equals(ACTION_RESUME)) { + + Transaction tx = (Transaction) synCtx.getProperty(SUSPENDED_TRANSACTION); + if (tx == null) + handleException("Couldn't find a suspended transaction to resume", synCtx); + try { + transactionManager.resume(tx); + } catch (Exception e) { + handleException("Unable to resume transaction", e, synCtx); + } + + } else { + handleException("Invalid transaction mediator action : " + action, synCtx); + } + + if (traceOrDebugOn) { + traceOrDebug(traceOn, "End : Transaction mediator"); + } + + return true; + } + + private TransactionManager getTransactionManager(MessageContext synCtx) { + + TransactionManager transactionManager = null; + try { + transactionManager = synCtx.getConfiguration() + .getTransactionConfiguration().getTransactionManager(); + } catch (AxisFault ex) { + handleException("Unable to get Transaction Manager", ex, synCtx); + } + + if (transactionManager == null) { + handleException("Unable to get Transaction Manager", synCtx); + } + + return transactionManager; + } + + public void setAction(String action) { + this.action = action; + } + + public String getAction() { + return action; + } + +} Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfiguration.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfiguration.java?pathrev=29272 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfiguration.java Thu Jan 22 09:21:53 2009 @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ws.commons.transactions; + +import org.apache.axis2.AxisFault; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.transaction.TransactionManager; +import javax.transaction.SystemException; +import java.util.Hashtable; + +public class TransactionConfiguration { + + private static final Log log = LogFactory.getLog(TransactionConfiguration.class); + + public static final int DEFAULT_TX_TIME_OUT = 300000 ; //30s + public static final String TX_MANAGER_JNDI_NAME = "TransactionManagerJNDIName"; + + private int transactionTimeout = DEFAULT_TX_TIME_OUT; + private ThreadLocal<TransactionManager> threadTransactionManager = null; + private Hashtable<String, String> jndiProperties = null; + private String transactionManagerJNDIName = null; + + + + public TransactionConfiguration(Hashtable<String, String> transactionParameters) + throws AxisFault { + + jndiProperties = transactionParameters; + transactionManagerJNDIName = transactionParameters.get(TX_MANAGER_JNDI_NAME); + + if(transactionManagerJNDIName == null){ + throw new AxisFault("Required transaction parameter " + + TX_MANAGER_JNDI_NAME + " is missing"); + } + threadTransactionManager = new ThreadLocal<TransactionManager>(); + } + + public synchronized TransactionManager getTransactionManager() throws AxisFault { + + TransactionManager transactionManager = threadTransactionManager.get(); + if (transactionManager == null) { + if (log.isDebugEnabled()) { + log.debug("JNDI lookup TransactionManager"); + } + transactionManager = lookupTransactionManager(); + threadTransactionManager.set(transactionManager); + } else { + if (log.isDebugEnabled()) { + log.debug("Re-use previously JNDI lookup TransactionManager"); + } + } + + try { + transactionManager.setTransactionTimeout(transactionTimeout); + } catch (SystemException e) { + log.warn("Couldn't set the transaction timeout to the TransactionManager"); + } + + return transactionManager; + } + + private synchronized TransactionManager lookupTransactionManager() throws AxisFault { + + try { + + Context context = new InitialContext(jndiProperties); + Object transactionManager = context.lookup(transactionManagerJNDIName); + + if (transactionManager != null && transactionManager instanceof TransactionManager) { + return (TransactionManager) transactionManager; + } else { + String message = "TransactionManager : " + transactionManagerJNDIName + " not " + + "found when looking up using JNDI properties : " + context.getEnvironment(); + log.error(message); + throw new AxisFault(message); + } + + } catch (NamingException e) { + String message = "TransactionManager not found when looking up " + + "using JNDI properties : " + jndiProperties; + log.error(message, e); + throw new AxisFault(message, e); + } + } + + public int getTransactionTimeout() { + return transactionTimeout; + } + + public void setTransactionTimeout(int transactionTimeout) { + this.transactionTimeout = transactionTimeout; + } + +} \ No newline at end of file Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfigurationBuilder.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfigurationBuilder.java?pathrev=29272 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/ws/commons/transactions/TransactionConfigurationBuilder.java Thu Jan 22 09:21:53 2009 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ws.commons.transactions; + +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.description.Parameter; +import org.apache.synapse.config.xml.XMLConfigConstants; + +import javax.xml.namespace.QName; +import java.util.Hashtable; +import java.util.Iterator; + +public class TransactionConfigurationBuilder { + + /** + * Builds the {...@link org.apache.ws.commons.transactions.TransactionConfiguration} object from + * the axis2.xml parameter + * + * @param parameter to be used for building the configuration, it should be as follows; + * <parameter name="JtaTransactionInfo"> + * <property name="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</property> + * <property name="java.naming.provider.url">localhost:1099</property> + * <property name="UserTransactionJNDIName">UserTransaction</property> + * <property name="TransactionManagerJNDIName">TransactionManager</property> + * <property name="TransactionTimeout">1000</property> + * </parameter> + * @return the configuration built from the above specified parameter + * @throws AxisFault in case of a build error + */ + public static TransactionConfiguration buildConfiguration(Parameter parameter) + throws AxisFault { + + OMElement txElement = parameter.getParameterElement(); + + Iterator items = txElement.getChildrenWithName(new QName("property")); + Hashtable<String, String> jndiProperties = new Hashtable<String, String>(); + int timeout = 0; + + while (items.hasNext()) { + OMElement elem = (OMElement) items.next(); + OMAttribute name = elem.getAttribute( + new QName(XMLConfigConstants.NULL_NAMESPACE, "name")); + String value = elem.getText(); + if (!"TransactionTimeout".equals(name.getAttributeValue())) { + jndiProperties.put(name.getAttributeValue(), value); + } else { + timeout = Integer.parseInt(value); + } + } + + TransactionConfiguration txCfg = new TransactionConfiguration(jndiProperties); + txCfg.setTransactionTimeout(timeout); + + return txCfg; + } + +} \ No newline at end of file Added: branches/synapse/1.2.wso2v1/modules/core/src/test/java/org/apache/synapse/config/xml/TransactionMediatorSerializationTest.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/test/java/org/apache/synapse/config/xml/TransactionMediatorSerializationTest.java?pathrev=29272 ============================================================================== --- (empty file) +++ branches/synapse/1.2.wso2v1/modules/core/src/test/java/org/apache/synapse/config/xml/TransactionMediatorSerializationTest.java Thu Jan 22 09:21:53 2009 @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.synapse.config.xml; + +public class TransactionMediatorSerializationTest extends AbstractTestCase { + + TransactionMediatorFactory transactionMediatorFactory; + TransactionMediatorSerializer transactionMediatorSerializer; + + public TransactionMediatorSerializationTest() { + super(DropMediatorSerializationTest.class.getName()); + transactionMediatorFactory = new TransactionMediatorFactory(); + transactionMediatorSerializer = new TransactionMediatorSerializer(); + } + + public void testTransactionMediatorSerializationSenarioOne() throws Exception { + String inputXml = "<transaction action=\"new\" xmlns=\"http://ws.apache.org/ns/synapse\" />"; + assertTrue(serialization(inputXml, transactionMediatorFactory, transactionMediatorSerializer)); + assertTrue(serialization(inputXml, transactionMediatorSerializer)); + } + + +} _______________________________________________ Esb-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
