aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.ws.client; aoqi@0: aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: import com.sun.istack.internal.Nullable; aoqi@0: import com.sun.xml.internal.ws.api.BindingID; aoqi@0: import com.sun.xml.internal.ws.api.EndpointAddress; aoqi@0: import com.sun.xml.internal.ws.api.WSService; aoqi@0: import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory; aoqi@0: import com.sun.xml.internal.ws.api.policy.PolicyResolver; aoqi@0: import com.sun.xml.internal.ws.api.client.WSPortInfo; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; aoqi@0: import com.sun.xml.internal.ws.binding.BindingImpl; aoqi@0: import com.sun.xml.internal.ws.binding.WebServiceFeatureList; aoqi@0: import com.sun.xml.internal.ws.policy.PolicyMap; aoqi@0: import com.sun.xml.internal.ws.policy.jaxws.PolicyUtil; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.ws.WebServiceFeature; aoqi@0: aoqi@0: /** aoqi@0: * Information about a port. aoqi@0: *

aoqi@0: * This object is owned by {@link WSServiceDelegate} to keep track of a port, aoqi@0: * since a port maybe added dynamically. aoqi@0: * aoqi@0: * @author JAXWS Development Team aoqi@0: */ aoqi@0: public class PortInfo implements WSPortInfo { aoqi@0: private final @NotNull WSServiceDelegate owner; aoqi@0: aoqi@0: public final @NotNull QName portName; aoqi@0: public final @NotNull EndpointAddress targetEndpoint; aoqi@0: public final @NotNull BindingID bindingId; aoqi@0: aoqi@0: public final @NotNull PolicyMap policyMap; aoqi@0: /** aoqi@0: * If a port is known statically to a WSDL, {@link PortInfo} may aoqi@0: * have the corresponding WSDL model. This would occur when the aoqi@0: * service was created with the WSDL location and the port is defined aoqi@0: * in the WSDL. aoqi@0: *

aoqi@0: * If this is a {@link SEIPortInfo}, then this is always non-null. aoqi@0: */ aoqi@0: public final @Nullable WSDLPort portModel; aoqi@0: aoqi@0: public PortInfo(WSServiceDelegate owner, EndpointAddress targetEndpoint, QName name, BindingID bindingId) { aoqi@0: this.owner = owner; aoqi@0: this.targetEndpoint = targetEndpoint; aoqi@0: this.portName = name; aoqi@0: this.bindingId = bindingId; aoqi@0: this.portModel = getPortModel(owner, name); aoqi@0: this.policyMap = createPolicyMap(); aoqi@0: aoqi@0: } aoqi@0: aoqi@0: public PortInfo(@NotNull WSServiceDelegate owner, @NotNull WSDLPort port) { aoqi@0: this.owner = owner; aoqi@0: this.targetEndpoint = port.getAddress(); aoqi@0: this.portName = port.getName(); aoqi@0: this.bindingId = port.getBinding().getBindingId(); aoqi@0: this.portModel = port; aoqi@0: this.policyMap = createPolicyMap(); aoqi@0: } aoqi@0: aoqi@0: public PolicyMap getPolicyMap() { aoqi@0: return policyMap; aoqi@0: } aoqi@0: aoqi@0: public PolicyMap createPolicyMap() { aoqi@0: PolicyMap map; aoqi@0: if(portModel != null) { aoqi@0: map = portModel.getOwner().getParent().getPolicyMap(); aoqi@0: } else { aoqi@0: map = PolicyResolverFactory.create().resolve(new PolicyResolver.ClientContext(null,owner.getContainer())); aoqi@0: } aoqi@0: //still map is null, create a empty map aoqi@0: if(map == null) aoqi@0: map = PolicyMap.createPolicyMap(null); aoqi@0: return map; aoqi@0: } aoqi@0: /** aoqi@0: * Creates {@link BindingImpl} for this {@link PortInfo}. aoqi@0: * aoqi@0: * @param webServiceFeatures aoqi@0: * User-specified features. aoqi@0: * @param portInterface aoqi@0: * Null if this is for dispatch. Otherwise the interface the proxy is going to implement aoqi@0: * @return aoqi@0: * The initialized BindingImpl aoqi@0: */ aoqi@0: public BindingImpl createBinding(WebServiceFeature[] webServiceFeatures, Class portInterface) { aoqi@0: return createBinding(new WebServiceFeatureList(webServiceFeatures), portInterface, null); aoqi@0: } aoqi@0: aoqi@0: public BindingImpl createBinding(WebServiceFeatureList webServiceFeatures, Class portInterface, aoqi@0: BindingImpl existingBinding) { aoqi@0: if (existingBinding != null) { aoqi@0: webServiceFeatures.addAll(existingBinding.getFeatures()); aoqi@0: } aoqi@0: aoqi@0: Iterable configFeatures; aoqi@0: //TODO incase of Dispatch, provide a way to User for complete control of the message processing by giving aoqi@0: // ability to turn off the WSDL/Policy based features and its associated tubes. aoqi@0: aoqi@0: //Even in case of Dispatch, merge all features configured via WSDL/Policy or deployment configuration aoqi@0: if (portModel != null) { aoqi@0: // could have merged features from this.policyMap, but some features are set in WSDLModel which are not there in PolicyMap aoqi@0: // for ex: wsdl extn., and since the policyMap features are merged into WSDLModel anyway during postFinished(), aoqi@0: // So, using here WsdlModel for merging is right. aoqi@0: aoqi@0: // merge features from WSDL aoqi@0: configFeatures = portModel.getFeatures(); aoqi@0: } else { aoqi@0: configFeatures = PolicyUtil.getPortScopedFeatures(policyMap, owner.getServiceName(),portName); aoqi@0: } aoqi@0: webServiceFeatures.mergeFeatures(configFeatures, false); aoqi@0: aoqi@0: // merge features from interceptor aoqi@0: webServiceFeatures.mergeFeatures(owner.serviceInterceptor.preCreateBinding(this, portInterface, webServiceFeatures), false); aoqi@0: aoqi@0: BindingImpl bindingImpl = BindingImpl.create(bindingId, webServiceFeatures.toArray()); aoqi@0: owner.getHandlerConfigurator().configureHandlers(this,bindingImpl); aoqi@0: return bindingImpl; aoqi@0: } aoqi@0: aoqi@0: //This method is used for Dispatch client only aoqi@0: private WSDLPort getPortModel(WSServiceDelegate owner, QName portName) { aoqi@0: aoqi@0: if (owner.getWsdlService() != null){ aoqi@0: Iterable ports = owner.getWsdlService().getPorts(); aoqi@0: for (WSDLPort port : ports){ aoqi@0: if (port.getName().equals(portName)) aoqi@0: return port; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // implementation of API PortInfo interface aoqi@0: // aoqi@0: aoqi@0: @Nullable aoqi@0: public WSDLPort getPort() { aoqi@0: return portModel; aoqi@0: } aoqi@0: aoqi@0: @NotNull aoqi@0: public WSService getOwner() { aoqi@0: return owner; aoqi@0: } aoqi@0: aoqi@0: @NotNull aoqi@0: public BindingID getBindingId() { aoqi@0: return bindingId; aoqi@0: } aoqi@0: aoqi@0: @NotNull aoqi@0: public EndpointAddress getEndpointAddress() { aoqi@0: return targetEndpoint; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @deprecated aoqi@0: * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}. aoqi@0: * Use {@link WSServiceDelegate#getServiceName()}. aoqi@0: */ aoqi@0: public QName getServiceName() { aoqi@0: return owner.getServiceName(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}. aoqi@0: * Use {@link #portName}. aoqi@0: */ aoqi@0: public QName getPortName() { aoqi@0: return portName; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @deprecated aoqi@0: * Only meant to be used via {@link javax.xml.ws.handler.PortInfo}. aoqi@0: * Use {@link #bindingId}. aoqi@0: */ aoqi@0: public String getBindingID() { aoqi@0: return bindingId.toString(); aoqi@0: } aoqi@0: }