001: /*
002: * @(#) OTSClientTransactionInterceptor.java 1.0 02/07/15
003: *
004: * JOTM: Java Open Transaction Manager
005: *
006: * This module was originally developed by
007: * - INRIA inside the ObjectWeb Consortium(http://www.objectweb.org)
008: *
009: * The original code and portions created by INRIA are
010: * Copyright (C) 2002 - INRIA (www.inria.fr)
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * -Redistributions of source code must retain the above copyright notice, this
017: * list of conditions and the following disclaimer.
018: *
019: * -Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
024: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
025: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
026: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
027: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
028: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
030: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
031: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
032: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
033: * POSSIBILITY OF SUCH DAMAGE.
034: *
035: * --------------------------------------------------------------------------
036: * $Id: OTSClientTransactionInterceptor.java,v 1.12 2004/12/13 19:49:29 tonyortiz Exp $
037: * --------------------------------------------------------------------------
038: */
039: package org.objectweb.jotm.ots;
040:
041: // java import
042: import org.objectweb.jotm.Current;
043: import org.objectweb.jotm.TransactionContext;
044: import org.omg.IOP.ServiceContext;
045: import org.omg.PortableInterceptor.ClientRequestInfo;
046: import org.omg.PortableInterceptor.ClientRequestInterceptor;
047: import org.omg.PortableInterceptor.ForwardRequest;
048: import org.omg.PortableInterceptor.ORBInitInfo;
049:
050: /**
051: * Class <code>OTSClientTransactionInterceptor</code> is a Client Interceptor for OTS Java Client
052: * of JOTM. This Interceptor translate the Standart OTS Propagation Context to a Internal JOTM
053: * Transaction context
054: *
055: * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
056: */
057: public class OTSClientTransactionInterceptor extends OTSInterceptor
058: implements ClientRequestInterceptor {
059:
060: /**
061: * current object
062: */
063: private static Current current = null;
064:
065: /**
066: * interceptor name
067: */
068: private String interceptorName = "OTSClientTransactionInteceptor";
069:
070: /**
071: * constructor
072: */
073: public OTSClientTransactionInterceptor(ORBInitInfo info) {
074: super (info);
075: }
076:
077: /**
078: * get the name of this interceptor
079: * @return name
080: */
081: public String name() {
082: return interceptorName;
083: }
084:
085: public void destroy() {
086: }
087:
088: /**
089: * send client transaction context with the request, if existed.
090: *
091: * @param jri ClientRequestInfo iiop client info
092: * @exception IOException if an exception occured with the ObjectOutput
093: */
094: public void send_request(ClientRequestInfo jri)
095: throws ForwardRequest {
096:
097: if (current == null)
098: current = Current.getCurrent();
099: if (current != null) {
100: try {
101: // get the Transaction Context (null if there is no transaction)
102: TransactionContext txCtx = current
103: .getPropagationContext(true);
104: ServiceContext pContext = null;
105:
106: if (txCtx != null) {
107:
108: // get the TransactionContext and build the Corba PropagtionContext
109: pContext = buildCorbaPropagationContext(txCtx);
110: jri.add_request_service_context(pContext, true);
111: } else {
112:
113: // if no active global transaction, the container does not include a tx context
114: // in the request message
115: }
116:
117: } catch (Exception e) {
118: throw new ForwardRequest();
119: }
120: }
121: }
122:
123: /**
124: * Receive reply interception
125: * @param jri JClientRequestInfo jri client info
126: * @exception IOException if an exception occur with the ObjectOutput
127: */
128: public void receive_reply(ClientRequestInfo jri) {
129:
130: if (current == null)
131: current = Current.getCurrent();
132:
133: if (current != null) {
134:
135: try {
136: TransactionContext txCtx = decodeCorbaPropagationContext(jri
137: .get_reply_service_context(TX_CTX_ID));
138:
139: if (txCtx != null) {
140:
141: // put into the the Current object (true for client side context)
142: current.setPropagationContext(txCtx, true);
143:
144: // associate Thread whith Tx
145: current.associateThreadTx(txCtx.getXid());
146: }
147:
148: } catch (org.omg.CORBA.BAD_PARAM b) {
149: // else we do nothing -> no transaction context for this call
150:
151: } catch (Exception e) {
152:
153: }
154: }
155: }
156:
157: // empty method
158: public void send_poll(ClientRequestInfo jri) {
159: }
160:
161: public void receive_exception(ClientRequestInfo jri)
162: throws ForwardRequest {
163: if (current == null)
164: current = Current.getCurrent();
165:
166: if (current != null) {
167: try {
168: TransactionContext txCtx = decodeCorbaPropagationContext(jri
169: .get_reply_service_context(TX_CTX_ID));
170:
171: if (txCtx != null) {
172:
173: // put into the the Current object (true for client side context)
174: current.setPropagationContext(txCtx, true);
175:
176: // associate Thread whith Tx
177: current.associateThreadTx(txCtx.getXid());
178: }
179:
180: } catch (org.omg.CORBA.BAD_PARAM b) {
181: // else we do nothing -> no transaction context for this call
182:
183: } catch (Exception e) {
184: }
185: }
186: }
187:
188: public void receive_other(ClientRequestInfo jri)
189: throws ForwardRequest {
190: }
191:
192: }
|