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

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.protocol.soap;
    28 import com.sun.xml.internal.ws.api.SOAPVersion;
    29 import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_11;
    30 import static com.sun.xml.internal.ws.api.SOAPVersion.SOAP_12;
    31 import com.sun.xml.internal.ws.api.WSBinding;
    32 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    33 import com.sun.xml.internal.ws.api.message.Header;
    34 import com.sun.xml.internal.ws.api.message.HeaderList;
    35 import com.sun.xml.internal.ws.api.message.Message;
    36 import com.sun.xml.internal.ws.api.pipe.Tube;
    37 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
    38 import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
    39 import com.sun.xml.internal.ws.binding.BindingImpl;
    40 import com.sun.xml.internal.ws.binding.SOAPBindingImpl;
    41 import com.sun.xml.internal.ws.message.DOMHeader;
    42 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
    43 import org.w3c.dom.Element;
    45 import javax.xml.namespace.QName;
    46 import javax.xml.soap.SOAPElement;
    47 import javax.xml.soap.SOAPException;
    48 import javax.xml.soap.SOAPFault;
    49 import javax.xml.ws.WebServiceException;
    50 import javax.xml.ws.soap.SOAPBinding;
    51 import javax.xml.ws.soap.SOAPFaultException;
    52 import java.util.HashSet;
    53 import java.util.Set;
    54 import java.util.logging.Logger;
    56 /**
    57  * @author Rama Pulavarthi
    58  */
    60 abstract class MUTube extends AbstractFilterTubeImpl {
    62     private static final String MU_FAULT_DETAIL_LOCALPART = "NotUnderstood";
    63     private final static QName MU_HEADER_DETAIL = new QName(SOAPVersion.SOAP_12.nsUri, MU_FAULT_DETAIL_LOCALPART);
    64     //TODO: change
    65     protected static final Logger logger = Logger.getLogger(
    66             com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".soap.decoder");
    67     private final static String MUST_UNDERSTAND_FAULT_MESSAGE_STRING =
    68             "One or more mandatory SOAP header blocks not understood";
    70     protected final SOAPVersion soapVersion;
    71     protected SOAPBindingImpl binding;
    73     protected MUTube(WSBinding binding, Tube next) {
    74         super(next);
    75         // MUPipe should n't be used for bindings other than SOAP.
    76         if (!(binding instanceof SOAPBinding)) {
    77             throw new WebServiceException(
    78                     "MUPipe should n't be used for bindings other than SOAP.");
    79         }
    80         this.binding = (SOAPBindingImpl) binding;
    81         this.soapVersion = binding.getSOAPVersion();
    82     }
    84     protected MUTube(MUTube that, TubeCloner cloner) {
    85         super(that, cloner);
    86         binding = that.binding;
    87         soapVersion = that.soapVersion;
    88     }
    90     /**
    91      * @param headers HeaderList that needs MU processing
    92      * @param roles        Roles configured on the Binding. Required Roles supposed to be assumbed a by a
    93      *                     SOAP Binding implementation are added.
    94      * @param handlerKnownHeaders Set of headers that the handlerchain associated with the binding understands
    95      * @return returns the headers that have mustUnderstand attribute and are not understood
    96      *         by the binding.
    97      */
    98     public final Set<QName> getMisUnderstoodHeaders(HeaderList headers, Set<String> roles,
    99                                                     Set<QName> handlerKnownHeaders) {
   100         Set<QName> notUnderstoodHeaders = null;
   101         for (int i = 0; i < headers.size(); i++) {
   102             if (!headers.isUnderstood(i)) {
   103                 Header header = headers.get(i);
   104                 if (!header.isIgnorable(soapVersion, roles)) {
   105                     QName qName = new QName(header.getNamespaceURI(), header.getLocalPart());
   106                     // see if the binding can understand it
   107                     if (!binding.understandsHeader(qName)) {
   108                         if (!handlerKnownHeaders.contains(qName)) {
   109                             logger.info("Element not understood=" + qName);
   110                             if (notUnderstoodHeaders == null)
   111                                 notUnderstoodHeaders = new HashSet<QName>();
   112                             notUnderstoodHeaders.add(qName);
   113                         }
   114                     }
   115                 }
   116             }
   117         }
   118         return notUnderstoodHeaders;
   119     }
   121     /**
   122      * @param notUnderstoodHeaders
   123      * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault.
   124      *         notUnderstoodHeaders are added in the fault detail.
   125      */
   126     final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) {
   127         try {
   128             SOAPFault fault = soapVersion.getSOAPFactory().createFault(
   129                 MUST_UNDERSTAND_FAULT_MESSAGE_STRING,
   130                 soapVersion.faultCodeMustUnderstand);
   131             fault.setFaultString("MustUnderstand headers:" +
   132                 notUnderstoodHeaders + " are not understood");
   133             return new SOAPFaultException(fault);
   134         } catch (SOAPException e) {
   135             throw new WebServiceException(e);
   136         }
   137     }
   139     /**
   140      * This should be used only in ServerMUPipe
   141      *
   142      * @param notUnderstoodHeaders
   143      * @return Message representing a SOAPFault
   144      *         In SOAP 1.1, notUnderstoodHeaders are added in the fault Detail
   145      *         in SOAP 1.2, notUnderstoodHeaders are added as the SOAP Headers
   146      */
   148     final Message createMUSOAPFaultMessage(Set<QName> notUnderstoodHeaders) {
   149         try {
   150             String faultString = MUST_UNDERSTAND_FAULT_MESSAGE_STRING;
   151             if (soapVersion == SOAP_11) {
   152                 faultString = "MustUnderstand headers:" + notUnderstoodHeaders + " are not understood";
   153             }
   154             Message  muFaultMessage = SOAPFaultBuilder.createSOAPFaultMessage(
   155                     soapVersion,faultString,soapVersion.faultCodeMustUnderstand);
   157             if (soapVersion == SOAP_12) {
   158                 addHeader(muFaultMessage, notUnderstoodHeaders);
   159             }
   160             return muFaultMessage;
   161         } catch (SOAPException e) {
   162             throw new WebServiceException(e);
   163         }
   164     }
   166     private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
   167         for (QName qname : notUnderstoodHeaders) {
   168             SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
   169             soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
   170             soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
   171             Header header = new DOMHeader<Element>(soapEl);
   172             m.getHeaders().add(header);
   173         }
   174     }
   175 }

mercurial