001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.tx.webservice.member.at;
037:
038: import com.sun.xml.ws.api.SOAPVersion;
039: import com.sun.xml.ws.api.addressing.AddressingVersion;
040: import com.sun.xml.ws.api.message.HeaderList;
041: import com.sun.xml.ws.api.tx.TXException;
042: import static com.sun.xml.ws.developer.JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY;
043: import com.sun.xml.ws.developer.MemberSubmissionAddressing;
044: import com.sun.xml.ws.developer.MemberSubmissionEndpointReference;
045: import com.sun.xml.ws.developer.Stateful;
046: import com.sun.xml.ws.developer.StatefulWebServiceManager;
047: import com.sun.xml.ws.tx.at.ATCoordinator;
048: import com.sun.xml.ws.tx.at.ATParticipant;
049: import static com.sun.xml.ws.tx.common.Constants.UNKNOWN_ID;
050: import com.sun.xml.ws.tx.common.TxLogger;
051: import com.sun.xml.ws.tx.coordinator.CoordinationManager;
052:
053: import javax.annotation.Resource;
054: import javax.jws.WebService;
055: import javax.xml.ws.EndpointReference;
056: import javax.xml.ws.WebServiceContext;
057: import javax.xml.ws.handler.MessageContext;
058: import java.util.logging.Level;
059:
060: /**
061: * WS-Atomic Transaction participant protocol service
062: *
063: * @author Joe.Fialli@Sun.COM
064: * @version $Revision: 1.5 $
065: * @since 1.0
066: */
067: @MemberSubmissionAddressing
068: @Stateful
069: @WebService(serviceName=ParticipantPortTypeImpl.serviceName,portName=ParticipantPortTypeImpl.portName,endpointInterface="com.sun.xml.ws.tx.webservice.member.at.ParticipantPortType",targetNamespace="http://schemas.xmlsoap.org/ws/2004/10/wsat",wsdlLocation="WEB-INF/wsdl/wsat.wsdl")
070: public class ParticipantPortTypeImpl implements ParticipantPortType {
071:
072: public static final String serviceName = "WSATCoordinator";
073: public static final String portName = "Participant";
074:
075: private static final TxLogger logger = TxLogger
076: .getLogger(ParticipantPortTypeImpl.class);
077:
078: @Resource
079: private WebServiceContext wsContext;
080:
081: // stateful web service
082: private static StatefulWebServiceManager<ParticipantPortTypeImpl> manager;
083: private String activityId;
084: private String participantId;
085:
086: private EndpointReference fallbackEPR;
087: private ATParticipant participant;
088:
089: public ParticipantPortTypeImpl() {
090: }
091:
092: public ParticipantPortTypeImpl(String activityId,
093: String participantId) {
094: this .activityId = activityId;
095: this .participantId = participantId;
096: }
097:
098: private void initPerOperationData() {
099: participant = null;
100: fallbackEPR = null;
101:
102: if (wsContext != null) {
103: MessageContext mc = wsContext.getMessageContext();
104: if (mc != null) {
105: HeaderList hdrLst = (HeaderList) mc
106: .get(INBOUND_HEADER_LIST_PROPERTY);
107: if (hdrLst != null) {
108: fallbackEPR = hdrLst.getReplyTo(
109: AddressingVersion.MEMBER,
110: SOAPVersion.SOAP_11).toSpec(
111: MemberSubmissionEndpointReference.class);
112: } else {
113: if (logger.isLogging(Level.WARNING)) {
114: logger
115: .warning("initOperationData",
116: "INBOUND_HEADER_LIST_PROPERTY unexpectedly null");
117: }
118: }
119: } else {
120: if (logger.isLogging(Level.WARNING)) {
121: logger
122: .warning("initOperationData",
123: "WebServiceContext.getMessageContext() unexpectedly null");
124: }
125: }
126: } else {
127: if (logger.isLogging(Level.WARNING)) {
128: logger.warning("initContextFromIncomingMessage",
129: "wsContext unexpectedly null");
130: }
131: }
132:
133: ATCoordinator coordinator = null;
134: if (activityId == UNKNOWN_ID) {
135: if (logger.isLogging(Level.INFO)) {
136: logger
137: .info("Two Phase Commit Participant",
138: "handling notification for an unknown transaction");
139: }
140: return;
141: } else {
142: coordinator = (ATCoordinator) CoordinationManager
143: .getInstance().getCoordinator(activityId);
144: if (coordinator != null) {
145: try {
146: participant = (ATParticipant) coordinator
147: .getRegistrant(participantId);
148: } catch (ClassCastException ce) {
149: if (logger.isLogging(Level.WARNING)) {
150: logger.warning("getATPartcipant", ce
151: .getLocalizedMessage());
152: }
153: }
154: }
155: }
156: }
157:
158: public void prepareOperation(Notification parameters) {
159: final String METHOD_NAME = "prepareOperation";
160:
161: initPerOperationData();
162: if (logger.isLogging(Level.FINER)) {
163: logger.entering(METHOD_NAME, getCoordIdPartId());
164: }
165: if (participant != null) {
166: try {
167: participant.prepare();
168: } catch (TXException ex) {
169: // TODO: should this be a fault
170: if (logger.isLogging(Level.WARNING)) {
171: logger.warning("prepareOperation",
172: "caught TXException during prepare");
173: }
174: }
175: } else {
176: if (fallbackEPR != null) {
177: // 2004 WS-AT, Section 3.3: Participant unknown, must send abort back to wsa:ReplyTo
178: if (logger.isLogging(Level.WARNING)) {
179: logger.warning("prepareOperation",
180: "Unknown participant " + getCoordIdPartId()
181: + " reply with aborted to "
182: + fallbackEPR);
183: }
184: ATParticipant.getATCoordinatorWS(fallbackEPR, null,
185: false).abortedOperation(null);
186: } else {
187: if (logger.isLogging(Level.SEVERE)) {
188: logger.severe("prepareOperation",
189: "required wsa:ReplyTo property not found");
190: }
191: }
192: }
193: if (logger.isLogging(Level.FINER)) {
194: logger.exiting(METHOD_NAME, getCoordIdPartId());
195: }
196: }
197:
198: public void commitOperation(Notification parameters) {
199: final String METHOD_NAME = "commitOperation";
200:
201: initPerOperationData();
202: if (logger.isLogging(Level.FINER)) {
203: logger.entering(METHOD_NAME, getCoordIdPartId());
204: }
205: if (participant != null) {
206: try {
207: participant.commit();
208: } catch (TXException ex) {
209: if (logger.isLogging(Level.WARNING)) {
210: logger.warning("commitOperation", ex
211: .getLocalizedMessage());
212: }
213: }
214: } else {
215: // Participant unknown.
216: // TODO: send committed to coordinator using wsa:replyTo of this message
217: // Specified in 2004 WS-AT, Section 3.3
218: // 2004 WS-AT, Section 3.3: Participant unknown, must send abort back to wsa:ReplyTo
219:
220: if (fallbackEPR != null) {
221: if (logger.isLogging(Level.WARNING)) {
222: logger.warning("commitOperation",
223: "Unknown participant " + getCoordIdPartId()
224: + " reply with committed to "
225: + fallbackEPR);
226: }
227: ATParticipant.getATCoordinatorWS(fallbackEPR, null,
228: false).committedOperation(null);
229: } else {
230: if (logger.isLogging(Level.SEVERE)) {
231: logger.severe("commitOperation",
232: "required wsa:ReplyTo property not found");
233: }
234: }
235: }
236: if (logger.isLogging(Level.FINER)) {
237: logger.exiting(METHOD_NAME, getCoordIdPartId());
238: }
239: }
240:
241: public void rollbackOperation(Notification parameters) {
242: final String METHOD_NAME = "rollbackOperation";
243:
244: initPerOperationData();
245: if (logger.isLogging(Level.FINER)) {
246: logger.entering(METHOD_NAME, parameters);
247: }
248: if (participant != null) {
249: participant.abort();
250: } else {
251: if (fallbackEPR != null) {
252: // Particpant unknown. (no need to forget)
253: if (logger.isLogging(Level.WARNING)) {
254: logger.warning("rollbackOperation",
255: "Unknown participant " + getCoordIdPartId()
256: + " reply with aborted to"
257: + fallbackEPR);
258: }
259: ATParticipant.getATCoordinatorWS(fallbackEPR, null,
260: false).abortedOperation(null);
261: } else {
262: if (logger.isLogging(Level.SEVERE)) {
263: logger.severe("rollbackOperation",
264: "required wsa:ReplyTo property not found");
265: }
266: }
267: }
268: if (logger.isLogging(Level.FINER)) {
269: logger.exiting(METHOD_NAME, getCoordIdPartId());
270: }
271: }
272:
273: private String getCoordIdPartId() {
274: return "CoorId=" + activityId + " PartId=" + participantId
275: + " ";
276: }
277:
278: public static StatefulWebServiceManager<ParticipantPortTypeImpl> getManager() {
279: return manager;
280: }
281:
282: public static void setManager(
283: StatefulWebServiceManager<ParticipantPortTypeImpl> aManager) {
284: manager = aManager;
285: }
286: }
|