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