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

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.ws.wsdl;
aoqi@0 27
aoqi@0 28 import com.sun.istack.internal.Nullable;
aoqi@0 29 import com.sun.xml.internal.ws.api.WSBinding;
aoqi@0 30 import com.sun.xml.internal.ws.api.model.SEIModel;
aoqi@0 31 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
aoqi@0 32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
aoqi@0 33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
aoqi@0 34 import com.sun.xml.internal.ws.api.message.Message;
aoqi@0 35 import com.sun.xml.internal.ws.api.message.Packet;
aoqi@0 36 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
aoqi@0 37 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
aoqi@0 38 import com.sun.xml.internal.ws.model.JavaMethodImpl;
aoqi@0 39 import com.sun.xml.internal.ws.resources.ServerMessages;
aoqi@0 40 import com.sun.xml.internal.ws.util.QNameMap;
aoqi@0 41 import com.sun.xml.internal.ws.wsdl.DispatchException;
aoqi@0 42
aoqi@0 43 import javax.xml.namespace.QName;
aoqi@0 44 import java.util.ArrayList;
aoqi@0 45 import java.util.List;
aoqi@0 46 import java.util.logging.Logger;
aoqi@0 47
aoqi@0 48 /**
aoqi@0 49 * An {@link WSDLOperationFinder} that uses SOAP payload first child's QName as the key for dispatching.
aoqi@0 50 * <p/>
aoqi@0 51 * A map of all payload QNames that the operations in the port allow and the corresponding QName of the wsdl operation
aoqi@0 52 * is initialized in the constructor. The payload QName is extracted from the
aoqi@0 53 * request {@link com.sun.xml.internal.ws.api.message.Packet} and used to identify the wsdl operation.
aoqi@0 54 *
aoqi@0 55 * @author Rama Pulavarthi
aoqi@0 56 * @author Arun Gupta
aoqi@0 57 * @author Jitendra Kotamraju
aoqi@0 58 */
aoqi@0 59 final class PayloadQNameBasedOperationFinder extends WSDLOperationFinder {
aoqi@0 60 private static final Logger LOGGER = Logger.getLogger(PayloadQNameBasedOperationFinder.class.getName());
aoqi@0 61
aoqi@0 62 public static final String EMPTY_PAYLOAD_LOCAL = "";
aoqi@0 63 public static final String EMPTY_PAYLOAD_NSURI = "";
aoqi@0 64 public static final QName EMPTY_PAYLOAD = new QName(EMPTY_PAYLOAD_NSURI, EMPTY_PAYLOAD_LOCAL);
aoqi@0 65
aoqi@0 66 private final QNameMap<WSDLOperationMapping> methodHandlers = new QNameMap<WSDLOperationMapping>();
aoqi@0 67 private final QNameMap<List<String>> unique = new QNameMap<List<String>>();
aoqi@0 68
aoqi@0 69
aoqi@0 70 public PayloadQNameBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) {
aoqi@0 71 super(wsdlModel,binding,seiModel);
aoqi@0 72 if (seiModel != null) {
aoqi@0 73 // Find if any payload QNames repeat for operations
aoqi@0 74 for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
aoqi@0 75 if(m.getMEP().isAsync)
aoqi@0 76 continue;
aoqi@0 77 QName name = m.getRequestPayloadName();
aoqi@0 78 if (name == null)
aoqi@0 79 name = EMPTY_PAYLOAD;
aoqi@0 80 List<String> methods = unique.get(name);
aoqi@0 81 if (methods == null) {
aoqi@0 82 methods = new ArrayList<String>();
aoqi@0 83 unique.put(name, methods);
aoqi@0 84 }
aoqi@0 85 methods.add(m.getMethod().getName());
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 // Log warnings about non unique payload QNames
aoqi@0 89 for (QNameMap.Entry<List<String>> e : unique.entrySet()) {
aoqi@0 90 if (e.getValue().size() > 1) {
aoqi@0 91 LOGGER.warning(ServerMessages.NON_UNIQUE_DISPATCH_QNAME(e.getValue(), e.createQName()));
aoqi@0 92 }
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
aoqi@0 96 QName name = m.getRequestPayloadName();
aoqi@0 97 if (name == null)
aoqi@0 98 name = EMPTY_PAYLOAD;
aoqi@0 99 // Set up method handlers only for unique QNames. So that dispatching
aoqi@0 100 // happens consistently for a method
aoqi@0 101 if (unique.get(name).size() == 1) {
aoqi@0 102 methodHandlers.put(name, wsdlOperationMapping(m));
aoqi@0 103 }
aoqi@0 104 }
aoqi@0 105 } else {
aoqi@0 106 for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) {
aoqi@0 107 QName name = wsdlOp.getRequestPayloadName();
aoqi@0 108 if (name == null)
aoqi@0 109 name = EMPTY_PAYLOAD;
aoqi@0 110 methodHandlers.put(name, wsdlOperationMapping(wsdlOp));
aoqi@0 111 }
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 /**
aoqi@0 116 *
aoqi@0 117 * @return not null if it finds a unique handler for the request
aoqi@0 118 * null if it cannot idenitify a unique wsdl operation from the Payload QName.
aoqi@0 119 *
aoqi@0 120 * @throws DispatchException if the payload itself is incorrect, this happens when the payload is not accepted by
aoqi@0 121 * any operation in the port.
aoqi@0 122 */
aoqi@0 123 // public QName getWSDLOperationQName(Packet request) throws DispatchException{
aoqi@0 124
aoqi@0 125 public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException {
aoqi@0 126 Message message = request.getMessage();
aoqi@0 127 String localPart = message.getPayloadLocalPart();
aoqi@0 128 String nsUri;
aoqi@0 129 if (localPart == null) {
aoqi@0 130 localPart = EMPTY_PAYLOAD_LOCAL;
aoqi@0 131 nsUri = EMPTY_PAYLOAD_NSURI;
aoqi@0 132 } else {
aoqi@0 133 nsUri = message.getPayloadNamespaceURI();
aoqi@0 134 if(nsUri == null)
aoqi@0 135 nsUri = EMPTY_PAYLOAD_NSURI;
aoqi@0 136 }
aoqi@0 137 WSDLOperationMapping op = methodHandlers.get(nsUri, localPart);
aoqi@0 138
aoqi@0 139 // Check if payload itself is correct. Usually it is, so let us check last
aoqi@0 140 if (op == null && !unique.containsKey(nsUri,localPart)) {
aoqi@0 141 String dispatchKey = "{" + nsUri + "}" + localPart;
aoqi@0 142 String faultString = ServerMessages.DISPATCH_CANNOT_FIND_METHOD(dispatchKey);
aoqi@0 143 throw new DispatchException(SOAPFaultBuilder.createSOAPFaultMessage(
aoqi@0 144 binding.getSOAPVersion(), faultString, binding.getSOAPVersion().faultCodeClient));
aoqi@0 145 }
aoqi@0 146 return op;
aoqi@0 147 }
aoqi@0 148 }

mercurial