|
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 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.client; |
|
27 |
|
28 import com.sun.istack.internal.NotNull; |
|
29 import com.sun.istack.internal.Nullable; |
|
30 import com.sun.xml.internal.ws.api.BindingID; |
|
31 import com.sun.xml.internal.ws.api.EndpointAddress; |
|
32 import com.sun.xml.internal.ws.api.WSService; |
|
33 import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory; |
|
34 import com.sun.xml.internal.ws.api.policy.PolicyResolver; |
|
35 import com.sun.xml.internal.ws.api.client.WSPortInfo; |
|
36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
|
37 import com.sun.xml.internal.ws.binding.BindingImpl; |
|
38 import com.sun.xml.internal.ws.binding.WebServiceFeatureList; |
|
39 import com.sun.xml.internal.ws.policy.PolicyMap; |
|
40 import com.sun.xml.internal.ws.policy.jaxws.PolicyUtil; |
|
41 |
|
42 import javax.xml.namespace.QName; |
|
43 import javax.xml.ws.WebServiceFeature; |
|
44 |
|
45 /** |
|
46 * Information about a port. |
|
47 * <p/> |
|
48 * This object is owned by {@link WSServiceDelegate} to keep track of a port, |
|
49 * since a port maybe added dynamically. |
|
50 * |
|
51 * @author JAXWS Development Team |
|
52 */ |
|
53 public class PortInfo implements WSPortInfo { |
|
54 private final @NotNull WSServiceDelegate owner; |
|
55 |
|
56 public final @NotNull QName portName; |
|
57 public final @NotNull EndpointAddress targetEndpoint; |
|
58 public final @NotNull BindingID bindingId; |
|
59 |
|
60 public final @NotNull PolicyMap policyMap; |
|
61 /** |
|
62 * If a port is known statically to a WSDL, {@link PortInfo} may |
|
63 * have the corresponding WSDL model. This would occur when the |
|
64 * service was created with the WSDL location and the port is defined |
|
65 * in the WSDL. |
|
66 * <p/> |
|
67 * If this is a {@link SEIPortInfo}, then this is always non-null. |
|
68 */ |
|
69 public final @Nullable WSDLPort portModel; |
|
70 |
|
71 public PortInfo(WSServiceDelegate owner, EndpointAddress targetEndpoint, QName name, BindingID bindingId) { |
|
72 this.owner = owner; |
|
73 this.targetEndpoint = targetEndpoint; |
|
74 this.portName = name; |
|
75 this.bindingId = bindingId; |
|
76 this.portModel = getPortModel(owner, name); |
|
77 this.policyMap = createPolicyMap(); |
|
78 |
|
79 } |
|
80 |
|
81 public PortInfo(@NotNull WSServiceDelegate owner, @NotNull WSDLPort port) { |
|
82 this.owner = owner; |
|
83 this.targetEndpoint = port.getAddress(); |
|
84 this.portName = port.getName(); |
|
85 this.bindingId = port.getBinding().getBindingId(); |
|
86 this.portModel = port; |
|
87 this.policyMap = createPolicyMap(); |
|
88 } |
|
89 |
|
90 public PolicyMap getPolicyMap() { |
|
91 return policyMap; |
|
92 } |
|
93 |
|
94 public PolicyMap createPolicyMap() { |
|
95 PolicyMap map; |
|
96 if(portModel != null) { |
|
97 map = portModel.getOwner().getParent().getPolicyMap(); |
|
98 } else { |
|
99 map = PolicyResolverFactory.create().resolve(new PolicyResolver.ClientContext(null,owner.getContainer())); |
|
100 } |
|
101 //still map is null, create a empty map |
|
102 if(map == null) |
|
103 map = PolicyMap.createPolicyMap(null); |
|
104 return map; |
|
105 } |
|
106 /** |
|
107 * Creates {@link BindingImpl} for this {@link PortInfo}. |
|
108 * |
|
109 * @param webServiceFeatures |
|
110 * User-specified features. |
|
111 * @param portInterface |
|
112 * Null if this is for dispatch. Otherwise the interface the proxy is going to implement |
|
113 * @return |
|
114 * The initialized BindingImpl |
|
115 */ |
|
116 public BindingImpl createBinding(WebServiceFeature[] webServiceFeatures, Class<?> portInterface) { |
|
117 return createBinding(new WebServiceFeatureList(webServiceFeatures), portInterface, null); |
|
118 } |
|
119 |
|
120 public BindingImpl createBinding(WebServiceFeatureList webServiceFeatures, Class<?> portInterface, |
|
121 BindingImpl existingBinding) { |
|
122 if (existingBinding != null) { |
|
123 webServiceFeatures.addAll(existingBinding.getFeatures()); |
|
124 } |
|
125 |
|
126 Iterable<WebServiceFeature> configFeatures; |
|
127 //TODO incase of Dispatch, provide a way to User for complete control of the message processing by giving |
|
128 // ability to turn off the WSDL/Policy based features and its associated tubes. |
|
129 |
|
130 //Even in case of Dispatch, merge all features configured via WSDL/Policy or deployment configuration |
|
131 if (portModel != null) { |
|
132 // could have merged features from this.policyMap, but some features are set in WSDLModel which are not there in PolicyMap |
|
133 // for ex: <wsaw:UsingAddressing> wsdl extn., and since the policyMap features are merged into WSDLModel anyway during postFinished(), |
|
134 // So, using here WsdlModel for merging is right. |
|
135 |
|
136 // merge features from WSDL |
|
137 configFeatures = portModel.getFeatures(); |
|
138 } else { |
|
139 configFeatures = PolicyUtil.getPortScopedFeatures(policyMap, owner.getServiceName(),portName); |
|
140 } |
|
141 webServiceFeatures.mergeFeatures(configFeatures, false); |
|
142 |
|
143 // merge features from interceptor |
|
144 webServiceFeatures.mergeFeatures(owner.serviceInterceptor.preCreateBinding(this, portInterface, webServiceFeatures), false); |
|
145 |
|
146 BindingImpl bindingImpl = BindingImpl.create(bindingId, webServiceFeatures.toArray()); |
|
147 owner.getHandlerConfigurator().configureHandlers(this,bindingImpl); |
|
148 return bindingImpl; |
|
149 } |
|
150 |
|
151 //This method is used for Dispatch client only |
|
152 private WSDLPort getPortModel(WSServiceDelegate owner, QName portName) { |
|
153 |
|
154 if (owner.getWsdlService() != null){ |
|
155 Iterable<? extends WSDLPort> ports = owner.getWsdlService().getPorts(); |
|
156 for (WSDLPort port : ports){ |
|
157 if (port.getName().equals(portName)) |
|
158 return port; |
|
159 } |
|
160 } |
|
161 return null; |
|
162 } |
|
163 |
|
164 // |
|
165 // implementation of API PortInfo interface |
|
166 // |
|
167 |
|
168 @Nullable |
|
169 public WSDLPort getPort() { |
|
170 return portModel; |
|
171 } |
|
172 |
|
173 @NotNull |
|
174 public WSService getOwner() { |
|
175 return owner; |
|
176 } |
|
177 |
|
178 @NotNull |
|
179 public BindingID getBindingId() { |
|
180 return bindingId; |
|
181 } |
|
182 |
|
183 @NotNull |
|
184 public EndpointAddress getEndpointAddress() { |
|
185 return targetEndpoint; |
|
186 } |
|
187 |
|
188 /** |
|
189 * @deprecated |
|
190 * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}. |
|
191 * Use {@link WSServiceDelegate#getServiceName()}. |
|
192 */ |
|
193 public QName getServiceName() { |
|
194 return owner.getServiceName(); |
|
195 } |
|
196 |
|
197 /** |
|
198 * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}. |
|
199 * Use {@link #portName}. |
|
200 */ |
|
201 public QName getPortName() { |
|
202 return portName; |
|
203 } |
|
204 |
|
205 /** |
|
206 * @deprecated |
|
207 * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}. |
|
208 * Use {@link #bindingId}. |
|
209 */ |
|
210 public String getBindingID() { |
|
211 return bindingId.toString(); |
|
212 } |
|
213 } |