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:
037: /*
038: * ProtocolMessageReceiver.java
039: *
040: * @author Mike Grogan
041: * Created on March 1, 2006, 12:50 PM
042: *
043: */
044:
045: package com.sun.xml.ws.rm.jaxws.runtime.client;
046:
047: import com.sun.xml.ws.rm.Constants;
048: import com.sun.xml.ws.rm.InvalidSequenceException;
049: import com.sun.xml.ws.rm.RMConstants;
050: import com.sun.xml.ws.rm.RMException;
051: import com.sun.xml.ws.rm.v200502.CreateSequenceResponseElement;
052: import com.sun.xml.ws.rm.v200502.SequenceAcknowledgementElement; //import com.sun.xml.ws.transport.http.server.EndpointImpl;
053:
054: import java.util.HashMap;
055:
056: /**
057: * Handles the contents of responses to RM Protocol requests with
058: * non-anonymous AcksTo.
059: */
060: public class ProtocolMessageReceiver {
061:
062: //Hardcoding the W3C version for now
063: public static final String anonymous = RMConstants.W3C
064: .getAnonymousURI().toString();
065: /**
066: * AcksTo URI used for non-anonymous responses... Currently one per process.
067: * Set using the <code>start</code> method. Defaults to anonymous. When
068: * start is called with non-anonymous argument, an HTTP listener is started to
069: * process the messages.
070: */
071: private static String acksTo = anonymous;
072:
073: /**
074: * Endpoint listening for protocol messages.
075: */
076: // private static EndpointImpl endpoint;
077: /**
078: * Map of messageId String / CreateSequenceElement pairs that have beeen
079: * passed to setCreateSequenceResponse.
080: */
081: private static HashMap<String, CreateSequenceResponseElement> knownIds = new HashMap<String, CreateSequenceResponseElement>();
082:
083: /**
084: * Everything is static
085: */
086: private ProtocolMessageReceiver() {
087: }
088:
089: /**
090: * Accessor for the AcksTo field.
091: */
092: public static String getAcksTo() {
093: return acksTo;
094: }
095:
096: /*
097: * Set the acksTo field to the specified URI and start the
098: * Http listener listening at that URI.
099: */
100: public static void start(String newAcksTo) {
101: /*
102: if (!acksTo.equals(anonymous) && !newAcksTo.equals(acksTo)) {
103: throw new UnsupportedOperationException("Cannot change non-anonymous acksTo");
104: }
105:
106: if (acksTo.equals(anonymous)) {
107: acksTo = newAcksTo;
108: //start our endpoint listening on the given URI
109: BindingID binding = BindingID.parse(SOAPBinding.SOAP12HTTP_BINDING) ;
110: endpoint = new EndpointImpl(binding, new DummyProvider());
111: endpoint.publish(acksTo);
112:
113: }
114: */
115: }
116:
117: public static void stop() {
118: /*
119: if (endpoint != null) {
120: endpoint.stop();
121: }
122: */
123: }
124:
125: public static void setCreateSequenceResponse(String messageId,
126: CreateSequenceResponseElement csrElement) {
127:
128: synchronized (knownIds) {
129: knownIds.put(messageId, csrElement);
130: knownIds.notifyAll();
131: }
132: }
133:
134: public static CreateSequenceResponseElement getCreateSequenceResponse(
135: String messageId) {
136:
137: CreateSequenceResponseElement ret = null;
138: synchronized (knownIds) {
139: if (!knownIds.keySet().contains(messageId)) {
140: knownIds.put(messageId, null);
141: }
142:
143: while (null == (ret = knownIds.get(messageId))) {
144: try {
145: knownIds.wait();
146: } catch (InterruptedException e) {
147: }
148: }
149: }
150: return ret;
151: }
152:
153: public static void handleAcknowledgement(
154: SequenceAcknowledgementElement el) throws RMException {
155: //probably no need for synchronization here. The element was initialized at the
156: //endpoint using a sequenceid generated by the endpoint that made it back to
157: //the client. That means that getCreateSequenceResponse has returned long ago.
158: String id = el.getId();
159: ClientOutboundSequence seq = RMSource.getRMSource()
160: .getOutboundSequence(id);
161: if (id == null) {
162: throw new InvalidSequenceException(String.format(
163: Constants.UNKNOWN_SEQUENCE_TEXT, id), id);
164: }
165:
166: seq.handleAckResponse(el);
167:
168: }
169:
170: }
|