|
1 /* |
|
2 * Copyright (c) 2007, 2012, 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 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.wsdl; |
|
27 |
|
28 import com.sun.istack.internal.Nullable; |
|
29 import com.sun.xml.internal.ws.api.WSBinding; |
|
30 import com.sun.xml.internal.ws.api.model.JavaMethod; |
|
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.message.Packet; |
|
36 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; |
|
37 import com.sun.xml.internal.ws.model.JavaMethodImpl; |
|
38 |
|
39 import javax.xml.namespace.QName; |
|
40 import java.util.HashMap; |
|
41 import java.util.Map; |
|
42 |
|
43 /** |
|
44 * An {@link WSDLOperationFinder} that uses SOAPAction as the key for dispatching. |
|
45 * <p/> |
|
46 * A map of all SOAPAction on the port and the corresponding WSDL operation QName |
|
47 * is initialized in the constructor. The SOAPAction from the |
|
48 * request {@link com.sun.xml.internal.ws.api.message.Packet} is used as the key to identify the associated wsdl operation. |
|
49 * |
|
50 * @author Jitendra Kotamraju |
|
51 */ |
|
52 final class SOAPActionBasedOperationFinder extends WSDLOperationFinder { |
|
53 private final Map<String, WSDLOperationMapping> methodHandlers; |
|
54 |
|
55 public SOAPActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) { |
|
56 super(wsdlModel,binding,seiModel); |
|
57 methodHandlers = new HashMap<String, WSDLOperationMapping>(); |
|
58 |
|
59 // Find if any SOAPAction repeat for operations |
|
60 Map<String, Integer> unique = new HashMap<String, Integer>(); |
|
61 if (seiModel != null) { |
|
62 for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { |
|
63 String soapAction = m.getSOAPAction(); |
|
64 Integer count = unique.get(soapAction); |
|
65 if (count == null) { |
|
66 unique.put(soapAction, 1); |
|
67 } else { |
|
68 unique.put(soapAction, ++count); |
|
69 } |
|
70 } |
|
71 |
|
72 for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) { |
|
73 String soapAction = m.getSOAPAction(); |
|
74 // Set up method handlers only for unique SOAPAction values so |
|
75 // that dispatching happens consistently for a method |
|
76 if (unique.get(soapAction) == 1) { |
|
77 methodHandlers.put('"' + soapAction + '"', wsdlOperationMapping(m)); |
|
78 } |
|
79 } |
|
80 } else { |
|
81 for(WSDLBoundOperation wsdlOp: wsdlModel.getBinding().getBindingOperations()) { |
|
82 methodHandlers.put(wsdlOp.getSOAPAction(), wsdlOperationMapping(wsdlOp)); |
|
83 } |
|
84 } |
|
85 |
|
86 } |
|
87 |
|
88 // public QName getWSDLOperationQName(Packet request) { |
|
89 public WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException { |
|
90 return request.soapAction == null ? null : methodHandlers.get(request.soapAction); |
|
91 } |
|
92 } |