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

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

mercurial