Fri, 04 Oct 2013 16:21:34 +0100
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2013, 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.NotNull; |
ohair@286 | 29 | import com.sun.istack.internal.Nullable; |
ohair@286 | 30 | import com.sun.xml.internal.ws.api.WSBinding; |
ohair@286 | 31 | import com.sun.xml.internal.ws.api.model.SEIModel; |
alanb@368 | 32 | import com.sun.xml.internal.ws.api.model.WSDLOperationMapping; |
ohair@286 | 33 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
ohair@286 | 34 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; |
ohair@286 | 35 | import com.sun.xml.internal.ws.api.addressing.AddressingVersion; |
alanb@368 | 36 | import com.sun.xml.internal.ws.api.message.AddressingUtils; |
ohair@286 | 37 | import com.sun.xml.internal.ws.api.message.Message; |
alanb@368 | 38 | import com.sun.xml.internal.ws.api.message.MessageHeaders; |
ohair@286 | 39 | import com.sun.xml.internal.ws.api.message.Messages; |
ohair@286 | 40 | import com.sun.xml.internal.ws.api.message.Packet; |
ohair@286 | 41 | import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; |
ohair@286 | 42 | import com.sun.xml.internal.ws.model.JavaMethodImpl; |
ohair@286 | 43 | import static com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.*; |
ohair@286 | 44 | import com.sun.xml.internal.ws.resources.AddressingMessages; |
ohair@286 | 45 | |
ohair@286 | 46 | import javax.xml.namespace.QName; |
ohair@286 | 47 | import java.util.HashMap; |
ohair@286 | 48 | import java.util.Map; |
ohair@286 | 49 | import java.util.logging.Logger; |
ohair@286 | 50 | |
ohair@286 | 51 | /** |
ohair@286 | 52 | * An {@link WSDLOperationFinder} implementation that uses |
ohair@286 | 53 | * WS-Addressing Action Message Addressing Property, <code>wsa:Action</code> and SOAP Payload QName, |
ohair@286 | 54 | * as the key for dispatching. |
ohair@286 | 55 | * <p/> |
ohair@286 | 56 | * This should be used only when AddressingFeature is enabled. |
ohair@286 | 57 | * A map of all {@link ActionBasedOperationSignature}s in the port and the corresponding and the WSDL Operation QNames |
ohair@286 | 58 | * is maintained. |
ohair@286 | 59 | * <p/> |
ohair@286 | 60 | * |
ohair@286 | 61 | * @author Rama Pulavarthi |
ohair@286 | 62 | */ |
ohair@286 | 63 | final class ActionBasedOperationFinder extends WSDLOperationFinder { |
ohair@286 | 64 | |
ohair@286 | 65 | private static final Logger LOGGER = Logger.getLogger(ActionBasedOperationFinder.class.getName()); |
alanb@368 | 66 | private final Map<ActionBasedOperationSignature, WSDLOperationMapping> uniqueOpSignatureMap; |
alanb@368 | 67 | private final Map<String, WSDLOperationMapping> actionMap; |
ohair@286 | 68 | |
ohair@286 | 69 | private final @NotNull AddressingVersion av; |
ohair@286 | 70 | |
ohair@286 | 71 | public ActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) { |
ohair@286 | 72 | super(wsdlModel, binding, seiModel); |
ohair@286 | 73 | |
ohair@286 | 74 | assert binding.getAddressingVersion() != null; // this dispatcher can be only used when addressing is on. |
ohair@286 | 75 | av = binding.getAddressingVersion(); |
alanb@368 | 76 | uniqueOpSignatureMap = new HashMap<ActionBasedOperationSignature, WSDLOperationMapping>(); |
alanb@368 | 77 | actionMap = new HashMap<String,WSDLOperationMapping>(); |
ohair@286 | 78 | |
ohair@286 | 79 | if (seiModel != null) { |
ohair@286 | 80 | for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { |
ohair@286 | 81 | if(m.getMEP().isAsync) |
ohair@286 | 82 | continue; |
ohair@286 | 83 | |
ohair@286 | 84 | String action = m.getInputAction(); |
ohair@286 | 85 | QName payloadName = m.getRequestPayloadName(); |
ohair@286 | 86 | if (payloadName == null) |
ohair@286 | 87 | payloadName = EMPTY_PAYLOAD; |
ohair@286 | 88 | //first look at annotations and then in wsdlmodel |
ohair@286 | 89 | if (action == null || action.equals("")) { |
ohair@286 | 90 | if (m.getOperation() != null) action = m.getOperation().getOperation().getInput().getAction(); |
ohair@286 | 91 | // action = m.getInputAction(); |
ohair@286 | 92 | } |
ohair@286 | 93 | if (action != null) { |
ohair@286 | 94 | ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(action, payloadName); |
ohair@286 | 95 | if(uniqueOpSignatureMap.get(opSignature) != null) { |
ohair@286 | 96 | LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE( |
ohair@286 | 97 | uniqueOpSignatureMap.get(opSignature),m.getOperationQName(),action,payloadName)); |
ohair@286 | 98 | } |
alanb@368 | 99 | uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(m)); |
alanb@368 | 100 | actionMap.put(action,wsdlOperationMapping(m)); |
ohair@286 | 101 | } |
ohair@286 | 102 | } |
ohair@286 | 103 | } else { |
ohair@286 | 104 | for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) { |
mkos@408 | 105 | QName payloadName = wsdlOp.getRequestPayloadName(); |
ohair@286 | 106 | if (payloadName == null) |
ohair@286 | 107 | payloadName = EMPTY_PAYLOAD; |
ohair@286 | 108 | String action = wsdlOp.getOperation().getInput().getAction(); |
ohair@286 | 109 | ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature( |
ohair@286 | 110 | action, payloadName); |
ohair@286 | 111 | if(uniqueOpSignatureMap.get(opSignature) != null) { |
ohair@286 | 112 | LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE( |
ohair@286 | 113 | uniqueOpSignatureMap.get(opSignature),wsdlOp.getName(),action,payloadName)); |
ohair@286 | 114 | |
ohair@286 | 115 | } |
alanb@368 | 116 | uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(wsdlOp)); |
alanb@368 | 117 | actionMap.put(action,wsdlOperationMapping(wsdlOp)); |
ohair@286 | 118 | } |
ohair@286 | 119 | } |
ohair@286 | 120 | } |
ohair@286 | 121 | |
alanb@368 | 122 | // /** |
alanb@368 | 123 | // * |
alanb@368 | 124 | // * @param request Request Packet that is used to find the associated WSDLOperation |
alanb@368 | 125 | // * @return WSDL operation Qname. |
alanb@368 | 126 | // * return null if WS-Addressing is not engaged. |
alanb@368 | 127 | // * @throws DispatchException with WSA defined fault message when it cannot find an associated WSDL operation. |
alanb@368 | 128 | // * |
alanb@368 | 129 | // */ |
alanb@368 | 130 | // @Override |
alanb@368 | 131 | // public QName getWSDLOperationQName(Packet request) throws DispatchException { |
alanb@368 | 132 | // return getWSDLOperationMapping(request).getWSDLBoundOperation().getName(); |
alanb@368 | 133 | // } |
alanb@368 | 134 | |
alanb@368 | 135 | public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException { |
alanb@368 | 136 | MessageHeaders hl = request.getMessage().getHeaders(); |
alanb@368 | 137 | String action = AddressingUtils.getAction(hl, av, binding.getSOAPVersion()); |
ohair@286 | 138 | |
ohair@286 | 139 | if (action == null) |
ohair@286 | 140 | // Addressing is not enagaged, return null to use other ways to dispatch. |
ohair@286 | 141 | return null; |
ohair@286 | 142 | |
ohair@286 | 143 | Message message = request.getMessage(); |
ohair@286 | 144 | QName payloadName; |
ohair@286 | 145 | String localPart = message.getPayloadLocalPart(); |
ohair@286 | 146 | if (localPart == null) { |
ohair@286 | 147 | payloadName = EMPTY_PAYLOAD; |
ohair@286 | 148 | } else { |
ohair@286 | 149 | String nsUri = message.getPayloadNamespaceURI(); |
ohair@286 | 150 | if (nsUri == null) |
ohair@286 | 151 | nsUri = EMPTY_PAYLOAD_NSURI; |
ohair@286 | 152 | payloadName = new QName(nsUri, localPart); |
ohair@286 | 153 | } |
ohair@286 | 154 | |
alanb@368 | 155 | WSDLOperationMapping opMapping = uniqueOpSignatureMap.get(new ActionBasedOperationSignature(action, payloadName)); |
alanb@368 | 156 | if (opMapping != null) |
alanb@368 | 157 | return opMapping; |
ohair@286 | 158 | |
ohair@286 | 159 | //Seems like in Wstrust STS wsdls, the payload does not match what is specified in the wsdl leading to incorrect |
ohair@286 | 160 | // wsdl operation resolution. Use just wsa:Action to dispatch as a last resort. |
ohair@286 | 161 | //try just with wsa:Action |
alanb@368 | 162 | opMapping = actionMap.get(action); |
alanb@368 | 163 | if (opMapping != null) |
alanb@368 | 164 | return opMapping; |
ohair@286 | 165 | |
ohair@286 | 166 | // invalid action header |
ohair@286 | 167 | Message result = Messages.create(action, av, binding.getSOAPVersion()); |
ohair@286 | 168 | |
ohair@286 | 169 | throw new DispatchException(result); |
ohair@286 | 170 | |
ohair@286 | 171 | } |
ohair@286 | 172 | } |