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 Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,155 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, 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.message.Header; 1.36 +import com.sun.xml.internal.ws.api.message.Message; 1.37 +import com.sun.xml.internal.ws.api.message.MessageHeaders; 1.38 +import com.sun.xml.internal.ws.api.pipe.Tube; 1.39 +import com.sun.xml.internal.ws.api.pipe.TubeCloner; 1.40 +import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl; 1.41 +import com.sun.xml.internal.ws.binding.SOAPBindingImpl; 1.42 +import com.sun.xml.internal.ws.message.DOMHeader; 1.43 +import com.sun.xml.internal.ws.fault.SOAPFaultBuilder; 1.44 +import org.w3c.dom.Element; 1.45 + 1.46 +import javax.xml.namespace.QName; 1.47 +import javax.xml.soap.SOAPElement; 1.48 +import javax.xml.soap.SOAPException; 1.49 +import javax.xml.soap.SOAPFault; 1.50 +import javax.xml.ws.WebServiceException; 1.51 +import javax.xml.ws.soap.SOAPBinding; 1.52 +import javax.xml.ws.soap.SOAPFaultException; 1.53 +import java.util.Set; 1.54 +import java.util.logging.Logger; 1.55 + 1.56 +/** 1.57 + * @author Rama Pulavarthi 1.58 + */ 1.59 + 1.60 +abstract class MUTube extends AbstractFilterTubeImpl { 1.61 + 1.62 + private static final String MU_FAULT_DETAIL_LOCALPART = "NotUnderstood"; 1.63 + private final static QName MU_HEADER_DETAIL = new QName(SOAPVersion.SOAP_12.nsUri, MU_FAULT_DETAIL_LOCALPART); 1.64 + //TODO: change 1.65 + protected static final Logger logger = Logger.getLogger( 1.66 + com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".soap.decoder"); 1.67 + private final static String MUST_UNDERSTAND_FAULT_MESSAGE_STRING = 1.68 + "One or more mandatory SOAP header blocks not understood"; 1.69 + 1.70 + protected final SOAPVersion soapVersion; 1.71 + protected SOAPBindingImpl binding; 1.72 + 1.73 + protected MUTube(WSBinding binding, Tube next) { 1.74 + super(next); 1.75 + // MUPipe should n't be used for bindings other than SOAP. 1.76 + if (!(binding instanceof SOAPBinding)) { 1.77 + throw new WebServiceException( 1.78 + "MUPipe should n't be used for bindings other than SOAP."); 1.79 + } 1.80 + this.binding = (SOAPBindingImpl) binding; 1.81 + this.soapVersion = binding.getSOAPVersion(); 1.82 + } 1.83 + 1.84 + protected MUTube(MUTube that, TubeCloner cloner) { 1.85 + super(that, cloner); 1.86 + binding = that.binding; 1.87 + soapVersion = that.soapVersion; 1.88 + } 1.89 + 1.90 + /** 1.91 + * @param headers HeaderList that needs MU processing 1.92 + * @param roles Roles configured on the Binding. Required Roles supposed to be assumbed a by a 1.93 + * SOAP Binding implementation are added. 1.94 + * @param handlerKnownHeaders Set of headers that the handlerchain associated with the binding understands 1.95 + * @return returns the headers that have mustUnderstand attribute and are not understood 1.96 + * by the binding. 1.97 + */ 1.98 + public final Set<QName> getMisUnderstoodHeaders(MessageHeaders headers, Set<String> roles, 1.99 + Set<QName> handlerKnownHeaders) { 1.100 + return headers.getNotUnderstoodHeaders(roles, handlerKnownHeaders, binding); 1.101 + 1.102 + } 1.103 + 1.104 + /** 1.105 + * @param notUnderstoodHeaders 1.106 + * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault. 1.107 + * notUnderstoodHeaders are added in the fault detail. 1.108 + */ 1.109 + final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) { 1.110 + try { 1.111 + SOAPFault fault = soapVersion.getSOAPFactory().createFault( 1.112 + MUST_UNDERSTAND_FAULT_MESSAGE_STRING, 1.113 + soapVersion.faultCodeMustUnderstand); 1.114 + fault.setFaultString("MustUnderstand headers:" + 1.115 + notUnderstoodHeaders + " are not understood"); 1.116 + return new SOAPFaultException(fault); 1.117 + } catch (SOAPException e) { 1.118 + throw new WebServiceException(e); 1.119 + } 1.120 + } 1.121 + 1.122 + /** 1.123 + * This should be used only in ServerMUPipe 1.124 + * 1.125 + * @param notUnderstoodHeaders 1.126 + * @return Message representing a SOAPFault 1.127 + * In SOAP 1.1, notUnderstoodHeaders are added in the fault Detail 1.128 + * in SOAP 1.2, notUnderstoodHeaders are added as the SOAP Headers 1.129 + */ 1.130 + 1.131 + final Message createMUSOAPFaultMessage(Set<QName> notUnderstoodHeaders) { 1.132 + try { 1.133 + String faultString = MUST_UNDERSTAND_FAULT_MESSAGE_STRING; 1.134 + if (soapVersion == SOAP_11) { 1.135 + faultString = "MustUnderstand headers:" + notUnderstoodHeaders + " are not understood"; 1.136 + } 1.137 + Message muFaultMessage = SOAPFaultBuilder.createSOAPFaultMessage( 1.138 + soapVersion,faultString,soapVersion.faultCodeMustUnderstand); 1.139 + 1.140 + if (soapVersion == SOAP_12) { 1.141 + addHeader(muFaultMessage, notUnderstoodHeaders); 1.142 + } 1.143 + return muFaultMessage; 1.144 + } catch (SOAPException e) { 1.145 + throw new WebServiceException(e); 1.146 + } 1.147 + } 1.148 + 1.149 + private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException { 1.150 + for (QName qname : notUnderstoodHeaders) { 1.151 + SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL); 1.152 + soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI()); 1.153 + soapEl.setAttribute("qname", "abc:" + qname.getLocalPart()); 1.154 + Header header = new DOMHeader<Element>(soapEl); 1.155 + m.getHeaders().add(header); 1.156 + } 1.157 + } 1.158 +}