You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kandula-dev@ws.apache.org by da...@apache.org on 2006/01/02 20:09:31 UTC
svn commit: r365397 - in
/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at:
TransactionManagerImpl.java TxHandler.java
Author: dasarath
Date: Mon Jan 2 11:09:30 2006
New Revision: 365397
URL: http://svn.apache.org/viewcvs?rev=365397&view=rev
Log: (empty)
Added:
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TransactionManagerImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TxHandler.java
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TransactionManagerImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TransactionManagerImpl.java?rev=365397&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TransactionManagerImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TransactionManagerImpl.java Mon Jan 2 11:09:30 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.transaction.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.ws.transaction.coordinator.ActivationStub;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+import org.apache.ws.transaction.coordinator.CoordinationService;
+
+public class TransactionManagerImpl {
+
+ private static TransactionManagerImpl instance = new TransactionManagerImpl();
+
+ private static ThreadLocal threadInfo = new ThreadLocal();
+
+ public static TransactionManagerImpl getInstance() {
+ return instance;
+ }
+
+ private TransactionManagerImpl() {
+ }
+
+ public void begin() throws RemoteException {
+ begin(CoordinationService.getInstance().getActivationService());
+ }
+
+ public void begin(EndpointReference epr) throws RemoteException {
+ if (threadInfo.get() != null)
+ throw new IllegalStateException();
+ CoordinationContext ctx;
+ try {
+ ctx = new ActivationStub(epr).createCoordinationContext(ATCoordinator.COORDINATION_TYPE_ID);
+ threadInfo.set(new TransactionImpl(ctx));
+ } catch (RemoteException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void commit() throws RemoteException {
+ TransactionImpl tx = getTransaction();
+ if (tx == null)
+ throw new IllegalStateException();
+ forget();
+ tx.commit();
+ }
+
+ public void rollback() throws RemoteException {
+ TransactionImpl tx = getTransaction();
+ if (tx == null)
+ throw new IllegalStateException();
+ forget();
+ tx.rollback();
+ }
+
+ public TransactionImpl suspend() {
+ TransactionImpl tx = getTransaction();
+ forget();
+ return tx;
+ }
+
+ public void resume(TransactionImpl tx) {
+ if (threadInfo.get() != null)
+ throw new IllegalStateException();
+ threadInfo.set(tx);
+ }
+
+ public void forget() {
+ threadInfo.set(null);
+ }
+
+ public TransactionImpl getTransaction() {
+ return (TransactionImpl) threadInfo.get();
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TxHandler.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TxHandler.java?rev=365397&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TxHandler.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/TxHandler.java Mon Jan 2 11:09:30 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.transaction.coordinator.at;
+
+import java.util.Iterator;
+
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.MessageContext;
+import org.apache.axis.handlers.BasicHandler;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class TxHandler extends BasicHandler {
+ TransactionManagerImpl tm = TransactionManagerImpl.getInstance();
+
+ public void invoke(MessageContext mc) throws AxisFault {
+ if (mc.isClient()) {
+ TransactionImpl tx = tm.getTransaction();
+ if (tx != null) {
+ try {
+ SOAPHeader header = mc.getCurrentMessage().getSOAPEnvelope().getHeader();
+ tx.getCoordinationContex().toSOAPHeaderElement(header);
+ } catch (Exception e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+ }
+ else {
+ if (mc.getPastPivot())
+ tm.forget();
+ else {
+ try {
+ SOAPHeader header = mc.getCurrentMessage().getSOAPEnvelope().getHeader();
+ Iterator iter = header.getChildElements();
+ while (iter.hasNext()) {
+ SOAPElement e = (SOAPElement) iter.next();
+ if (CoordinationContext.is(e)) {
+ CoordinationContext ctx = new CoordinationContext(e);
+ tm.resume(new TransactionImpl(ctx));
+ return;
+ }
+ }
+ } catch (SOAPException e){
+ e.printStackTrace();
+ throw new AxisFault();
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org