src/share/jaxws_classes/com/sun/xml/internal/ws/protocol/soap/MUTube.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2010, 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 package com.sun.xml.internal.ws.protocol.soap;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 29 import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_11;
ohair@286 30 import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_12;
ohair@286 31 import com.sun.xml.internal.ws.api.WSBinding;
ohair@286 32 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
ohair@286 33 import com.sun.xml.internal.ws.api.message.Header;
ohair@286 34 import com.sun.xml.internal.ws.api.message.HeaderList;
ohair@286 35 import com.sun.xml.internal.ws.api.message.Message;
ohair@286 36 import com.sun.xml.internal.ws.api.pipe.Tube;
ohair@286 37 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
ohair@286 38 import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
ohair@286 39 import com.sun.xml.internal.ws.binding.BindingImpl;
ohair@286 40 import com.sun.xml.internal.ws.binding.SOAPBindingImpl;
ohair@286 41 import com.sun.xml.internal.ws.message.DOMHeader;
ohair@286 42 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
ohair@286 43 import org.w3c.dom.Element;
ohair@286 44
ohair@286 45 import javax.xml.namespace.QName;
ohair@286 46 import javax.xml.soap.SOAPElement;
ohair@286 47 import javax.xml.soap.SOAPException;
ohair@286 48 import javax.xml.soap.SOAPFault;
ohair@286 49 import javax.xml.ws.WebServiceException;
ohair@286 50 import javax.xml.ws.soap.SOAPBinding;
ohair@286 51 import javax.xml.ws.soap.SOAPFaultException;
ohair@286 52 import java.util.HashSet;
ohair@286 53 import java.util.Set;
ohair@286 54 import java.util.logging.Logger;
ohair@286 55
ohair@286 56 /**
ohair@286 57 * @author Rama Pulavarthi
ohair@286 58 */
ohair@286 59
ohair@286 60 abstract class MUTube extends AbstractFilterTubeImpl {
ohair@286 61
ohair@286 62 private static final String MU_FAULT_DETAIL_LOCALPART = "NotUnderstood";
ohair@286 63 private final static QName MU_HEADER_DETAIL = new QName(SOAPVersion.SOAP_12.nsUri, MU_FAULT_DETAIL_LOCALPART);
ohair@286 64 //TODO: change
ohair@286 65 protected static final Logger logger = Logger.getLogger(
ohair@286 66 com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".soap.decoder");
ohair@286 67 private final static String MUST_UNDERSTAND_FAULT_MESSAGE_STRING =
ohair@286 68 "One or more mandatory SOAP header blocks not understood";
ohair@286 69
ohair@286 70 protected final SOAPVersion soapVersion;
ohair@286 71 protected SOAPBindingImpl binding;
ohair@286 72
ohair@286 73 protected MUTube(WSBinding binding, Tube next) {
ohair@286 74 super(next);
ohair@286 75 // MUPipe should n't be used for bindings other than SOAP.
ohair@286 76 if (!(binding instanceof SOAPBinding)) {
ohair@286 77 throw new WebServiceException(
ohair@286 78 "MUPipe should n't be used for bindings other than SOAP.");
ohair@286 79 }
ohair@286 80 this.binding = (SOAPBindingImpl) binding;
ohair@286 81 this.soapVersion = binding.getSOAPVersion();
ohair@286 82 }
ohair@286 83
ohair@286 84 protected MUTube(MUTube that, TubeCloner cloner) {
ohair@286 85 super(that, cloner);
ohair@286 86 binding = that.binding;
ohair@286 87 soapVersion = that.soapVersion;
ohair@286 88 }
ohair@286 89
ohair@286 90 /**
ohair@286 91 * @param headers HeaderList that needs MU processing
ohair@286 92 * @param roles Roles configured on the Binding. Required Roles supposed to be assumbed a by a
ohair@286 93 * SOAP Binding implementation are added.
ohair@286 94 * @param handlerKnownHeaders Set of headers that the handlerchain associated with the binding understands
ohair@286 95 * @return returns the headers that have mustUnderstand attribute and are not understood
ohair@286 96 * by the binding.
ohair@286 97 */
ohair@286 98 public final Set<QName> getMisUnderstoodHeaders(HeaderList headers, Set<String> roles,
ohair@286 99 Set<QName> handlerKnownHeaders) {
ohair@286 100 Set<QName> notUnderstoodHeaders = null;
ohair@286 101 for (int i = 0; i < headers.size(); i++) {
ohair@286 102 if (!headers.isUnderstood(i)) {
ohair@286 103 Header header = headers.get(i);
ohair@286 104 if (!header.isIgnorable(soapVersion, roles)) {
ohair@286 105 QName qName = new QName(header.getNamespaceURI(), header.getLocalPart());
ohair@286 106 // see if the binding can understand it
ohair@286 107 if (!binding.understandsHeader(qName)) {
ohair@286 108 if (!handlerKnownHeaders.contains(qName)) {
ohair@286 109 logger.info("Element not understood=" + qName);
ohair@286 110 if (notUnderstoodHeaders == null)
ohair@286 111 notUnderstoodHeaders = new HashSet<QName>();
ohair@286 112 notUnderstoodHeaders.add(qName);
ohair@286 113 }
ohair@286 114 }
ohair@286 115 }
ohair@286 116 }
ohair@286 117 }
ohair@286 118 return notUnderstoodHeaders;
ohair@286 119 }
ohair@286 120
ohair@286 121 /**
ohair@286 122 * @param notUnderstoodHeaders
ohair@286 123 * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault.
ohair@286 124 * notUnderstoodHeaders are added in the fault detail.
ohair@286 125 */
ohair@286 126 final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) {
ohair@286 127 try {
ohair@286 128 SOAPFault fault = soapVersion.getSOAPFactory().createFault(
ohair@286 129 MUST_UNDERSTAND_FAULT_MESSAGE_STRING,
ohair@286 130 soapVersion.faultCodeMustUnderstand);
ohair@286 131 fault.setFaultString("MustUnderstand headers:" +
ohair@286 132 notUnderstoodHeaders + " are not understood");
ohair@286 133 return new SOAPFaultException(fault);
ohair@286 134 } catch (SOAPException e) {
ohair@286 135 throw new WebServiceException(e);
ohair@286 136 }
ohair@286 137 }
ohair@286 138
ohair@286 139 /**
ohair@286 140 * This should be used only in ServerMUPipe
ohair@286 141 *
ohair@286 142 * @param notUnderstoodHeaders
ohair@286 143 * @return Message representing a SOAPFault
ohair@286 144 * In SOAP 1.1, notUnderstoodHeaders are added in the fault Detail
ohair@286 145 * in SOAP 1.2, notUnderstoodHeaders are added as the SOAP Headers
ohair@286 146 */
ohair@286 147
ohair@286 148 final Message createMUSOAPFaultMessage(Set<QName> notUnderstoodHeaders) {
ohair@286 149 try {
ohair@286 150 String faultString = MUST_UNDERSTAND_FAULT_MESSAGE_STRING;
ohair@286 151 if (soapVersion == SOAP_11) {
ohair@286 152 faultString = "MustUnderstand headers:" + notUnderstoodHeaders + " are not understood";
ohair@286 153 }
ohair@286 154 Message muFaultMessage = SOAPFaultBuilder.createSOAPFaultMessage(
ohair@286 155 soapVersion,faultString,soapVersion.faultCodeMustUnderstand);
ohair@286 156
ohair@286 157 if (soapVersion == SOAP_12) {
ohair@286 158 addHeader(muFaultMessage, notUnderstoodHeaders);
ohair@286 159 }
ohair@286 160 return muFaultMessage;
ohair@286 161 } catch (SOAPException e) {
ohair@286 162 throw new WebServiceException(e);
ohair@286 163 }
ohair@286 164 }
ohair@286 165
ohair@286 166 private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
ohair@286 167 for (QName qname : notUnderstoodHeaders) {
ohair@286 168 SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
ohair@286 169 soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
ohair@286 170 soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
ohair@286 171 Header header = new DOMHeader<Element>(soapEl);
ohair@286 172 m.getHeaders().add(header);
ohair@286 173 }
ohair@286 174 }
ohair@286 175 }

mercurial