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

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 408
b0610cd08440
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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

mercurial