ohair@286: /* alanb@368: * Copyright (c) 1997, 2013, 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.NotNull; 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.addressing.AddressingVersion; alanb@368: import com.sun.xml.internal.ws.api.message.AddressingUtils; ohair@286: import com.sun.xml.internal.ws.api.message.Message; alanb@368: import com.sun.xml.internal.ws.api.message.MessageHeaders; ohair@286: import com.sun.xml.internal.ws.api.message.Messages; ohair@286: import com.sun.xml.internal.ws.api.message.Packet; ohair@286: import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; ohair@286: import com.sun.xml.internal.ws.model.JavaMethodImpl; ohair@286: import static com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.*; ohair@286: import com.sun.xml.internal.ws.resources.AddressingMessages; ohair@286: ohair@286: import javax.xml.namespace.QName; ohair@286: import java.util.HashMap; ohair@286: import java.util.Map; ohair@286: import java.util.logging.Logger; ohair@286: ohair@286: /** ohair@286: * An {@link WSDLOperationFinder} implementation that uses ohair@286: * WS-Addressing Action Message Addressing Property, wsa:Action and SOAP Payload QName, ohair@286: * as the key for dispatching. ohair@286: *

ohair@286: * This should be used only when AddressingFeature is enabled. ohair@286: * A map of all {@link ActionBasedOperationSignature}s in the port and the corresponding and the WSDL Operation QNames ohair@286: * is maintained. ohair@286: *

ohair@286: * ohair@286: * @author Rama Pulavarthi ohair@286: */ ohair@286: final class ActionBasedOperationFinder extends WSDLOperationFinder { ohair@286: ohair@286: private static final Logger LOGGER = Logger.getLogger(ActionBasedOperationFinder.class.getName()); alanb@368: private final Map uniqueOpSignatureMap; alanb@368: private final Map actionMap; ohair@286: ohair@286: private final @NotNull AddressingVersion av; ohair@286: ohair@286: public ActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) { ohair@286: super(wsdlModel, binding, seiModel); ohair@286: ohair@286: assert binding.getAddressingVersion() != null; // this dispatcher can be only used when addressing is on. ohair@286: av = binding.getAddressingVersion(); alanb@368: uniqueOpSignatureMap = new HashMap(); alanb@368: actionMap = new HashMap(); ohair@286: ohair@286: if (seiModel != null) { ohair@286: for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { ohair@286: if(m.getMEP().isAsync) ohair@286: continue; ohair@286: ohair@286: String action = m.getInputAction(); ohair@286: QName payloadName = m.getRequestPayloadName(); ohair@286: if (payloadName == null) ohair@286: payloadName = EMPTY_PAYLOAD; ohair@286: //first look at annotations and then in wsdlmodel ohair@286: if (action == null || action.equals("")) { ohair@286: if (m.getOperation() != null) action = m.getOperation().getOperation().getInput().getAction(); ohair@286: // action = m.getInputAction(); ohair@286: } ohair@286: if (action != null) { ohair@286: ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(action, payloadName); ohair@286: if(uniqueOpSignatureMap.get(opSignature) != null) { ohair@286: LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE( ohair@286: uniqueOpSignatureMap.get(opSignature),m.getOperationQName(),action,payloadName)); ohair@286: } alanb@368: uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(m)); alanb@368: actionMap.put(action,wsdlOperationMapping(m)); ohair@286: } ohair@286: } ohair@286: } else { ohair@286: for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) { mkos@408: QName payloadName = wsdlOp.getRequestPayloadName(); ohair@286: if (payloadName == null) ohair@286: payloadName = EMPTY_PAYLOAD; ohair@286: String action = wsdlOp.getOperation().getInput().getAction(); ohair@286: ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature( ohair@286: action, payloadName); ohair@286: if(uniqueOpSignatureMap.get(opSignature) != null) { ohair@286: LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE( ohair@286: uniqueOpSignatureMap.get(opSignature),wsdlOp.getName(),action,payloadName)); ohair@286: ohair@286: } alanb@368: uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(wsdlOp)); alanb@368: actionMap.put(action,wsdlOperationMapping(wsdlOp)); ohair@286: } ohair@286: } ohair@286: } ohair@286: alanb@368: // /** alanb@368: // * alanb@368: // * @param request Request Packet that is used to find the associated WSDLOperation alanb@368: // * @return WSDL operation Qname. alanb@368: // * return null if WS-Addressing is not engaged. alanb@368: // * @throws DispatchException with WSA defined fault message when it cannot find an associated WSDL operation. alanb@368: // * alanb@368: // */ alanb@368: // @Override alanb@368: // public QName getWSDLOperationQName(Packet request) throws DispatchException { alanb@368: // return getWSDLOperationMapping(request).getWSDLBoundOperation().getName(); alanb@368: // } alanb@368: alanb@368: public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException { alanb@368: MessageHeaders hl = request.getMessage().getHeaders(); alanb@368: String action = AddressingUtils.getAction(hl, av, binding.getSOAPVersion()); ohair@286: ohair@286: if (action == null) ohair@286: // Addressing is not enagaged, return null to use other ways to dispatch. ohair@286: return null; ohair@286: ohair@286: Message message = request.getMessage(); ohair@286: QName payloadName; ohair@286: String localPart = message.getPayloadLocalPart(); ohair@286: if (localPart == null) { ohair@286: payloadName = EMPTY_PAYLOAD; ohair@286: } else { ohair@286: String nsUri = message.getPayloadNamespaceURI(); ohair@286: if (nsUri == null) ohair@286: nsUri = EMPTY_PAYLOAD_NSURI; ohair@286: payloadName = new QName(nsUri, localPart); ohair@286: } ohair@286: alanb@368: WSDLOperationMapping opMapping = uniqueOpSignatureMap.get(new ActionBasedOperationSignature(action, payloadName)); alanb@368: if (opMapping != null) alanb@368: return opMapping; ohair@286: ohair@286: //Seems like in Wstrust STS wsdls, the payload does not match what is specified in the wsdl leading to incorrect ohair@286: // wsdl operation resolution. Use just wsa:Action to dispatch as a last resort. ohair@286: //try just with wsa:Action alanb@368: opMapping = actionMap.get(action); alanb@368: if (opMapping != null) alanb@368: return opMapping; ohair@286: ohair@286: // invalid action header ohair@286: Message result = Messages.create(action, av, binding.getSOAPVersion()); ohair@286: ohair@286: throw new DispatchException(result); ohair@286: ohair@286: } ohair@286: }