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