ohair@286: /* alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.xml.internal.ws.protocol.soap; ohair@286: ohair@286: import com.sun.xml.internal.ws.api.SOAPVersion; ohair@286: import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_11; ohair@286: import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_12; ohair@286: import com.sun.xml.internal.ws.api.WSBinding; ohair@286: import com.sun.xml.internal.ws.api.message.Header; ohair@286: import com.sun.xml.internal.ws.api.message.Message; alanb@368: import com.sun.xml.internal.ws.api.message.MessageHeaders; ohair@286: import com.sun.xml.internal.ws.api.pipe.Tube; ohair@286: import com.sun.xml.internal.ws.api.pipe.TubeCloner; ohair@286: import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl; ohair@286: import com.sun.xml.internal.ws.binding.SOAPBindingImpl; ohair@286: import com.sun.xml.internal.ws.message.DOMHeader; ohair@286: import com.sun.xml.internal.ws.fault.SOAPFaultBuilder; ohair@286: import org.w3c.dom.Element; ohair@286: ohair@286: import javax.xml.namespace.QName; ohair@286: import javax.xml.soap.SOAPElement; ohair@286: import javax.xml.soap.SOAPException; ohair@286: import javax.xml.soap.SOAPFault; ohair@286: import javax.xml.ws.WebServiceException; ohair@286: import javax.xml.ws.soap.SOAPBinding; ohair@286: import javax.xml.ws.soap.SOAPFaultException; ohair@286: import java.util.Set; ohair@286: import java.util.logging.Logger; ohair@286: ohair@286: /** ohair@286: * @author Rama Pulavarthi ohair@286: */ ohair@286: ohair@286: abstract class MUTube extends AbstractFilterTubeImpl { ohair@286: ohair@286: private static final String MU_FAULT_DETAIL_LOCALPART = "NotUnderstood"; ohair@286: private final static QName MU_HEADER_DETAIL = new QName(SOAPVersion.SOAP_12.nsUri, MU_FAULT_DETAIL_LOCALPART); ohair@286: //TODO: change ohair@286: protected static final Logger logger = Logger.getLogger( ohair@286: com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".soap.decoder"); ohair@286: private final static String MUST_UNDERSTAND_FAULT_MESSAGE_STRING = ohair@286: "One or more mandatory SOAP header blocks not understood"; ohair@286: ohair@286: protected final SOAPVersion soapVersion; ohair@286: protected SOAPBindingImpl binding; ohair@286: ohair@286: protected MUTube(WSBinding binding, Tube next) { ohair@286: super(next); ohair@286: // MUPipe should n't be used for bindings other than SOAP. ohair@286: if (!(binding instanceof SOAPBinding)) { ohair@286: throw new WebServiceException( ohair@286: "MUPipe should n't be used for bindings other than SOAP."); ohair@286: } ohair@286: this.binding = (SOAPBindingImpl) binding; ohair@286: this.soapVersion = binding.getSOAPVersion(); ohair@286: } ohair@286: ohair@286: protected MUTube(MUTube that, TubeCloner cloner) { ohair@286: super(that, cloner); ohair@286: binding = that.binding; ohair@286: soapVersion = that.soapVersion; ohair@286: } ohair@286: ohair@286: /** ohair@286: * @param headers HeaderList that needs MU processing ohair@286: * @param roles Roles configured on the Binding. Required Roles supposed to be assumbed a by a ohair@286: * SOAP Binding implementation are added. ohair@286: * @param handlerKnownHeaders Set of headers that the handlerchain associated with the binding understands ohair@286: * @return returns the headers that have mustUnderstand attribute and are not understood ohair@286: * by the binding. ohair@286: */ alanb@368: public final Set getMisUnderstoodHeaders(MessageHeaders headers, Set roles, ohair@286: Set handlerKnownHeaders) { alanb@368: return headers.getNotUnderstoodHeaders(roles, handlerKnownHeaders, binding); alanb@368: ohair@286: } ohair@286: ohair@286: /** ohair@286: * @param notUnderstoodHeaders ohair@286: * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault. ohair@286: * notUnderstoodHeaders are added in the fault detail. ohair@286: */ ohair@286: final SOAPFaultException createMUSOAPFaultException(Set notUnderstoodHeaders) { ohair@286: try { ohair@286: SOAPFault fault = soapVersion.getSOAPFactory().createFault( ohair@286: MUST_UNDERSTAND_FAULT_MESSAGE_STRING, ohair@286: soapVersion.faultCodeMustUnderstand); ohair@286: fault.setFaultString("MustUnderstand headers:" + ohair@286: notUnderstoodHeaders + " are not understood"); ohair@286: return new SOAPFaultException(fault); ohair@286: } catch (SOAPException e) { ohair@286: throw new WebServiceException(e); ohair@286: } ohair@286: } ohair@286: ohair@286: /** ohair@286: * This should be used only in ServerMUPipe ohair@286: * ohair@286: * @param notUnderstoodHeaders ohair@286: * @return Message representing a SOAPFault ohair@286: * In SOAP 1.1, notUnderstoodHeaders are added in the fault Detail ohair@286: * in SOAP 1.2, notUnderstoodHeaders are added as the SOAP Headers ohair@286: */ ohair@286: ohair@286: final Message createMUSOAPFaultMessage(Set notUnderstoodHeaders) { ohair@286: try { ohair@286: String faultString = MUST_UNDERSTAND_FAULT_MESSAGE_STRING; ohair@286: if (soapVersion == SOAP_11) { ohair@286: faultString = "MustUnderstand headers:" + notUnderstoodHeaders + " are not understood"; ohair@286: } ohair@286: Message muFaultMessage = SOAPFaultBuilder.createSOAPFaultMessage( ohair@286: soapVersion,faultString,soapVersion.faultCodeMustUnderstand); ohair@286: ohair@286: if (soapVersion == SOAP_12) { ohair@286: addHeader(muFaultMessage, notUnderstoodHeaders); ohair@286: } ohair@286: return muFaultMessage; ohair@286: } catch (SOAPException e) { ohair@286: throw new WebServiceException(e); ohair@286: } ohair@286: } ohair@286: ohair@286: private static void addHeader(Message m, Set notUnderstoodHeaders) throws SOAPException { ohair@286: for (QName qname : notUnderstoodHeaders) { ohair@286: SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL); ohair@286: soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI()); ohair@286: soapEl.setAttribute("qname", "abc:" + qname.getLocalPart()); ohair@286: Header header = new DOMHeader(soapEl); ohair@286: m.getHeaders().add(header); ohair@286: } ohair@286: } ohair@286: }