1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/ActionBasedOperationFinder.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,172 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.wsdl; 1.30 + 1.31 +import com.sun.istack.internal.NotNull; 1.32 +import com.sun.istack.internal.Nullable; 1.33 +import com.sun.xml.internal.ws.api.WSBinding; 1.34 +import com.sun.xml.internal.ws.api.model.SEIModel; 1.35 +import com.sun.xml.internal.ws.api.model.WSDLOperationMapping; 1.36 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; 1.37 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; 1.38 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion; 1.39 +import com.sun.xml.internal.ws.api.message.AddressingUtils; 1.40 +import com.sun.xml.internal.ws.api.message.Message; 1.41 +import com.sun.xml.internal.ws.api.message.MessageHeaders; 1.42 +import com.sun.xml.internal.ws.api.message.Messages; 1.43 +import com.sun.xml.internal.ws.api.message.Packet; 1.44 +import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; 1.45 +import com.sun.xml.internal.ws.model.JavaMethodImpl; 1.46 +import static com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.*; 1.47 +import com.sun.xml.internal.ws.resources.AddressingMessages; 1.48 + 1.49 +import javax.xml.namespace.QName; 1.50 +import java.util.HashMap; 1.51 +import java.util.Map; 1.52 +import java.util.logging.Logger; 1.53 + 1.54 +/** 1.55 + * An {@link WSDLOperationFinder} implementation that uses 1.56 + * WS-Addressing Action Message Addressing Property, <code>wsa:Action</code> and SOAP Payload QName, 1.57 + * as the key for dispatching. 1.58 + * <p/> 1.59 + * This should be used only when AddressingFeature is enabled. 1.60 + * A map of all {@link ActionBasedOperationSignature}s in the port and the corresponding and the WSDL Operation QNames 1.61 + * is maintained. 1.62 + * <p/> 1.63 + * 1.64 + * @author Rama Pulavarthi 1.65 + */ 1.66 +final class ActionBasedOperationFinder extends WSDLOperationFinder { 1.67 + 1.68 + private static final Logger LOGGER = Logger.getLogger(ActionBasedOperationFinder.class.getName()); 1.69 + private final Map<ActionBasedOperationSignature, WSDLOperationMapping> uniqueOpSignatureMap; 1.70 + private final Map<String, WSDLOperationMapping> actionMap; 1.71 + 1.72 + private final @NotNull AddressingVersion av; 1.73 + 1.74 + public ActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) { 1.75 + super(wsdlModel, binding, seiModel); 1.76 + 1.77 + assert binding.getAddressingVersion() != null; // this dispatcher can be only used when addressing is on. 1.78 + av = binding.getAddressingVersion(); 1.79 + uniqueOpSignatureMap = new HashMap<ActionBasedOperationSignature, WSDLOperationMapping>(); 1.80 + actionMap = new HashMap<String,WSDLOperationMapping>(); 1.81 + 1.82 + if (seiModel != null) { 1.83 + for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { 1.84 + if(m.getMEP().isAsync) 1.85 + continue; 1.86 + 1.87 + String action = m.getInputAction(); 1.88 + QName payloadName = m.getRequestPayloadName(); 1.89 + if (payloadName == null) 1.90 + payloadName = EMPTY_PAYLOAD; 1.91 + //first look at annotations and then in wsdlmodel 1.92 + if (action == null || action.equals("")) { 1.93 + if (m.getOperation() != null) action = m.getOperation().getOperation().getInput().getAction(); 1.94 +// action = m.getInputAction(); 1.95 + } 1.96 + if (action != null) { 1.97 + ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(action, payloadName); 1.98 + if(uniqueOpSignatureMap.get(opSignature) != null) { 1.99 + LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE( 1.100 + uniqueOpSignatureMap.get(opSignature),m.getOperationQName(),action,payloadName)); 1.101 + } 1.102 + uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(m)); 1.103 + actionMap.put(action,wsdlOperationMapping(m)); 1.104 + } 1.105 + } 1.106 + } else { 1.107 + for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) { 1.108 + QName payloadName = wsdlOp.getRequestPayloadName(); 1.109 + if (payloadName == null) 1.110 + payloadName = EMPTY_PAYLOAD; 1.111 + String action = wsdlOp.getOperation().getInput().getAction(); 1.112 + ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature( 1.113 + action, payloadName); 1.114 + if(uniqueOpSignatureMap.get(opSignature) != null) { 1.115 + LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE( 1.116 + uniqueOpSignatureMap.get(opSignature),wsdlOp.getName(),action,payloadName)); 1.117 + 1.118 + } 1.119 + uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(wsdlOp)); 1.120 + actionMap.put(action,wsdlOperationMapping(wsdlOp)); 1.121 + } 1.122 + } 1.123 + } 1.124 + 1.125 +// /** 1.126 +// * 1.127 +// * @param request Request Packet that is used to find the associated WSDLOperation 1.128 +// * @return WSDL operation Qname. 1.129 +// * return null if WS-Addressing is not engaged. 1.130 +// * @throws DispatchException with WSA defined fault message when it cannot find an associated WSDL operation. 1.131 +// * 1.132 +// */ 1.133 +// @Override 1.134 +// public QName getWSDLOperationQName(Packet request) throws DispatchException { 1.135 +// return getWSDLOperationMapping(request).getWSDLBoundOperation().getName(); 1.136 +// } 1.137 + 1.138 + public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException { 1.139 + MessageHeaders hl = request.getMessage().getHeaders(); 1.140 + String action = AddressingUtils.getAction(hl, av, binding.getSOAPVersion()); 1.141 + 1.142 + if (action == null) 1.143 + // Addressing is not enagaged, return null to use other ways to dispatch. 1.144 + return null; 1.145 + 1.146 + Message message = request.getMessage(); 1.147 + QName payloadName; 1.148 + String localPart = message.getPayloadLocalPart(); 1.149 + if (localPart == null) { 1.150 + payloadName = EMPTY_PAYLOAD; 1.151 + } else { 1.152 + String nsUri = message.getPayloadNamespaceURI(); 1.153 + if (nsUri == null) 1.154 + nsUri = EMPTY_PAYLOAD_NSURI; 1.155 + payloadName = new QName(nsUri, localPart); 1.156 + } 1.157 + 1.158 + WSDLOperationMapping opMapping = uniqueOpSignatureMap.get(new ActionBasedOperationSignature(action, payloadName)); 1.159 + if (opMapping != null) 1.160 + return opMapping; 1.161 + 1.162 + //Seems like in Wstrust STS wsdls, the payload does not match what is specified in the wsdl leading to incorrect 1.163 + // wsdl operation resolution. Use just wsa:Action to dispatch as a last resort. 1.164 + //try just with wsa:Action 1.165 + opMapping = actionMap.get(action); 1.166 + if (opMapping != null) 1.167 + return opMapping; 1.168 + 1.169 + // invalid action header 1.170 + Message result = Messages.create(action, av, binding.getSOAPVersion()); 1.171 + 1.172 + throw new DispatchException(result); 1.173 + 1.174 + } 1.175 +}