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