src/share/jaxws_classes/com/sun/xml/internal/ws/protocol/soap/MUTube.java

Wed, 27 Apr 2016 01:27:09 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:27:09 +0800
changeset 0
373ffda63c9a
child 637
9c07ef4934dd
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17

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

mercurial