src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/SOAPExtensionHandler.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/SOAPExtensionHandler.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,471 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2012, 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.tools.internal.ws.wsdl.parser;
    1.30 +
    1.31 +import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
    1.32 +import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
    1.33 +import com.sun.tools.internal.ws.util.xml.XmlUtil;
    1.34 +import com.sun.tools.internal.ws.wsdl.document.soap.*;
    1.35 +import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl;
    1.36 +import org.w3c.dom.Element;
    1.37 +import org.xml.sax.Locator;
    1.38 +
    1.39 +import javax.xml.namespace.QName;
    1.40 +import java.util.Iterator;
    1.41 +import java.util.Map;
    1.42 +
    1.43 +/**
    1.44 + * The SOAP extension handler for WSDL.
    1.45 + *
    1.46 + * @author WS Development Team
    1.47 + */
    1.48 +public class SOAPExtensionHandler extends AbstractExtensionHandler {
    1.49 +
    1.50 +    public SOAPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
    1.51 +        super(extensionHandlerMap);
    1.52 +    }
    1.53 +
    1.54 +    public String getNamespaceURI() {
    1.55 +        return Constants.NS_WSDL_SOAP;
    1.56 +    }
    1.57 +
    1.58 +    public boolean handleDefinitionsExtension(
    1.59 +        TWSDLParserContext context,
    1.60 +        TWSDLExtensible parent,
    1.61 +        Element e) {
    1.62 +        Util.fail(
    1.63 +            "parsing.invalidExtensionElement",
    1.64 +            e.getTagName(),
    1.65 +            e.getNamespaceURI());
    1.66 +        return false; // keep compiler happy
    1.67 +    }
    1.68 +
    1.69 +    public boolean handleTypesExtension(
    1.70 +        com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context,
    1.71 +        TWSDLExtensible parent,
    1.72 +        Element e) {
    1.73 +        Util.fail(
    1.74 +            "parsing.invalidExtensionElement",
    1.75 +            e.getTagName(),
    1.76 +            e.getNamespaceURI());
    1.77 +        return false; // keep compiler happy
    1.78 +    }
    1.79 +
    1.80 +    protected SOAPBinding getSOAPBinding(Locator location){
    1.81 +        return new SOAPBinding(location);
    1.82 +    }
    1.83 +
    1.84 +    public boolean handleBindingExtension(
    1.85 +        TWSDLParserContext context,
    1.86 +        TWSDLExtensible parent,
    1.87 +        Element e) {
    1.88 +        if (XmlUtil.matchesTagNS(e, getBindingQName())) {
    1.89 +            context.push();
    1.90 +            context.registerNamespaces(e);
    1.91 +
    1.92 +            SOAPBinding binding = getSOAPBinding(context.getLocation(e));
    1.93 +
    1.94 +            // NOTE - the "transport" attribute is required according to section 3.3 of the WSDL 1.1 spec,
    1.95 +            // but optional according to the schema in appendix A 4.2 of the same document!
    1.96 +            String transport =
    1.97 +                Util.getRequiredAttribute(e, Constants.ATTR_TRANSPORT);
    1.98 +            binding.setTransport(transport);
    1.99 +
   1.100 +            String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
   1.101 +            if (style != null) {
   1.102 +                if (style.equals(Constants.ATTRVALUE_RPC)) {
   1.103 +                    binding.setStyle(SOAPStyle.RPC);
   1.104 +                } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
   1.105 +                    binding.setStyle(SOAPStyle.DOCUMENT);
   1.106 +                } else {
   1.107 +                    Util.fail(
   1.108 +                        "parsing.invalidAttributeValue",
   1.109 +                        Constants.ATTR_STYLE,
   1.110 +                        style);
   1.111 +                }
   1.112 +            }
   1.113 +            parent.addExtension(binding);
   1.114 +            context.pop();
   1.115 +//            context.fireDoneParsingEntity(getBindingQName(), binding);
   1.116 +            return true;
   1.117 +        } else {
   1.118 +            Util.fail(
   1.119 +                "parsing.invalidExtensionElement",
   1.120 +                e.getTagName(),
   1.121 +                e.getNamespaceURI());
   1.122 +            return false; // keep compiler happy
   1.123 +        }
   1.124 +    }
   1.125 +
   1.126 +    public boolean handleOperationExtension(
   1.127 +        TWSDLParserContext context,
   1.128 +        TWSDLExtensible parent,
   1.129 +        Element e) {
   1.130 +        if (XmlUtil.matchesTagNS(e, getOperationQName())) {
   1.131 +            context.push();
   1.132 +            context.registerNamespaces(e);
   1.133 +
   1.134 +            SOAPOperation operation = new SOAPOperation(context.getLocation(e));
   1.135 +
   1.136 +            String soapAction =
   1.137 +                XmlUtil.getAttributeOrNull(e, Constants.ATTR_SOAP_ACTION);
   1.138 +            if (soapAction != null) {
   1.139 +                operation.setSOAPAction(soapAction);
   1.140 +            }
   1.141 +
   1.142 +            String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
   1.143 +            if (style != null) {
   1.144 +                if (style.equals(Constants.ATTRVALUE_RPC)) {
   1.145 +                    operation.setStyle(SOAPStyle.RPC);
   1.146 +                } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
   1.147 +                    operation.setStyle(SOAPStyle.DOCUMENT);
   1.148 +                } else {
   1.149 +                    Util.fail(
   1.150 +                        "parsing.invalidAttributeValue",
   1.151 +                        Constants.ATTR_STYLE,
   1.152 +                        style);
   1.153 +                }
   1.154 +            }
   1.155 +            parent.addExtension(operation);
   1.156 +            context.pop();
   1.157 +//            context.fireDoneParsingEntity(
   1.158 +//                getOperationQName(),
   1.159 +//                operation);
   1.160 +            return true;
   1.161 +        } else {
   1.162 +            Util.fail(
   1.163 +                "parsing.invalidExtensionElement",
   1.164 +                e.getTagName(),
   1.165 +                e.getNamespaceURI());
   1.166 +            return false; // keep compiler happy
   1.167 +        }
   1.168 +    }
   1.169 +
   1.170 +    public boolean handleInputExtension(
   1.171 +        TWSDLParserContext context,
   1.172 +        TWSDLExtensible parent,
   1.173 +        Element e) {
   1.174 +        return handleInputOutputExtension(context, parent, e);
   1.175 +    }
   1.176 +    public boolean handleOutputExtension(
   1.177 +        TWSDLParserContext context,
   1.178 +        TWSDLExtensible parent,
   1.179 +        Element e) {
   1.180 +        return handleInputOutputExtension(context, parent, e);
   1.181 +    }
   1.182 +
   1.183 +    @Override
   1.184 +    protected boolean handleMIMEPartExtension(
   1.185 +        TWSDLParserContext context,
   1.186 +        TWSDLExtensible parent,
   1.187 +        Element e) {
   1.188 +        return handleInputOutputExtension(context, parent, e);
   1.189 +    }
   1.190 +
   1.191 +    protected boolean handleInputOutputExtension(
   1.192 +        TWSDLParserContext contextif,
   1.193 +        TWSDLExtensible parent,
   1.194 +        Element e) {
   1.195 +        TWSDLParserContextImpl context = (TWSDLParserContextImpl)contextif;
   1.196 +        if (XmlUtil.matchesTagNS(e, getBodyQName())) {
   1.197 +            context.push();
   1.198 +            context.registerNamespaces(e);
   1.199 +
   1.200 +            SOAPBody body = new SOAPBody(context.getLocation(e));
   1.201 +
   1.202 +            String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
   1.203 +            if (use != null) {
   1.204 +                if (use.equals(Constants.ATTRVALUE_LITERAL)) {
   1.205 +                    body.setUse(SOAPUse.LITERAL);
   1.206 +                } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
   1.207 +                    body.setUse(SOAPUse.ENCODED);
   1.208 +                } else {
   1.209 +                    Util.fail(
   1.210 +                        "parsing.invalidAttributeValue",
   1.211 +                        Constants.ATTR_USE,
   1.212 +                        use);
   1.213 +                }
   1.214 +            }
   1.215 +
   1.216 +            String namespace =
   1.217 +                XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
   1.218 +            if (namespace != null) {
   1.219 +                body.setNamespace(namespace);
   1.220 +            }
   1.221 +
   1.222 +            String encodingStyle =
   1.223 +                XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
   1.224 +            if (encodingStyle != null) {
   1.225 +                body.setEncodingStyle(encodingStyle);
   1.226 +            }
   1.227 +
   1.228 +            String parts = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARTS);
   1.229 +            if (parts != null) {
   1.230 +                body.setParts(parts);
   1.231 +            }
   1.232 +
   1.233 +            parent.addExtension(body);
   1.234 +            context.pop();
   1.235 +//            context.fireDoneParsingEntity(getBodyQName(), body);
   1.236 +            return true;
   1.237 +        } else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
   1.238 +            return handleHeaderElement(parent, e, context);
   1.239 +        } else {
   1.240 +            Util.fail("parsing.invalidExtensionElement", e.getTagName(), e.getNamespaceURI());
   1.241 +            return false; // keep compiler happy
   1.242 +        }
   1.243 +    }
   1.244 +
   1.245 +    private boolean handleHeaderElement(TWSDLExtensible parent, Element e, TWSDLParserContextImpl context) {
   1.246 +        context.push();
   1.247 +        context.registerNamespaces(e);
   1.248 +
   1.249 +        SOAPHeader header = new SOAPHeader(context.getLocation(e));
   1.250 +
   1.251 +        String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
   1.252 +        if (use != null) {
   1.253 +            if (use.equals(Constants.ATTRVALUE_LITERAL)) {
   1.254 +                header.setUse(SOAPUse.LITERAL);
   1.255 +            } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
   1.256 +                header.setUse(SOAPUse.ENCODED);
   1.257 +            } else {
   1.258 +                Util.fail("parsing.invalidAttributeValue", Constants.ATTR_USE, use);
   1.259 +            }
   1.260 +        }
   1.261 +
   1.262 +        String namespace = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
   1.263 +        if (namespace != null) {
   1.264 +            header.setNamespace(namespace);
   1.265 +        }
   1.266 +
   1.267 +        String encodingStyle = XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
   1.268 +        if (encodingStyle != null) {
   1.269 +            header.setEncodingStyle(encodingStyle);
   1.270 +        }
   1.271 +
   1.272 +        String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
   1.273 +        if (part != null) {
   1.274 +            header.setPart(part);
   1.275 +        }
   1.276 +
   1.277 +        String messageAttr = XmlUtil.getAttributeOrNull(e, Constants.ATTR_MESSAGE);
   1.278 +        if (messageAttr != null) {
   1.279 +            header.setMessage(context.translateQualifiedName(context.getLocation(e), messageAttr));
   1.280 +        }
   1.281 +
   1.282 +        for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
   1.283 +            Element e2 = Util.nextElement(iter);
   1.284 +            if (e2 == null)
   1.285 +                break;
   1.286 +
   1.287 +            if (XmlUtil.matchesTagNS(e2, getHeaderfaultQName())) {
   1.288 +                handleHeaderFaultElement(e, context, header, use, e2);
   1.289 +            } else {
   1.290 +                Util.fail("parsing.invalidElement", e2.getTagName(), e2.getNamespaceURI());
   1.291 +            }
   1.292 +        }
   1.293 +
   1.294 +        parent.addExtension(header);
   1.295 +        context.pop();
   1.296 +        context.fireDoneParsingEntity(getHeaderQName(), header);
   1.297 +        return true;
   1.298 +    }
   1.299 +
   1.300 +    private void handleHeaderFaultElement(Element e, TWSDLParserContextImpl context, SOAPHeader header, String use, Element e2) {
   1.301 +        context.push();
   1.302 +        context.registerNamespaces(e);
   1.303 +
   1.304 +        SOAPHeaderFault headerfault = new SOAPHeaderFault(context.getLocation(e));
   1.305 +
   1.306 +        String use2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_USE);
   1.307 +        if (use2 != null) {
   1.308 +            if (use2.equals(Constants.ATTRVALUE_LITERAL)) {
   1.309 +                headerfault.setUse(SOAPUse.LITERAL);
   1.310 +            } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
   1.311 +                headerfault.setUse(SOAPUse.ENCODED);
   1.312 +            } else {
   1.313 +                Util.fail("parsing.invalidAttributeValue", Constants.ATTR_USE, use2);
   1.314 +            }
   1.315 +        }
   1.316 +
   1.317 +        String namespace2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAMESPACE);
   1.318 +        if (namespace2 != null) {
   1.319 +            headerfault.setNamespace(namespace2);
   1.320 +        }
   1.321 +
   1.322 +        String encodingStyle2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_ENCODING_STYLE);
   1.323 +        if (encodingStyle2 != null) {
   1.324 +            headerfault.setEncodingStyle(encodingStyle2);
   1.325 +        }
   1.326 +
   1.327 +        String part2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_PART);
   1.328 +        if (part2 != null) {
   1.329 +            headerfault.setPart(part2);
   1.330 +        }
   1.331 +
   1.332 +        String messageAttr2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_MESSAGE);
   1.333 +        if (messageAttr2 != null) {
   1.334 +            headerfault.setMessage(
   1.335 +                context.translateQualifiedName(context.getLocation(e2), messageAttr2));
   1.336 +        }
   1.337 +
   1.338 +        header.add(headerfault);
   1.339 +        context.pop();
   1.340 +    }
   1.341 +
   1.342 +    public boolean handleFaultExtension(
   1.343 +        TWSDLParserContext context,
   1.344 +        TWSDLExtensible parent,
   1.345 +        Element e) {
   1.346 +        if (XmlUtil.matchesTagNS(e, getFaultQName())) {
   1.347 +            context.push();
   1.348 +            context.registerNamespaces(e);
   1.349 +
   1.350 +            SOAPFault fault = new SOAPFault(context.getLocation(e));
   1.351 +
   1.352 +            String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME);
   1.353 +            if (name != null) {
   1.354 +                fault.setName(name);
   1.355 +            }
   1.356 +
   1.357 +            String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
   1.358 +            if (use != null) {
   1.359 +                if (use.equals(Constants.ATTRVALUE_LITERAL)) {
   1.360 +                    fault.setUse(SOAPUse.LITERAL);
   1.361 +                } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
   1.362 +                    fault.setUse(SOAPUse.ENCODED);
   1.363 +                } else {
   1.364 +                    Util.fail(
   1.365 +                        "parsing.invalidAttributeValue",
   1.366 +                        Constants.ATTR_USE,
   1.367 +                        use);
   1.368 +                }
   1.369 +            }
   1.370 +
   1.371 +            String namespace =
   1.372 +                XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
   1.373 +            if (namespace != null) {
   1.374 +                fault.setNamespace(namespace);
   1.375 +            }
   1.376 +
   1.377 +            String encodingStyle =
   1.378 +                XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
   1.379 +            if (encodingStyle != null) {
   1.380 +                fault.setEncodingStyle(encodingStyle);
   1.381 +            }
   1.382 +
   1.383 +            parent.addExtension(fault);
   1.384 +            context.pop();
   1.385 +//            context.fireDoneParsingEntity(getFaultQName(), fault);
   1.386 +            return true;
   1.387 +        } else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
   1.388 +            // although SOAP spec doesn't define meaning of this extension; it is allowed
   1.389 +            // to be here, so we have to accept it, not fail (bug 13576977)
   1.390 +            return handleHeaderElement(parent, e, (TWSDLParserContextImpl) context);
   1.391 +        } else {
   1.392 +            Util.fail(
   1.393 +                "parsing.invalidExtensionElement",
   1.394 +                e.getTagName(),
   1.395 +                e.getNamespaceURI());
   1.396 +            return false; // keep compiler happy
   1.397 +        }
   1.398 +    }
   1.399 +
   1.400 +    public boolean handleServiceExtension(
   1.401 +        TWSDLParserContext context,
   1.402 +        TWSDLExtensible parent,
   1.403 +        Element e) {
   1.404 +        Util.fail(
   1.405 +            "parsing.invalidExtensionElement",
   1.406 +            e.getTagName(),
   1.407 +            e.getNamespaceURI());
   1.408 +        return false; // keep compiler happy
   1.409 +    }
   1.410 +
   1.411 +    @Override
   1.412 +    public boolean handlePortExtension(
   1.413 +        TWSDLParserContext context,
   1.414 +        TWSDLExtensible parent,
   1.415 +        Element e) {
   1.416 +        if (XmlUtil.matchesTagNS(e, getAddressQName())) {
   1.417 +            context.push();
   1.418 +            context.registerNamespaces(e);
   1.419 +
   1.420 +            SOAPAddress address = new SOAPAddress(context.getLocation(e));
   1.421 +
   1.422 +            String location =
   1.423 +                Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
   1.424 +            address.setLocation(location);
   1.425 +
   1.426 +            parent.addExtension(address);
   1.427 +            context.pop();
   1.428 +//            context.fireDoneParsingEntity(getAddressQName(), address);
   1.429 +            return true;
   1.430 +        } else {
   1.431 +            Util.fail(
   1.432 +                "parsing.invalidExtensionElement",
   1.433 +                e.getTagName(),
   1.434 +                e.getNamespaceURI());
   1.435 +            return false; // keep compiler happy
   1.436 +        }
   1.437 +    }
   1.438 +
   1.439 +    public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
   1.440 +       Util.fail(
   1.441 +            "parsing.invalidExtensionElement",
   1.442 +            e.getTagName(),
   1.443 +            e.getNamespaceURI());
   1.444 +        return false; // keep compiler happy
   1.445 +    }
   1.446 +
   1.447 +    protected QName getBodyQName(){
   1.448 +        return SOAPConstants.QNAME_BODY;
   1.449 +    }
   1.450 +
   1.451 +    protected QName getHeaderQName(){
   1.452 +        return SOAPConstants.QNAME_HEADER;
   1.453 +    }
   1.454 +
   1.455 +    protected QName getHeaderfaultQName(){
   1.456 +        return SOAPConstants.QNAME_HEADERFAULT;
   1.457 +    }
   1.458 +
   1.459 +    protected QName getOperationQName(){
   1.460 +        return SOAPConstants.QNAME_OPERATION;
   1.461 +    }
   1.462 +
   1.463 +    protected QName getFaultQName(){
   1.464 +        return SOAPConstants.QNAME_FAULT;
   1.465 +    }
   1.466 +
   1.467 +    protected QName getAddressQName(){
   1.468 +        return SOAPConstants.QNAME_ADDRESS;
   1.469 +    }
   1.470 +
   1.471 +    protected QName getBindingQName(){
   1.472 +        return SOAPConstants.QNAME_BINDING;
   1.473 +    }
   1.474 +}

mercurial