src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/PayloadQNameBasedOperationFinder.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/xml/internal/ws/wsdl/PayloadQNameBasedOperationFinder.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, 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.xml.internal.ws.wsdl;
    1.30 +
    1.31 +import com.sun.istack.internal.Nullable;
    1.32 +import com.sun.xml.internal.ws.api.WSBinding;
    1.33 +import com.sun.xml.internal.ws.api.model.SEIModel;
    1.34 +import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
    1.35 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.36 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    1.37 +import com.sun.xml.internal.ws.api.message.Message;
    1.38 +import com.sun.xml.internal.ws.api.message.Packet;
    1.39 +import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
    1.40 +import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
    1.41 +import com.sun.xml.internal.ws.model.JavaMethodImpl;
    1.42 +import com.sun.xml.internal.ws.resources.ServerMessages;
    1.43 +import com.sun.xml.internal.ws.util.QNameMap;
    1.44 +import com.sun.xml.internal.ws.wsdl.DispatchException;
    1.45 +
    1.46 +import javax.xml.namespace.QName;
    1.47 +import java.util.ArrayList;
    1.48 +import java.util.List;
    1.49 +import java.util.logging.Logger;
    1.50 +
    1.51 +/**
    1.52 + * An {@link WSDLOperationFinder} that uses SOAP payload first child's QName as the key for dispatching.
    1.53 + * <p/>
    1.54 + * A map of all payload QNames that the operations in the port allow and the corresponding QName of the wsdl operation
    1.55 + * is initialized in the constructor. The payload QName is extracted from the
    1.56 + * request {@link com.sun.xml.internal.ws.api.message.Packet} and used to identify the wsdl operation.
    1.57 + *
    1.58 + * @author Rama Pulavarthi
    1.59 + * @author Arun Gupta
    1.60 + * @author Jitendra Kotamraju
    1.61 + */
    1.62 +final class PayloadQNameBasedOperationFinder extends WSDLOperationFinder {
    1.63 +    private static final Logger LOGGER = Logger.getLogger(PayloadQNameBasedOperationFinder.class.getName());
    1.64 +
    1.65 +    public static final String EMPTY_PAYLOAD_LOCAL = "";
    1.66 +    public static final String EMPTY_PAYLOAD_NSURI = "";
    1.67 +    public static final QName EMPTY_PAYLOAD = new QName(EMPTY_PAYLOAD_NSURI, EMPTY_PAYLOAD_LOCAL);
    1.68 +
    1.69 +    private final QNameMap<WSDLOperationMapping> methodHandlers = new QNameMap<WSDLOperationMapping>();
    1.70 +    private final QNameMap<List<String>> unique = new QNameMap<List<String>>();
    1.71 +
    1.72 +
    1.73 +    public PayloadQNameBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) {
    1.74 +        super(wsdlModel,binding,seiModel);
    1.75 +        if (seiModel != null) {
    1.76 +            // Find if any payload QNames repeat for operations
    1.77 +            for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
    1.78 +                if(m.getMEP().isAsync)
    1.79 +                    continue;
    1.80 +                QName name = m.getRequestPayloadName();
    1.81 +                if (name == null)
    1.82 +                    name = EMPTY_PAYLOAD;
    1.83 +                List<String> methods = unique.get(name);
    1.84 +                if (methods == null) {
    1.85 +                    methods = new ArrayList<String>();
    1.86 +                    unique.put(name, methods);
    1.87 +                }
    1.88 +                methods.add(m.getMethod().getName());
    1.89 +            }
    1.90 +
    1.91 +            // Log warnings about non unique payload QNames
    1.92 +            for (QNameMap.Entry<List<String>> e : unique.entrySet()) {
    1.93 +                if (e.getValue().size() > 1) {
    1.94 +                    LOGGER.warning(ServerMessages.NON_UNIQUE_DISPATCH_QNAME(e.getValue(), e.createQName()));
    1.95 +                }
    1.96 +            }
    1.97 +
    1.98 +            for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
    1.99 +                QName name = m.getRequestPayloadName();
   1.100 +                if (name == null)
   1.101 +                    name = EMPTY_PAYLOAD;
   1.102 +                // Set up method handlers only for unique QNames. So that dispatching
   1.103 +                // happens consistently for a method
   1.104 +                if (unique.get(name).size() == 1) {
   1.105 +                    methodHandlers.put(name, wsdlOperationMapping(m));
   1.106 +                }
   1.107 +            }
   1.108 +        } else {
   1.109 +            for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) {
   1.110 +                QName name = wsdlOp.getRequestPayloadName();
   1.111 +                if (name == null)
   1.112 +                    name = EMPTY_PAYLOAD;
   1.113 +                methodHandlers.put(name, wsdlOperationMapping(wsdlOp));
   1.114 +            }
   1.115 +        }
   1.116 +    }
   1.117 +
   1.118 +    /**
   1.119 +     *
   1.120 +     * @return not null if it finds a unique handler for the request
   1.121 +     *         null if it cannot idenitify a unique wsdl operation from the Payload QName.
   1.122 +     *
   1.123 +     * @throws DispatchException if the payload itself is incorrect, this happens when the payload is not accepted by
   1.124 +     *          any operation in the port.
   1.125 +     */
   1.126 +//  public QName getWSDLOperationQName(Packet request) throws DispatchException{
   1.127 +
   1.128 +    public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException {
   1.129 +        Message message = request.getMessage();
   1.130 +        String localPart = message.getPayloadLocalPart();
   1.131 +        String nsUri;
   1.132 +        if (localPart == null) {
   1.133 +            localPart = EMPTY_PAYLOAD_LOCAL;
   1.134 +            nsUri = EMPTY_PAYLOAD_NSURI;
   1.135 +        } else {
   1.136 +            nsUri = message.getPayloadNamespaceURI();
   1.137 +            if(nsUri == null)
   1.138 +                nsUri = EMPTY_PAYLOAD_NSURI;
   1.139 +        }
   1.140 +        WSDLOperationMapping op = methodHandlers.get(nsUri, localPart);
   1.141 +
   1.142 +        // Check if payload itself is correct. Usually it is, so let us check last
   1.143 +        if (op == null && !unique.containsKey(nsUri,localPart)) {
   1.144 +            String dispatchKey = "{" + nsUri + "}" + localPart;
   1.145 +            String faultString = ServerMessages.DISPATCH_CANNOT_FIND_METHOD(dispatchKey);
   1.146 +            throw new DispatchException(SOAPFaultBuilder.createSOAPFaultMessage(
   1.147 +                 binding.getSOAPVersion(), faultString, binding.getSOAPVersion().faultCodeClient));
   1.148 +        }
   1.149 +        return op;
   1.150 +    }
   1.151 +}

mercurial