001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
022: *
023: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
024: *
025: * The contents of this file are subject to the terms of either the GNU
026: * General Public License Version 2 only ("GPL") or the Common Development
027: * and Distribution License("CDDL") (collectively, the "License"). You
028: * may not use this file except in compliance with the License. You can obtain
029: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
030: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
031: * language governing permissions and limitations under the License.
032: *
033: * When distributing the software, include this License Header Notice in each
034: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
035: * Sun designates this particular file as subject to the "Classpath" exception
036: * as provided by Sun in the GPL Version 2 section of the License file that
037: * accompanied this code. If applicable, add the following below the License
038: * Header, with the fields enclosed by brackets [] replaced by your own
039: * identifying information: "Portions Copyrighted [year]
040: * [name of copyright owner]"
041: *
042: * Contributor(s):
043: *
044: * If you wish your version of this file to be governed by only the CDDL or
045: * only the GPL Version 2, indicate your decision by adding "[Contributor]
046: * elects to include this software in this distribution under the [CDDL or GPL
047: * Version 2] license." If you don't indicate a single choice of license, a
048: * recipient has the option to distribute your version of this file under
049: * either the CDDL, the GPL Version 2 or to extend the choice of license to
050: * its licensees as provided above. However, if you add GPL Version 2 code
051: * and therefore, elected the GPL Version 2 license, then the option applies
052: * only if the new code is made subject to such option by the copyright
053: * holder.
054: */
055:
056: package com.sun.xml.soap;
057:
058: import java.util.*;
059:
060: import javax.xml.namespace.QName;
061: import javax.xml.soap.*;
062:
063: public class SOAPProcessorImpl extends SOAPProcessor {
064:
065: private String ultimateReceiverURL = "http://schemas.xmlsoap.org/soap/actor/ultimateReceiver";
066:
067: //Limit access
068: protected SOAPProcessorImpl() {
069: }
070:
071: /**
072: * Implementation for SOAP 1.1
073: */
074: public SOAPMessage acceptMessage(SOAPMessage message)
075: throws Exception {
076:
077: SOAPHeader header = message.getSOAPHeader();
078:
079: checkMustUnderstand(header);
080:
081: ProcessingContext context = new ProcessingContext();
082: context.setProperty(SOAPProcessorConstants.MESSAGE_PROPERTY,
083: message);
084:
085: ProcessingStates currentState = null;
086: Stack recipientsCalled = new Stack();
087:
088: Iterator eachHeaderElement = header.examineAllHeaderElements();
089: while (eachHeaderElement.hasNext()) {
090: SOAPHeaderElement element = (SOAPHeaderElement) eachHeaderElement
091: .next();
092: String role = getRoleAttributeValue(element);
093: for (Iterator eachRecipient = recipients.iterator(); eachRecipient
094: .hasNext();) {
095: SOAPRecipient recipient = (SOAPRecipient) eachRecipient
096: .next();
097: if (recipient.supportsRole(role)) {
098: Name elementName = element.getElementName();
099: QName elementQName = new QName(
100: elementName.getURI(), elementName
101: .getLocalName(), elementName
102: .getPrefix());
103: if (recipient.supportsHeader(elementQName)) {
104:
105: recipientsCalled.push(recipient);
106:
107: recipient.acceptHeaderElement(element, context);
108:
109: currentState = (ProcessingStates) context
110: .getProperty(SOAPProcessorConstants.STATE_PROPERTY);
111: if (currentState == ProcessingStates.STOP
112: || currentState == ProcessingStates.FAULT
113: || currentState == ProcessingStates.HEADER_DONE) {
114:
115: break;
116: }
117: }
118: }
119: }
120: if (currentState == ProcessingStates.STOP) {
121: break;
122: }
123: if (currentState == ProcessingStates.FAULT) {
124: handleFault(context, recipientsCalled);
125: break;
126: }
127: }
128: message.saveChanges();
129: return message;
130: }
131:
132: private void checkMustUnderstand(SOAPHeader header)
133: throws SOAPException {
134: Iterator eachHeaderElement = header.examineAllHeaderElements();
135: for (; eachHeaderElement.hasNext();) {
136: SOAPHeaderElement headerElement = (SOAPHeaderElement) eachHeaderElement
137: .next();
138: Name headerName = headerElement.getElementName();
139: QName headerQName = new QName(headerName.getURI(),
140: headerName.getLocalName(), headerName.getPrefix());
141: String role = getRoleAttributeValue(headerElement);
142: boolean canBeProcessed = false;
143: boolean isTargeted = false;
144: for (Iterator eachRecipient = recipients.iterator(); eachRecipient
145: .hasNext();) {
146: SOAPRecipient recipient = (SOAPRecipient) eachRecipient
147: .next();
148: if (recipient.supportsRole(role)) {
149: isTargeted = true;
150: if (recipient.supportsHeader(headerQName)) {
151: canBeProcessed = true;
152: }
153: }
154: }
155: if (!canBeProcessed && isTargeted
156: && headerElement.getMustUnderstand()) {
157:
158: throw new SOAPException(
159: "MustUnderstand failure. Header = "
160: + headerQName + " Role = " + role);
161: }
162: }
163: }
164:
165: public SOAPMessage prepareMessage(SOAPMessage message)
166: throws Exception {
167:
168: SOAPHeader header = message.getSOAPHeader();
169: ProcessingContext context = new ProcessingContext();
170: context.setProperty(SOAPProcessorConstants.MESSAGE_PROPERTY,
171: message);
172: ProcessingStates currentState = null;
173: Stack annotatorsCalled = new Stack();
174: for (Iterator it = annotators.iterator(); it.hasNext();) {
175: SOAPAnnotator annotator = (SOAPAnnotator) it.next();
176: annotatorsCalled.push(annotator);
177: annotator.annotateHeader(header, context);
178: currentState = (ProcessingStates) context
179: .getProperty(SOAPProcessorConstants.STATE_PROPERTY);
180: if (currentState == ProcessingStates.STOP
181: || currentState == ProcessingStates.FAULT) {
182: break;
183: }
184: }
185: if (currentState == ProcessingStates.FAULT) {
186: handleFault(context, annotatorsCalled);
187: }
188: message.saveChanges();
189: return message;
190: }
191:
192: private void handleFault(ProcessingContext context,
193: Stack recipientsCalled) {
194: while (true) {
195: ProcessingFaultHandler faultHandler = (ProcessingFaultHandler) recipientsCalled
196: .pop();
197: if (faultHandler == null) {
198: break;
199: }
200: faultHandler.handleIncomingFault(context);
201: }
202: }
203:
204: /**
205: * Implementation for SOAP 1.1
206: */
207: protected String getRoleAttributeValue(SOAPHeaderElement element) {
208:
209: String ret = element.getActor();
210: if (ret == null)
211: ret = ultimateReceiverURL;
212: return ret;
213: }
214:
215: }
|