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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

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

mercurial