1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/protocol/soap/MUTube.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,175 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.protocol.soap; 1.30 + 1.31 +import com.sun.xml.internal.ws.api.SOAPVersion; 1.32 +import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_11; 1.33 +import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_12; 1.34 +import com.sun.xml.internal.ws.api.WSBinding; 1.35 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion; 1.36 +import com.sun.xml.internal.ws.api.message.Header; 1.37 +import com.sun.xml.internal.ws.api.message.HeaderList; 1.38 +import com.sun.xml.internal.ws.api.message.Message; 1.39 +import com.sun.xml.internal.ws.api.pipe.Tube; 1.40 +import com.sun.xml.internal.ws.api.pipe.TubeCloner; 1.41 +import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl; 1.42 +import com.sun.xml.internal.ws.binding.BindingImpl; 1.43 +import com.sun.xml.internal.ws.binding.SOAPBindingImpl; 1.44 +import com.sun.xml.internal.ws.message.DOMHeader; 1.45 +import com.sun.xml.internal.ws.fault.SOAPFaultBuilder; 1.46 +import org.w3c.dom.Element; 1.47 + 1.48 +import javax.xml.namespace.QName; 1.49 +import javax.xml.soap.SOAPElement; 1.50 +import javax.xml.soap.SOAPException; 1.51 +import javax.xml.soap.SOAPFault; 1.52 +import javax.xml.ws.WebServiceException; 1.53 +import javax.xml.ws.soap.SOAPBinding; 1.54 +import javax.xml.ws.soap.SOAPFaultException; 1.55 +import java.util.HashSet; 1.56 +import java.util.Set; 1.57 +import java.util.logging.Logger; 1.58 + 1.59 +/** 1.60 + * @author Rama Pulavarthi 1.61 + */ 1.62 + 1.63 +abstract class MUTube extends AbstractFilterTubeImpl { 1.64 + 1.65 + private static final String MU_FAULT_DETAIL_LOCALPART = "NotUnderstood"; 1.66 + private final static QName MU_HEADER_DETAIL = new QName(SOAPVersion.SOAP_12.nsUri, MU_FAULT_DETAIL_LOCALPART); 1.67 + //TODO: change 1.68 + protected static final Logger logger = Logger.getLogger( 1.69 + com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".soap.decoder"); 1.70 + private final static String MUST_UNDERSTAND_FAULT_MESSAGE_STRING = 1.71 + "One or more mandatory SOAP header blocks not understood"; 1.72 + 1.73 + protected final SOAPVersion soapVersion; 1.74 + protected SOAPBindingImpl binding; 1.75 + 1.76 + protected MUTube(WSBinding binding, Tube next) { 1.77 + super(next); 1.78 + // MUPipe should n't be used for bindings other than SOAP. 1.79 + if (!(binding instanceof SOAPBinding)) { 1.80 + throw new WebServiceException( 1.81 + "MUPipe should n't be used for bindings other than SOAP."); 1.82 + } 1.83 + this.binding = (SOAPBindingImpl) binding; 1.84 + this.soapVersion = binding.getSOAPVersion(); 1.85 + } 1.86 + 1.87 + protected MUTube(MUTube that, TubeCloner cloner) { 1.88 + super(that, cloner); 1.89 + binding = that.binding; 1.90 + soapVersion = that.soapVersion; 1.91 + } 1.92 + 1.93 + /** 1.94 + * @param headers HeaderList that needs MU processing 1.95 + * @param roles Roles configured on the Binding. Required Roles supposed to be assumbed a by a 1.96 + * SOAP Binding implementation are added. 1.97 + * @param handlerKnownHeaders Set of headers that the handlerchain associated with the binding understands 1.98 + * @return returns the headers that have mustUnderstand attribute and are not understood 1.99 + * by the binding. 1.100 + */ 1.101 + public final Set<QName> getMisUnderstoodHeaders(HeaderList headers, Set<String> roles, 1.102 + Set<QName> handlerKnownHeaders) { 1.103 + Set<QName> notUnderstoodHeaders = null; 1.104 + for (int i = 0; i < headers.size(); i++) { 1.105 + if (!headers.isUnderstood(i)) { 1.106 + Header header = headers.get(i); 1.107 + if (!header.isIgnorable(soapVersion, roles)) { 1.108 + QName qName = new QName(header.getNamespaceURI(), header.getLocalPart()); 1.109 + // see if the binding can understand it 1.110 + if (!binding.understandsHeader(qName)) { 1.111 + if (!handlerKnownHeaders.contains(qName)) { 1.112 + logger.info("Element not understood=" + qName); 1.113 + if (notUnderstoodHeaders == null) 1.114 + notUnderstoodHeaders = new HashSet<QName>(); 1.115 + notUnderstoodHeaders.add(qName); 1.116 + } 1.117 + } 1.118 + } 1.119 + } 1.120 + } 1.121 + return notUnderstoodHeaders; 1.122 + } 1.123 + 1.124 + /** 1.125 + * @param notUnderstoodHeaders 1.126 + * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault. 1.127 + * notUnderstoodHeaders are added in the fault detail. 1.128 + */ 1.129 + final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) { 1.130 + try { 1.131 + SOAPFault fault = soapVersion.getSOAPFactory().createFault( 1.132 + MUST_UNDERSTAND_FAULT_MESSAGE_STRING, 1.133 + soapVersion.faultCodeMustUnderstand); 1.134 + fault.setFaultString("MustUnderstand headers:" + 1.135 + notUnderstoodHeaders + " are not understood"); 1.136 + return new SOAPFaultException(fault); 1.137 + } catch (SOAPException e) { 1.138 + throw new WebServiceException(e); 1.139 + } 1.140 + } 1.141 + 1.142 + /** 1.143 + * This should be used only in ServerMUPipe 1.144 + * 1.145 + * @param notUnderstoodHeaders 1.146 + * @return Message representing a SOAPFault 1.147 + * In SOAP 1.1, notUnderstoodHeaders are added in the fault Detail 1.148 + * in SOAP 1.2, notUnderstoodHeaders are added as the SOAP Headers 1.149 + */ 1.150 + 1.151 + final Message createMUSOAPFaultMessage(Set<QName> notUnderstoodHeaders) { 1.152 + try { 1.153 + String faultString = MUST_UNDERSTAND_FAULT_MESSAGE_STRING; 1.154 + if (soapVersion == SOAP_11) { 1.155 + faultString = "MustUnderstand headers:" + notUnderstoodHeaders + " are not understood"; 1.156 + } 1.157 + Message muFaultMessage = SOAPFaultBuilder.createSOAPFaultMessage( 1.158 + soapVersion,faultString,soapVersion.faultCodeMustUnderstand); 1.159 + 1.160 + if (soapVersion == SOAP_12) { 1.161 + addHeader(muFaultMessage, notUnderstoodHeaders); 1.162 + } 1.163 + return muFaultMessage; 1.164 + } catch (SOAPException e) { 1.165 + throw new WebServiceException(e); 1.166 + } 1.167 + } 1.168 + 1.169 + private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException { 1.170 + for (QName qname : notUnderstoodHeaders) { 1.171 + SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL); 1.172 + soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI()); 1.173 + soapEl.setAttribute("qname", "abc:" + qname.getLocalPart()); 1.174 + Header header = new DOMHeader<Element>(soapEl); 1.175 + m.getHeaders().add(header); 1.176 + } 1.177 + } 1.178 +}