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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2013, 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.wsdl;
    28 import com.sun.istack.internal.Nullable;
    29 import com.sun.xml.internal.ws.api.WSBinding;
    30 import com.sun.xml.internal.ws.api.model.SEIModel;
    31 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
    32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    34 import com.sun.xml.internal.ws.api.message.Message;
    35 import com.sun.xml.internal.ws.api.message.Packet;
    36 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
    37 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
    38 import com.sun.xml.internal.ws.model.JavaMethodImpl;
    39 import com.sun.xml.internal.ws.resources.ServerMessages;
    40 import com.sun.xml.internal.ws.util.QNameMap;
    41 import com.sun.xml.internal.ws.wsdl.DispatchException;
    43 import javax.xml.namespace.QName;
    44 import java.util.ArrayList;
    45 import java.util.List;
    46 import java.util.logging.Logger;
    48 /**
    49  * An {@link WSDLOperationFinder} that uses SOAP payload first child's QName as the key for dispatching.
    50  * <p/>
    51  * A map of all payload QNames that the operations in the port allow and the corresponding QName of the wsdl operation
    52  * is initialized in the constructor. The payload QName is extracted from the
    53  * request {@link com.sun.xml.internal.ws.api.message.Packet} and used to identify the wsdl operation.
    54  *
    55  * @author Rama Pulavarthi
    56  * @author Arun Gupta
    57  * @author Jitendra Kotamraju
    58  */
    59 final class PayloadQNameBasedOperationFinder extends WSDLOperationFinder {
    60     private static final Logger LOGGER = Logger.getLogger(PayloadQNameBasedOperationFinder.class.getName());
    62     public static final String EMPTY_PAYLOAD_LOCAL = "";
    63     public static final String EMPTY_PAYLOAD_NSURI = "";
    64     public static final QName EMPTY_PAYLOAD = new QName(EMPTY_PAYLOAD_NSURI, EMPTY_PAYLOAD_LOCAL);
    66     private final QNameMap<WSDLOperationMapping> methodHandlers = new QNameMap<WSDLOperationMapping>();
    67     private final QNameMap<List<String>> unique = new QNameMap<List<String>>();
    70     public PayloadQNameBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) {
    71         super(wsdlModel,binding,seiModel);
    72         if (seiModel != null) {
    73             // Find if any payload QNames repeat for operations
    74             for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
    75                 if(m.getMEP().isAsync)
    76                     continue;
    77                 QName name = m.getRequestPayloadName();
    78                 if (name == null)
    79                     name = EMPTY_PAYLOAD;
    80                 List<String> methods = unique.get(name);
    81                 if (methods == null) {
    82                     methods = new ArrayList<String>();
    83                     unique.put(name, methods);
    84                 }
    85                 methods.add(m.getMethod().getName());
    86             }
    88             // Log warnings about non unique payload QNames
    89             for (QNameMap.Entry<List<String>> e : unique.entrySet()) {
    90                 if (e.getValue().size() > 1) {
    91                     LOGGER.warning(ServerMessages.NON_UNIQUE_DISPATCH_QNAME(e.getValue(), e.createQName()));
    92                 }
    93             }
    95             for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
    96                 QName name = m.getRequestPayloadName();
    97                 if (name == null)
    98                     name = EMPTY_PAYLOAD;
    99                 // Set up method handlers only for unique QNames. So that dispatching
   100                 // happens consistently for a method
   101                 if (unique.get(name).size() == 1) {
   102                     methodHandlers.put(name, wsdlOperationMapping(m));
   103                 }
   104             }
   105         } else {
   106             for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) {
   107                 QName name = wsdlOp.getRequestPayloadName();
   108                 if (name == null)
   109                     name = EMPTY_PAYLOAD;
   110                 methodHandlers.put(name, wsdlOperationMapping(wsdlOp));
   111             }
   112         }
   113     }
   115     /**
   116      *
   117      * @return not null if it finds a unique handler for the request
   118      *         null if it cannot idenitify a unique wsdl operation from the Payload QName.
   119      *
   120      * @throws DispatchException if the payload itself is incorrect, this happens when the payload is not accepted by
   121      *          any operation in the port.
   122      */
   123 //  public QName getWSDLOperationQName(Packet request) throws DispatchException{
   125     public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException {
   126         Message message = request.getMessage();
   127         String localPart = message.getPayloadLocalPart();
   128         String nsUri;
   129         if (localPart == null) {
   130             localPart = EMPTY_PAYLOAD_LOCAL;
   131             nsUri = EMPTY_PAYLOAD_NSURI;
   132         } else {
   133             nsUri = message.getPayloadNamespaceURI();
   134             if(nsUri == null)
   135                 nsUri = EMPTY_PAYLOAD_NSURI;
   136         }
   137         WSDLOperationMapping op = methodHandlers.get(nsUri, localPart);
   139         // Check if payload itself is correct. Usually it is, so let us check last
   140         if (op == null && !unique.containsKey(nsUri,localPart)) {
   141             String dispatchKey = "{" + nsUri + "}" + localPart;
   142             String faultString = ServerMessages.DISPATCH_CANNOT_FIND_METHOD(dispatchKey);
   143             throw new DispatchException(SOAPFaultBuilder.createSOAPFaultMessage(
   144                  binding.getSOAPVersion(), faultString, binding.getSOAPVersion().faultCodeClient));
   145         }
   146         return op;
   147     }
   148 }

mercurial