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 static com.sun.xml.ws.developer.JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY;
042: import com.sun.xml.ws.developer.MemberSubmissionAddressing;
043: import com.sun.xml.ws.developer.MemberSubmissionEndpointReference;
044: import com.sun.xml.ws.developer.StatefulWebServiceManager;
045: import com.sun.xml.ws.tx.at.ATCoordinator;
046: import static com.sun.xml.ws.tx.common.Constants.UNKNOWN_ID;
047: import com.sun.xml.ws.tx.common.TxLogger;
048: import com.sun.xml.ws.tx.coordinator.CoordinationManager;
049:
050: import javax.annotation.Resource;
051: import javax.jws.WebService;
052: import javax.xml.ws.EndpointReference;
053: import javax.xml.ws.WebServiceContext;
054: import javax.xml.ws.handler.MessageContext;
055: import java.util.logging.Level;
056:
057: /**
058: * Implements WS-AT Coordinator web service.
059: * <p/>
060: * Proceses notificaions from participants in coordinated atomic transaction activity.
061: *
062: * @author Joe.Fialli@Sun.COM
063: * @version $Revision: 1.5 $
064: * @since 1.0
065: */
066: @MemberSubmissionAddressing
067: @com.sun.xml.ws.developer.Stateful
068: @WebService(serviceName=CoordinatorPortTypeImpl.serviceName,portName=CoordinatorPortTypeImpl.portName,endpointInterface="com.sun.xml.ws.tx.webservice.member.at.CoordinatorPortType",targetNamespace="http://schemas.xmlsoap.org/ws/2004/10/wsat",wsdlLocation="WEB-INF/wsdl/wsat.wsdl")
069: public class CoordinatorPortTypeImpl implements CoordinatorPortType {
070:
071: public static final String serviceName = "WSATCoordinator";
072: public static final String portName = "Coordinator";
073:
074: /* stateful fields */
075: private static StatefulWebServiceManager<CoordinatorPortTypeImpl> manager;
076: private String activityId;
077: private String participantId;
078:
079: @Resource
080: private WebServiceContext wsContext;
081:
082: private static final TxLogger logger = TxLogger
083: .getLogger(CoordinatorPortTypeImpl.class);
084:
085: private ATCoordinator coordinator = null;
086:
087: private EndpointReference fallbackEPR = null;
088:
089: public CoordinatorPortTypeImpl() {
090: }
091:
092: public CoordinatorPortTypeImpl(String activityId,
093: String participantId) {
094: this .activityId = activityId;
095: this .participantId = participantId;
096: }
097:
098: private void initContextFromIncomingMessage() {
099: coordinator = (ATCoordinator) CoordinationManager.getInstance()
100: .getCoordinator(activityId);
101: if (wsContext != null) {
102: MessageContext mc = wsContext.getMessageContext();
103: //TODO start using replyTo EPR if coordinator/participant is unknown or if initial remote 2PC notification
104: // fails one should see if replyTo EPR can get notfication through.
105: HeaderList hdrLst = (HeaderList) mc
106: .get(INBOUND_HEADER_LIST_PROPERTY);
107: if (hdrLst != null) {
108: fallbackEPR = hdrLst
109: .getReplyTo(AddressingVersion.MEMBER,
110: SOAPVersion.SOAP_11)
111: .toSpec(MemberSubmissionEndpointReference.class);
112: }
113: } else {
114: if (logger.isLogging(Level.WARNING)) {
115: logger.warning("initContextFromIncomingMessage",
116: "wsContext unexpectedly null");
117: }
118: }
119:
120: if (activityId == UNKNOWN_ID) {
121: if (logger.isLogging(Level.INFO)) {
122: logger
123: .info("Atomic Transaction Coordinator",
124: "handling notification for an unknown transaction");
125: }
126: coordinator = null;
127: } else {
128: coordinator = (ATCoordinator) CoordinationManager
129: .getInstance().getCoordinator(activityId);
130: }
131: }
132:
133: public void preparedOperation(Notification parameters) {
134: final String METHOD_NAME = "preparedOperation";
135:
136: initContextFromIncomingMessage();
137: if (logger.isLogging(Level.FINER)) {
138: logger.entering(METHOD_NAME, getCoordIdPartId());
139: }
140: if (coordinator != null) {
141: coordinator.prepared(participantId);
142: } else {
143: // TODO unknown activity id, send rollbackOperation to participant
144: if (logger.isLogging(Level.SEVERE)) {
145: logger.severe("preparedOperation",
146: "unknown coordId or partId "
147: + getCoordIdPartId());
148: }
149: }
150: if (logger.isLogging(Level.FINER)) {
151: logger.exiting(METHOD_NAME, getCoordIdPartId());
152: }
153: }
154:
155: public void abortedOperation(Notification parameters) {
156: final String METHOD_NAME = "abortedOperation";
157:
158: initContextFromIncomingMessage();
159: if (logger.isLogging(Level.FINER)) {
160: logger.entering(METHOD_NAME, getCoordIdPartId());
161: }
162: if (coordinator != null) {
163: coordinator.aborted(participantId);
164: } else {
165: if (logger.isLogging(Level.SEVERE)) {
166: logger.severe("abortedOperation",
167: "unknown coordId or partId "
168: + getCoordIdPartId());
169: }
170: }
171: if (logger.isLogging(Level.FINER)) {
172: logger.exiting(METHOD_NAME, getCoordIdPartId());
173: }
174: }
175:
176: public void readOnlyOperation(Notification parameters) {
177: final String METHOD_NAME = "readonlyOperation";
178:
179: initContextFromIncomingMessage();
180: if (logger.isLogging(Level.FINER)) {
181: logger.entering(METHOD_NAME, getCoordIdPartId());
182: }
183: if (coordinator != null) {
184: coordinator.readonly(participantId);
185: } else {
186: // TODO unknown activity id, is logging enough or send something to fallback EPR
187: if (logger.isLogging(Level.SEVERE)) {
188: logger.severe("readonlyOperation",
189: "unknown coordId or partId "
190: + getCoordIdPartId());
191: }
192: }
193: if (logger.isLogging(Level.FINER)) {
194: logger.exiting(METHOD_NAME, getCoordIdPartId());
195: }
196: }
197:
198: public void committedOperation(Notification parameters) {
199: final String METHOD_NAME = "committedOperation";
200:
201: initContextFromIncomingMessage();
202: if (logger.isLogging(Level.FINER)) {
203: logger.entering(METHOD_NAME, getCoordIdPartId());
204: }
205: if (coordinator != null) {
206: coordinator.committed(participantId);
207: } else {
208: // TODO unknown activity id, is logging enough or send something to participant fallbackEPR
209: if (logger.isLogging(Level.SEVERE)) {
210: logger.severe("committedOperation",
211: "unknown coordId or partId "
212: + getCoordIdPartId());
213: }
214: }
215: if (logger.isLogging(Level.FINER)) {
216: logger.exiting(METHOD_NAME, getCoordIdPartId());
217: }
218: }
219:
220: public void replayOperation(Notification parameters) {
221: final String METHOD_NAME = "replayOperation";
222:
223: initContextFromIncomingMessage();
224: if (logger.isLogging(Level.FINER)) {
225: logger.entering(METHOD_NAME, getCoordIdPartId());
226: }
227: if (coordinator != null) {
228: coordinator.replay(participantId);
229: } else {
230: // TODO unknown activity id, is logging enough or send something to participant fallbackEPR
231: if (logger.isLogging(Level.SEVERE)) {
232: logger.severe("replayOperation",
233: "unknown coordId or partId "
234: + getCoordIdPartId());
235: }
236: }
237: if (logger.isLogging(Level.FINER)) {
238: logger.exiting(METHOD_NAME, getCoordIdPartId());
239: }
240: }
241:
242: private String getCoordIdPartId() {
243: return "CoorId=" + activityId + " PartId=" + participantId
244: + " ";
245: }
246:
247: public static StatefulWebServiceManager<CoordinatorPortTypeImpl> getManager() {
248: return manager;
249: }
250:
251: public static void setManager(
252: StatefulWebServiceManager<CoordinatorPortTypeImpl> aManager) {
253: manager = aManager;
254: }
255: }
|