ohair@286: /* alanb@368: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.xml.internal.ws.wsdl; ohair@286: ohair@286: import com.sun.istack.internal.Nullable; ohair@286: import com.sun.xml.internal.ws.api.WSBinding; ohair@286: import com.sun.xml.internal.ws.api.model.SEIModel; alanb@368: import com.sun.xml.internal.ws.api.model.WSDLOperationMapping; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; ohair@286: import com.sun.xml.internal.ws.api.message.Message; ohair@286: import com.sun.xml.internal.ws.api.message.Packet; ohair@286: import com.sun.xml.internal.ws.fault.SOAPFaultBuilder; ohair@286: import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; ohair@286: import com.sun.xml.internal.ws.model.JavaMethodImpl; ohair@286: import com.sun.xml.internal.ws.resources.ServerMessages; ohair@286: import com.sun.xml.internal.ws.util.QNameMap; ohair@286: import com.sun.xml.internal.ws.wsdl.DispatchException; ohair@286: ohair@286: import javax.xml.namespace.QName; ohair@286: import java.util.ArrayList; ohair@286: import java.util.List; ohair@286: import java.util.logging.Logger; ohair@286: ohair@286: /** ohair@286: * An {@link WSDLOperationFinder} that uses SOAP payload first child's QName as the key for dispatching. ohair@286: *

ohair@286: * A map of all payload QNames that the operations in the port allow and the corresponding QName of the wsdl operation ohair@286: * is initialized in the constructor. The payload QName is extracted from the ohair@286: * request {@link com.sun.xml.internal.ws.api.message.Packet} and used to identify the wsdl operation. ohair@286: * ohair@286: * @author Rama Pulavarthi ohair@286: * @author Arun Gupta ohair@286: * @author Jitendra Kotamraju ohair@286: */ ohair@286: final class PayloadQNameBasedOperationFinder extends WSDLOperationFinder { ohair@286: private static final Logger LOGGER = Logger.getLogger(PayloadQNameBasedOperationFinder.class.getName()); ohair@286: ohair@286: public static final String EMPTY_PAYLOAD_LOCAL = ""; ohair@286: public static final String EMPTY_PAYLOAD_NSURI = ""; ohair@286: public static final QName EMPTY_PAYLOAD = new QName(EMPTY_PAYLOAD_NSURI, EMPTY_PAYLOAD_LOCAL); ohair@286: alanb@368: private final QNameMap methodHandlers = new QNameMap(); ohair@286: private final QNameMap> unique = new QNameMap>(); ohair@286: ohair@286: ohair@286: public PayloadQNameBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) { ohair@286: super(wsdlModel,binding,seiModel); ohair@286: if (seiModel != null) { ohair@286: // Find if any payload QNames repeat for operations ohair@286: for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { ohair@286: if(m.getMEP().isAsync) ohair@286: continue; ohair@286: QName name = m.getRequestPayloadName(); ohair@286: if (name == null) ohair@286: name = EMPTY_PAYLOAD; ohair@286: List methods = unique.get(name); ohair@286: if (methods == null) { ohair@286: methods = new ArrayList(); ohair@286: unique.put(name, methods); ohair@286: } ohair@286: methods.add(m.getMethod().getName()); ohair@286: } ohair@286: ohair@286: // Log warnings about non unique payload QNames ohair@286: for (QNameMap.Entry> e : unique.entrySet()) { ohair@286: if (e.getValue().size() > 1) { ohair@286: LOGGER.warning(ServerMessages.NON_UNIQUE_DISPATCH_QNAME(e.getValue(), e.createQName())); ohair@286: } ohair@286: } ohair@286: ohair@286: for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { ohair@286: QName name = m.getRequestPayloadName(); ohair@286: if (name == null) ohair@286: name = EMPTY_PAYLOAD; ohair@286: // Set up method handlers only for unique QNames. So that dispatching ohair@286: // happens consistently for a method ohair@286: if (unique.get(name).size() == 1) { alanb@368: methodHandlers.put(name, wsdlOperationMapping(m)); ohair@286: } ohair@286: } ohair@286: } else { ohair@286: for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) { ohair@286: QName name = wsdlOp.getReqPayloadName(); ohair@286: if (name == null) ohair@286: name = EMPTY_PAYLOAD; alanb@368: methodHandlers.put(name, wsdlOperationMapping(wsdlOp)); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: /** ohair@286: * ohair@286: * @return not null if it finds a unique handler for the request ohair@286: * null if it cannot idenitify a unique wsdl operation from the Payload QName. ohair@286: * ohair@286: * @throws DispatchException if the payload itself is incorrect, this happens when the payload is not accepted by ohair@286: * any operation in the port. ohair@286: */ alanb@368: // public QName getWSDLOperationQName(Packet request) throws DispatchException{ alanb@368: alanb@368: public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException { ohair@286: Message message = request.getMessage(); ohair@286: String localPart = message.getPayloadLocalPart(); ohair@286: String nsUri; ohair@286: if (localPart == null) { ohair@286: localPart = EMPTY_PAYLOAD_LOCAL; ohair@286: nsUri = EMPTY_PAYLOAD_NSURI; ohair@286: } else { ohair@286: nsUri = message.getPayloadNamespaceURI(); ohair@286: if(nsUri == null) ohair@286: nsUri = EMPTY_PAYLOAD_NSURI; ohair@286: } alanb@368: WSDLOperationMapping op = methodHandlers.get(nsUri, localPart); ohair@286: ohair@286: // Check if payload itself is correct. Usually it is, so let us check last ohair@286: if (op == null && !unique.containsKey(nsUri,localPart)) { ohair@286: String dispatchKey = "{" + nsUri + "}" + localPart; ohair@286: String faultString = ServerMessages.DISPATCH_CANNOT_FIND_METHOD(dispatchKey); ohair@286: throw new DispatchException(SOAPFaultBuilder.createSOAPFaultMessage( ohair@286: binding.getSOAPVersion(), faultString, binding.getSOAPVersion().faultCodeClient)); ohair@286: } ohair@286: return op; ohair@286: } ohair@286: }