src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/PayloadQNameBasedOperationFinder.java

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

mercurial