src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/ActionBasedOperationFinder.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.ws.wsdl;
aoqi@0 27
aoqi@0 28 import com.sun.istack.internal.NotNull;
aoqi@0 29 import com.sun.istack.internal.Nullable;
aoqi@0 30 import com.sun.xml.internal.ws.api.WSBinding;
aoqi@0 31 import com.sun.xml.internal.ws.api.model.SEIModel;
aoqi@0 32 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
aoqi@0 33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
aoqi@0 34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
aoqi@0 35 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
aoqi@0 36 import com.sun.xml.internal.ws.api.message.AddressingUtils;
aoqi@0 37 import com.sun.xml.internal.ws.api.message.Message;
aoqi@0 38 import com.sun.xml.internal.ws.api.message.MessageHeaders;
aoqi@0 39 import com.sun.xml.internal.ws.api.message.Messages;
aoqi@0 40 import com.sun.xml.internal.ws.api.message.Packet;
aoqi@0 41 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
aoqi@0 42 import com.sun.xml.internal.ws.model.JavaMethodImpl;
aoqi@0 43 import static com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.*;
aoqi@0 44 import com.sun.xml.internal.ws.resources.AddressingMessages;
aoqi@0 45
aoqi@0 46 import javax.xml.namespace.QName;
aoqi@0 47 import java.util.HashMap;
aoqi@0 48 import java.util.Map;
aoqi@0 49 import java.util.logging.Logger;
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * An {@link WSDLOperationFinder} implementation that uses
aoqi@0 53 * WS-Addressing Action Message Addressing Property, <code>wsa:Action</code> and SOAP Payload QName,
aoqi@0 54 * as the key for dispatching.
aoqi@0 55 * <p/>
aoqi@0 56 * This should be used only when AddressingFeature is enabled.
aoqi@0 57 * A map of all {@link ActionBasedOperationSignature}s in the port and the corresponding and the WSDL Operation QNames
aoqi@0 58 * is maintained.
aoqi@0 59 * <p/>
aoqi@0 60 *
aoqi@0 61 * @author Rama Pulavarthi
aoqi@0 62 */
aoqi@0 63 final class ActionBasedOperationFinder extends WSDLOperationFinder {
aoqi@0 64
aoqi@0 65 private static final Logger LOGGER = Logger.getLogger(ActionBasedOperationFinder.class.getName());
aoqi@0 66 private final Map<ActionBasedOperationSignature, WSDLOperationMapping> uniqueOpSignatureMap;
aoqi@0 67 private final Map<String, WSDLOperationMapping> actionMap;
aoqi@0 68
aoqi@0 69 private final @NotNull AddressingVersion av;
aoqi@0 70
aoqi@0 71 public ActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) {
aoqi@0 72 super(wsdlModel, binding, seiModel);
aoqi@0 73
aoqi@0 74 assert binding.getAddressingVersion() != null; // this dispatcher can be only used when addressing is on.
aoqi@0 75 av = binding.getAddressingVersion();
aoqi@0 76 uniqueOpSignatureMap = new HashMap<ActionBasedOperationSignature, WSDLOperationMapping>();
aoqi@0 77 actionMap = new HashMap<String,WSDLOperationMapping>();
aoqi@0 78
aoqi@0 79 if (seiModel != null) {
aoqi@0 80 for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
aoqi@0 81 if(m.getMEP().isAsync)
aoqi@0 82 continue;
aoqi@0 83
aoqi@0 84 String action = m.getInputAction();
aoqi@0 85 QName payloadName = m.getRequestPayloadName();
aoqi@0 86 if (payloadName == null)
aoqi@0 87 payloadName = EMPTY_PAYLOAD;
aoqi@0 88 //first look at annotations and then in wsdlmodel
aoqi@0 89 if (action == null || action.equals("")) {
aoqi@0 90 if (m.getOperation() != null) action = m.getOperation().getOperation().getInput().getAction();
aoqi@0 91 // action = m.getInputAction();
aoqi@0 92 }
aoqi@0 93 if (action != null) {
aoqi@0 94 ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(action, payloadName);
aoqi@0 95 if(uniqueOpSignatureMap.get(opSignature) != null) {
aoqi@0 96 LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE(
aoqi@0 97 uniqueOpSignatureMap.get(opSignature),m.getOperationQName(),action,payloadName));
aoqi@0 98 }
aoqi@0 99 uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(m));
aoqi@0 100 actionMap.put(action,wsdlOperationMapping(m));
aoqi@0 101 }
aoqi@0 102 }
aoqi@0 103 } else {
aoqi@0 104 for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) {
aoqi@0 105 QName payloadName = wsdlOp.getRequestPayloadName();
aoqi@0 106 if (payloadName == null)
aoqi@0 107 payloadName = EMPTY_PAYLOAD;
aoqi@0 108 String action = wsdlOp.getOperation().getInput().getAction();
aoqi@0 109 ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(
aoqi@0 110 action, payloadName);
aoqi@0 111 if(uniqueOpSignatureMap.get(opSignature) != null) {
aoqi@0 112 LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE(
aoqi@0 113 uniqueOpSignatureMap.get(opSignature),wsdlOp.getName(),action,payloadName));
aoqi@0 114
aoqi@0 115 }
aoqi@0 116 uniqueOpSignatureMap.put(opSignature, wsdlOperationMapping(wsdlOp));
aoqi@0 117 actionMap.put(action,wsdlOperationMapping(wsdlOp));
aoqi@0 118 }
aoqi@0 119 }
aoqi@0 120 }
aoqi@0 121
aoqi@0 122 // /**
aoqi@0 123 // *
aoqi@0 124 // * @param request Request Packet that is used to find the associated WSDLOperation
aoqi@0 125 // * @return WSDL operation Qname.
aoqi@0 126 // * return null if WS-Addressing is not engaged.
aoqi@0 127 // * @throws DispatchException with WSA defined fault message when it cannot find an associated WSDL operation.
aoqi@0 128 // *
aoqi@0 129 // */
aoqi@0 130 // @Override
aoqi@0 131 // public QName getWSDLOperationQName(Packet request) throws DispatchException {
aoqi@0 132 // return getWSDLOperationMapping(request).getWSDLBoundOperation().getName();
aoqi@0 133 // }
aoqi@0 134
aoqi@0 135 public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException {
aoqi@0 136 MessageHeaders hl = request.getMessage().getHeaders();
aoqi@0 137 String action = AddressingUtils.getAction(hl, av, binding.getSOAPVersion());
aoqi@0 138
aoqi@0 139 if (action == null)
aoqi@0 140 // Addressing is not enagaged, return null to use other ways to dispatch.
aoqi@0 141 return null;
aoqi@0 142
aoqi@0 143 Message message = request.getMessage();
aoqi@0 144 QName payloadName;
aoqi@0 145 String localPart = message.getPayloadLocalPart();
aoqi@0 146 if (localPart == null) {
aoqi@0 147 payloadName = EMPTY_PAYLOAD;
aoqi@0 148 } else {
aoqi@0 149 String nsUri = message.getPayloadNamespaceURI();
aoqi@0 150 if (nsUri == null)
aoqi@0 151 nsUri = EMPTY_PAYLOAD_NSURI;
aoqi@0 152 payloadName = new QName(nsUri, localPart);
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 WSDLOperationMapping opMapping = uniqueOpSignatureMap.get(new ActionBasedOperationSignature(action, payloadName));
aoqi@0 156 if (opMapping != null)
aoqi@0 157 return opMapping;
aoqi@0 158
aoqi@0 159 //Seems like in Wstrust STS wsdls, the payload does not match what is specified in the wsdl leading to incorrect
aoqi@0 160 // wsdl operation resolution. Use just wsa:Action to dispatch as a last resort.
aoqi@0 161 //try just with wsa:Action
aoqi@0 162 opMapping = actionMap.get(action);
aoqi@0 163 if (opMapping != null)
aoqi@0 164 return opMapping;
aoqi@0 165
aoqi@0 166 // invalid action header
aoqi@0 167 Message result = Messages.create(action, av, binding.getSOAPVersion());
aoqi@0 168
aoqi@0 169 throw new DispatchException(result);
aoqi@0 170
aoqi@0 171 }
aoqi@0 172 }

mercurial