src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/ver1_1/Fault1_1Impl.java

Sun, 15 Dec 2013 23:35:45 +0100

author
mkos
date
Sun, 15 Dec 2013 23:35:45 +0100
changeset 494
2fcd3ddb57a6
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025152: Enhance activation set up
8028388: 9 jaxws tests failed in nightly build with java.lang.ClassCastException
Summary: fix also reviewed by Bill Shannon, Alexander Fomin
Reviewed-by: dfuchs, hawtin, mgrebac
Contributed-by: bill.shannon@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 /**
ohair@286 27 *
ohair@286 28 * @author SAAJ RI Development Team
ohair@286 29 */
ohair@286 30 package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
ohair@286 31
ohair@286 32 import java.util.Iterator;
ohair@286 33 import java.util.Locale;
ohair@286 34 import java.util.logging.Logger;
ohair@286 35 import java.util.logging.Level;
ohair@286 36
ohair@286 37 import javax.xml.namespace.QName;
ohair@286 38 import javax.xml.soap.SOAPElement;
ohair@286 39 import javax.xml.soap.SOAPFaultElement;
ohair@286 40 import javax.xml.soap.SOAPException;
ohair@286 41 import javax.xml.soap.SOAPConstants;
ohair@286 42 import javax.xml.soap.Name;
ohair@286 43 import javax.xml.soap.Name;
ohair@286 44
ohair@286 45 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
ohair@286 46 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
ohair@286 47 import com.sun.xml.internal.messaging.saaj.soap.impl.*;
ohair@286 48 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
ohair@286 49 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
ohair@286 50 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
ohair@286 51
ohair@286 52
ohair@286 53 public class Fault1_1Impl extends FaultImpl {
ohair@286 54
ohair@286 55 protected static final Logger log =
ohair@286 56 Logger.getLogger(
ohair@286 57 LogDomainConstants.SOAP_VER1_1_DOMAIN,
ohair@286 58 "com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
ohair@286 59
ohair@286 60 public Fault1_1Impl(SOAPDocumentImpl ownerDocument, String prefix) {
ohair@286 61 super(ownerDocument, NameImpl.createFault1_1Name(prefix));
ohair@286 62 }
ohair@286 63
ohair@286 64 protected NameImpl getDetailName() {
ohair@286 65 return NameImpl.createDetail1_1Name();
ohair@286 66 }
ohair@286 67
ohair@286 68 protected NameImpl getFaultCodeName() {
ohair@286 69 return NameImpl.createFromUnqualifiedName("faultcode");
ohair@286 70 }
ohair@286 71
ohair@286 72 protected NameImpl getFaultStringName() {
ohair@286 73 return NameImpl.createFromUnqualifiedName("faultstring");
ohair@286 74 }
ohair@286 75
ohair@286 76 protected NameImpl getFaultActorName() {
ohair@286 77 return NameImpl.createFromUnqualifiedName("faultactor");
ohair@286 78 }
ohair@286 79
ohair@286 80 protected DetailImpl createDetail() {
ohair@286 81 return new Detail1_1Impl(
ohair@286 82 ((SOAPDocument) getOwnerDocument()).getDocument());
ohair@286 83 }
ohair@286 84
ohair@286 85 protected FaultElementImpl createSOAPFaultElement(String localName) {
ohair@286 86 return new FaultElement1_1Impl(
ohair@286 87 ((SOAPDocument) getOwnerDocument()).getDocument(),
ohair@286 88 localName);
ohair@286 89 }
ohair@286 90
ohair@286 91 protected void checkIfStandardFaultCode(String faultCode, String uri)
ohair@286 92 throws SOAPException {
ohair@286 93 // SOAP 1.1 doesn't seem to mandate using faultcode from a particular
ohair@286 94 // set of values.
ohair@286 95 // Also need to be backward compatible.
ohair@286 96 }
ohair@286 97
ohair@286 98 protected void finallySetFaultCode(String faultcode) throws SOAPException {
ohair@286 99 this.faultCodeElement.addTextNode(faultcode);
ohair@286 100 }
ohair@286 101
ohair@286 102 public String getFaultCode() {
ohair@286 103 if (this.faultCodeElement == null)
ohair@286 104 findFaultCodeElement();
ohair@286 105 return this.faultCodeElement.getValue();
ohair@286 106 }
ohair@286 107
ohair@286 108 public Name getFaultCodeAsName() {
ohair@286 109
ohair@286 110 String faultcodeString = getFaultCode();
ohair@286 111 if (faultcodeString == null) {
ohair@286 112 return null;
ohair@286 113 }
ohair@286 114 int prefixIndex = faultcodeString.indexOf(':');
ohair@286 115 if (prefixIndex == -1) {
ohair@286 116 // Not a valid SOAP message, but we return the unqualified name
ohair@286 117 // anyway since some apps do not strictly conform to SOAP
ohair@286 118 // specs. A message that does not contain a <faultcode>
ohair@286 119 // element itself is also not valid in which case we return
ohair@286 120 // null instead of throwing an exception so this is consistent.
ohair@286 121 return NameImpl.createFromUnqualifiedName(faultcodeString);
ohair@286 122 }
ohair@286 123
ohair@286 124 // Get the prefix and map it to a namespace name (AKA namespace URI)
ohair@286 125 String prefix = faultcodeString.substring(0, prefixIndex);
ohair@286 126 if (this.faultCodeElement == null)
ohair@286 127 findFaultCodeElement();
ohair@286 128 String nsName = this.faultCodeElement.getNamespaceURI(prefix);
ohair@286 129 return NameImpl.createFromQualifiedName(faultcodeString, nsName);
ohair@286 130 }
ohair@286 131
ohair@286 132 public QName getFaultCodeAsQName() {
ohair@286 133 String faultcodeString = getFaultCode();
ohair@286 134 if (faultcodeString == null) {
ohair@286 135 return null;
ohair@286 136 }
ohair@286 137 if (this.faultCodeElement == null)
ohair@286 138 findFaultCodeElement();
ohair@286 139 return convertCodeToQName(faultcodeString, this.faultCodeElement);
ohair@286 140 }
ohair@286 141
ohair@286 142 public void setFaultString(String faultString) throws SOAPException {
ohair@286 143
ohair@286 144 if (this.faultStringElement == null)
ohair@286 145 findFaultStringElement();
ohair@286 146
ohair@286 147 if (this.faultStringElement == null)
ohair@286 148 this.faultStringElement = addSOAPFaultElement("faultstring");
ohair@286 149 else {
ohair@286 150 this.faultStringElement.removeContents();
ohair@286 151 //this.faultStringElement.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "lang");
ohair@286 152 this.faultStringElement.removeAttribute("xml:lang");
ohair@286 153 }
ohair@286 154
ohair@286 155 this.faultStringElement.addTextNode(faultString);
ohair@286 156 }
ohair@286 157
ohair@286 158 public String getFaultString() {
ohair@286 159 if (this.faultStringElement == null)
ohair@286 160 findFaultStringElement();
ohair@286 161 return this.faultStringElement.getValue();
ohair@286 162
ohair@286 163 }
ohair@286 164
ohair@286 165 public Locale getFaultStringLocale() {
ohair@286 166 if (this.faultStringElement == null)
ohair@286 167 findFaultStringElement();
ohair@286 168 if (this.faultStringElement != null) {
ohair@286 169 String xmlLangAttr =
ohair@286 170 this.faultStringElement.getAttributeValue(
ohair@286 171 NameImpl.createFromUnqualifiedName("xml:lang"));
ohair@286 172 if (xmlLangAttr != null)
ohair@286 173 return xmlLangToLocale(xmlLangAttr);
ohair@286 174 }
ohair@286 175 return null;
ohair@286 176 }
ohair@286 177
ohair@286 178 public void setFaultString(String faultString, Locale locale)
ohair@286 179 throws SOAPException {
ohair@286 180 setFaultString(faultString);
ohair@286 181 this.faultStringElement.addAttribute(
ohair@286 182 NameImpl.createFromTagName("xml:lang"),
ohair@286 183 localeToXmlLang(locale));
ohair@286 184 }
ohair@286 185
ohair@286 186 protected boolean isStandardFaultElement(String localName) {
ohair@286 187 if (localName.equalsIgnoreCase("detail") ||
ohair@286 188 localName.equalsIgnoreCase("faultcode") ||
ohair@286 189 localName.equalsIgnoreCase("faultstring") ||
ohair@286 190 localName.equalsIgnoreCase("faultactor")) {
ohair@286 191 return true;
ohair@286 192 }
ohair@286 193 return false;
ohair@286 194 }
ohair@286 195
ohair@286 196 public void appendFaultSubcode(QName subcode) {
ohair@286 197 log.log(
ohair@286 198 Level.SEVERE,
ohair@286 199 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 200 "appendFaultSubcode");
ohair@286 201 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 202 }
ohair@286 203
ohair@286 204 public void removeAllFaultSubcodes() {
ohair@286 205 log.log(
ohair@286 206 Level.SEVERE,
ohair@286 207 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 208 "removeAllFaultSubcodes");
ohair@286 209 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 210 }
ohair@286 211
ohair@286 212 public Iterator getFaultSubcodes() {
ohair@286 213 log.log(
ohair@286 214 Level.SEVERE,
ohair@286 215 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 216 "getFaultSubcodes");
ohair@286 217 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 218 }
ohair@286 219
ohair@286 220 public String getFaultReasonText(Locale locale) {
ohair@286 221 log.log(
ohair@286 222 Level.SEVERE,
ohair@286 223 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 224 "getFaultReasonText");
ohair@286 225 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 226 }
ohair@286 227
ohair@286 228 public Iterator getFaultReasonTexts() {
ohair@286 229 log.log(
ohair@286 230 Level.SEVERE,
ohair@286 231 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 232 "getFaultReasonTexts");
ohair@286 233 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 234 }
ohair@286 235
ohair@286 236 public Iterator getFaultReasonLocales() {
ohair@286 237 log.log(
ohair@286 238 Level.SEVERE,
ohair@286 239 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 240 "getFaultReasonLocales");
ohair@286 241 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 242 }
ohair@286 243
ohair@286 244 public void addFaultReasonText(String text, java.util.Locale locale)
ohair@286 245 throws SOAPException {
ohair@286 246 log.log(
ohair@286 247 Level.SEVERE,
ohair@286 248 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 249 "addFaultReasonText");
ohair@286 250 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 251 }
ohair@286 252
ohair@286 253 public String getFaultRole() {
ohair@286 254 log.log(
ohair@286 255 Level.SEVERE,
ohair@286 256 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 257 "getFaultRole");
ohair@286 258 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 259 }
ohair@286 260
ohair@286 261 public void setFaultRole(String uri) {
ohair@286 262 log.log(
ohair@286 263 Level.SEVERE,
ohair@286 264 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 265 "setFaultRole");
ohair@286 266 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 267 }
ohair@286 268
ohair@286 269 public String getFaultNode() {
ohair@286 270 log.log(
ohair@286 271 Level.SEVERE,
ohair@286 272 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 273 "getFaultNode");
ohair@286 274 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 275 }
ohair@286 276
ohair@286 277 public void setFaultNode(String uri) {
ohair@286 278 log.log(
ohair@286 279 Level.SEVERE,
ohair@286 280 "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
ohair@286 281 "setFaultNode");
ohair@286 282 throw new UnsupportedOperationException("Not supported in SOAP 1.1");
ohair@286 283 }
ohair@286 284
ohair@286 285 protected QName getDefaultFaultCode() {
ohair@286 286 return new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Server");
ohair@286 287 }
ohair@286 288
ohair@286 289 public SOAPElement addChildElement(SOAPElement element)
ohair@286 290 throws SOAPException {
ohair@286 291 String localName = element.getLocalName();
ohair@286 292 if ("Detail".equalsIgnoreCase(localName)) {
ohair@286 293 if (hasDetail()) {
ohair@286 294 log.severe("SAAJ0305.ver1_2.detail.exists.error");
ohair@286 295 throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
ohair@286 296 }
ohair@286 297 }
ohair@286 298 return super.addChildElement(element);
ohair@286 299 }
ohair@286 300
ohair@286 301 protected FaultElementImpl createSOAPFaultElement(QName qname) {
ohair@286 302 return new FaultElement1_1Impl(
ohair@286 303 ((SOAPDocument) getOwnerDocument()).getDocument(),
ohair@286 304 qname);
ohair@286 305 }
ohair@286 306
ohair@286 307 protected FaultElementImpl createSOAPFaultElement(Name qname) {
ohair@286 308 return new FaultElement1_1Impl(
ohair@286 309 ((SOAPDocument) getOwnerDocument()).getDocument(),
ohair@286 310 (NameImpl)qname);
ohair@286 311 }
ohair@286 312
ohair@286 313 public void setFaultCode(String faultCode, String prefix, String uri)
ohair@286 314 throws SOAPException {
ohair@286 315 if (prefix == null || "".equals(prefix)) {
ohair@286 316 if (uri != null && !"".equals(uri)) {
ohair@286 317 prefix = getNamespacePrefix(uri);
ohair@286 318 if (prefix == null || "".equals(prefix)) {
ohair@286 319 prefix = "ns0";
ohair@286 320 }
ohair@286 321 }
ohair@286 322 }
ohair@286 323
ohair@286 324 if (this.faultCodeElement == null)
ohair@286 325 findFaultCodeElement();
ohair@286 326
ohair@286 327 if (this.faultCodeElement == null)
ohair@286 328 this.faultCodeElement = addFaultCodeElement();
ohair@286 329 else
ohair@286 330 this.faultCodeElement.removeContents();
ohair@286 331
ohair@286 332 if (uri == null || "".equals(uri)) {
ohair@286 333 if (prefix != null && !"".equals("prefix")) {
ohair@286 334 uri = this.faultCodeElement.getNamespaceURI(prefix);
ohair@286 335 }
ohair@286 336 }
ohair@286 337
ohair@286 338 if (uri == null || "".equals(uri)) {
ohair@286 339 if (prefix != null && !"".equals(prefix)) {
ohair@286 340 //cannot allow an empty URI for a non-Empty prefix
ohair@286 341 log.log(Level.SEVERE, "SAAJ0307.impl.no.ns.URI", new Object[]{prefix + ":" + faultCode});
ohair@286 342 throw new SOAPExceptionImpl("Empty/Null NamespaceURI specified for faultCode \"" + prefix + ":" + faultCode + "\"");
ohair@286 343 } else {
ohair@286 344 uri = "";
ohair@286 345 }
ohair@286 346 }
ohair@286 347
ohair@286 348 checkIfStandardFaultCode(faultCode, uri);
ohair@286 349 ((FaultElementImpl) this.faultCodeElement).ensureNamespaceIsDeclared(prefix, uri);
ohair@286 350
ohair@286 351 if (prefix == null || "".equals(prefix)) {
ohair@286 352 finallySetFaultCode(faultCode);
ohair@286 353 } else {
ohair@286 354 finallySetFaultCode(prefix + ":" + faultCode);
ohair@286 355 }
ohair@286 356 }
ohair@286 357
ohair@286 358 private boolean standardFaultCode(String faultCode) {
ohair@286 359 if (faultCode.equals("VersionMismatch") || faultCode.equals("MustUnderstand")
ohair@286 360 || faultCode.equals("Client") || faultCode.equals("Server")) {
ohair@286 361 return true;
ohair@286 362 }
ohair@286 363 if (faultCode.startsWith("VersionMismatch.") || faultCode.startsWith("MustUnderstand.")
ohair@286 364 || faultCode.startsWith("Client.") || faultCode.startsWith("Server.")) {
ohair@286 365 return true;
ohair@286 366 }
ohair@286 367 return false;
ohair@286 368 }
ohair@286 369
ohair@286 370 public void setFaultActor(String faultActor) throws SOAPException {
ohair@286 371 if (this.faultActorElement == null)
ohair@286 372 findFaultActorElement();
ohair@286 373 if (this.faultActorElement != null)
ohair@286 374 this.faultActorElement.detachNode();
ohair@286 375 if (faultActor == null)
ohair@286 376 return;
ohair@286 377 this.faultActorElement =
ohair@286 378 createSOAPFaultElement(getFaultActorName());
ohair@286 379 this.faultActorElement.addTextNode(faultActor);
ohair@286 380 if (hasDetail()) {
ohair@286 381 insertBefore(this.faultActorElement, this.detail);
ohair@286 382 return;
ohair@286 383 }
ohair@286 384 addNode(this.faultActorElement);
ohair@286 385
ohair@286 386 }
ohair@286 387 }

mercurial