1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/client/WSServiceDelegate.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/client/WSServiceDelegate.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -30,18 +30,19 @@ 1.11 import com.sun.xml.internal.ws.Closeable; 1.12 import com.sun.xml.internal.ws.api.BindingID; 1.13 import com.sun.xml.internal.ws.api.ComponentFeature; 1.14 +import com.sun.xml.internal.ws.api.ComponentsFeature; 1.15 import com.sun.xml.internal.ws.api.ComponentFeature.Target; 1.16 import com.sun.xml.internal.ws.api.EndpointAddress; 1.17 import com.sun.xml.internal.ws.api.WSService; 1.18 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference; 1.19 import com.sun.xml.internal.ws.api.client.ServiceInterceptor; 1.20 import com.sun.xml.internal.ws.api.client.ServiceInterceptorFactory; 1.21 +import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; 1.22 import com.sun.xml.internal.ws.api.databinding.DatabindingFactory; 1.23 -import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; 1.24 +import com.sun.xml.internal.ws.api.databinding.MetadataReader; 1.25 import com.sun.xml.internal.ws.api.model.SEIModel; 1.26 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; 1.27 -import com.sun.xml.internal.ws.api.model.wsdl.WSDLService; 1.28 -import com.sun.xml.internal.ws.api.pipe.*; 1.29 +import com.sun.xml.internal.ws.api.pipe.Stubs; 1.30 import com.sun.xml.internal.ws.api.server.Container; 1.31 import com.sun.xml.internal.ws.api.server.ContainerResolver; 1.32 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; 1.33 @@ -50,9 +51,10 @@ 1.34 import com.sun.xml.internal.ws.client.HandlerConfigurator.AnnotationConfigurator; 1.35 import com.sun.xml.internal.ws.client.HandlerConfigurator.HandlerResolverImpl; 1.36 import com.sun.xml.internal.ws.client.sei.SEIStub; 1.37 + 1.38 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature; 1.39 +import com.sun.xml.internal.ws.developer.UsesJAXBContextFeature; 1.40 import com.sun.xml.internal.ws.developer.WSBindingProvider; 1.41 -import com.sun.xml.internal.ws.developer.UsesJAXBContextFeature; 1.42 import com.sun.xml.internal.ws.model.RuntimeModeler; 1.43 import com.sun.xml.internal.ws.model.SOAPSEIModel; 1.44 import com.sun.xml.internal.ws.model.wsdl.WSDLModelImpl; 1.45 @@ -64,9 +66,7 @@ 1.46 import com.sun.xml.internal.ws.util.JAXWSUtils; 1.47 import com.sun.xml.internal.ws.util.ServiceConfigurationError; 1.48 import com.sun.xml.internal.ws.util.ServiceFinder; 1.49 -import static com.sun.xml.internal.ws.util.xml.XmlUtil.createDefaultCatalogResolver; 1.50 import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser; 1.51 - 1.52 import org.xml.sax.EntityResolver; 1.53 import org.xml.sax.SAXException; 1.54 1.55 @@ -77,7 +77,13 @@ 1.56 import javax.xml.stream.XMLStreamException; 1.57 import javax.xml.transform.Source; 1.58 import javax.xml.transform.stream.StreamSource; 1.59 -import javax.xml.ws.*; 1.60 +import javax.xml.ws.BindingProvider; 1.61 +import javax.xml.ws.Dispatch; 1.62 +import javax.xml.ws.EndpointReference; 1.63 +import javax.xml.ws.Service; 1.64 +import javax.xml.ws.WebServiceClient; 1.65 +import javax.xml.ws.WebServiceException; 1.66 +import javax.xml.ws.WebServiceFeature; 1.67 import javax.xml.ws.handler.HandlerResolver; 1.68 import javax.xml.ws.soap.AddressingFeature; 1.69 import java.io.IOException; 1.70 @@ -87,10 +93,17 @@ 1.71 import java.net.URL; 1.72 import java.security.AccessController; 1.73 import java.security.PrivilegedAction; 1.74 -import java.util.*; 1.75 +import java.util.Collection; 1.76 +import java.util.HashMap; 1.77 +import java.util.HashSet; 1.78 +import java.util.Iterator; 1.79 +import java.util.Map; 1.80 +import java.util.Set; 1.81 import java.util.concurrent.Executor; 1.82 import java.util.concurrent.ThreadFactory; 1.83 1.84 +import static com.sun.xml.internal.ws.util.xml.XmlUtil.createDefaultCatalogResolver; 1.85 + 1.86 /** 1.87 * <code>Service</code> objects provide the client view of a Web service. 1.88 * 1.89 @@ -177,6 +190,10 @@ 1.90 1.91 1.92 public WSServiceDelegate(URL wsdlDocumentLocation, QName serviceName, Class<? extends Service> serviceClass, WebServiceFeature... features) { 1.93 + this(wsdlDocumentLocation, serviceName, serviceClass, new WebServiceFeatureList(features)); 1.94 + } 1.95 + 1.96 + protected WSServiceDelegate(URL wsdlDocumentLocation, QName serviceName, Class<? extends Service> serviceClass, WebServiceFeatureList features) { 1.97 this( 1.98 wsdlDocumentLocation==null ? null : new StreamSource(wsdlDocumentLocation.toExternalForm()), 1.99 serviceName,serviceClass, features); 1.100 @@ -187,6 +204,14 @@ 1.101 * Either {@link Service}.class or other generated service-derived classes. 1.102 */ 1.103 public WSServiceDelegate(@Nullable Source wsdl, @NotNull QName serviceName, @NotNull final Class<? extends Service> serviceClass, WebServiceFeature... features) { 1.104 + this(wsdl, serviceName, serviceClass, new WebServiceFeatureList(features)); 1.105 + } 1.106 + 1.107 + /** 1.108 + * @param serviceClass 1.109 + * Either {@link Service}.class or other generated service-derived classes. 1.110 + */ 1.111 + protected WSServiceDelegate(@Nullable Source wsdl, @NotNull QName serviceName, @NotNull final Class<? extends Service> serviceClass, WebServiceFeatureList features) { 1.112 this(wsdl, null, serviceName, serviceClass, features); 1.113 } 1.114 1.115 @@ -195,15 +220,26 @@ 1.116 * Either {@link Service}.class or other generated service-derived classes. 1.117 */ 1.118 public WSServiceDelegate(@Nullable Source wsdl, @Nullable WSDLServiceImpl service, @NotNull QName serviceName, @NotNull final Class<? extends Service> serviceClass, WebServiceFeature... features) { 1.119 + this(wsdl, service, serviceName, serviceClass, new WebServiceFeatureList(features)); 1.120 + } 1.121 + 1.122 + /** 1.123 + * @param serviceClass 1.124 + * Either {@link Service}.class or other generated service-derived classes. 1.125 + */ 1.126 + public WSServiceDelegate(@Nullable Source wsdl, @Nullable WSDLServiceImpl service, @NotNull QName serviceName, @NotNull final Class<? extends Service> serviceClass, WebServiceFeatureList features) { 1.127 //we cant create a Service without serviceName 1.128 - if (serviceName == null) 1.129 - throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME_NULL(serviceName)); 1.130 + if (serviceName == null) { 1.131 + throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME_NULL(null)); 1.132 + } 1.133 1.134 - this.features = new WebServiceFeatureList(features); 1.135 + this.features = features; 1.136 1.137 InitParams initParams = INIT_PARAMS.get(); 1.138 INIT_PARAMS.set(null); // mark it as consumed 1.139 - if(initParams==null) initParams = EMPTY_PARAMS; 1.140 + if(initParams==null) { 1.141 + initParams = EMPTY_PARAMS; 1.142 + } 1.143 1.144 this.serviceName = serviceName; 1.145 this.serviceClass = serviceClass; 1.146 @@ -221,10 +257,26 @@ 1.147 break; 1.148 case CONTAINER: 1.149 this.container.getComponents().add(cf.getComponent()); 1.150 + break; 1.151 default: 1.152 throw new IllegalArgumentException(); 1.153 } 1.154 } 1.155 + ComponentsFeature csf = this.features.get(ComponentsFeature.class); 1.156 + if (csf != null) { 1.157 + for (ComponentFeature cfi : csf.getComponentFeatures()) { 1.158 + switch(cfi.getTarget()) { 1.159 + case SERVICE: 1.160 + getComponents().add(cfi.getComponent()); 1.161 + break; 1.162 + case CONTAINER: 1.163 + this.container.getComponents().add(cfi.getComponent()); 1.164 + break; 1.165 + default: 1.166 + throw new IllegalArgumentException(); 1.167 + } 1.168 + } 1.169 + } 1.170 1.171 // load interceptor 1.172 ServiceInterceptor interceptor = ServiceInterceptorFactory.load(this, Thread.currentThread().getContextClassLoader()); 1.173 @@ -354,10 +406,11 @@ 1.174 1.175 public <T> T getPort(WSEndpointReference wsepr, Class<T> portInterface, WebServiceFeature... features) { 1.176 //get the portType from SEI, so that it can be used if EPR does n't have endpointName 1.177 - QName portTypeName = RuntimeModeler.getPortTypeName(portInterface); 1.178 + WebServiceFeatureList featureList = new WebServiceFeatureList(features); 1.179 + QName portTypeName = RuntimeModeler.getPortTypeName(portInterface, getMetadadaReader(featureList, portInterface.getClassLoader())); 1.180 //if port name is not specified in EPR, it will use portTypeName to get it from the WSDL model. 1.181 QName portName = getPortNameFromEPR(wsepr, portTypeName); 1.182 - return getPort(wsepr,portName,portInterface,new WebServiceFeatureList(features)); 1.183 + return getPort(wsepr,portName,portInterface, featureList); 1.184 } 1.185 1.186 protected <T> T getPort(WSEndpointReference wsepr, QName portName, Class<T> portInterface, 1.187 @@ -366,29 +419,38 @@ 1.188 if (cf != null && !Target.STUB.equals(cf.getTarget())) { 1.189 throw new IllegalArgumentException(); 1.190 } 1.191 + ComponentsFeature csf = features.get(ComponentsFeature.class); 1.192 + if (csf != null) { 1.193 + for (ComponentFeature cfi : csf.getComponentFeatures()) { 1.194 + if (!Target.STUB.equals(cfi.getTarget())) 1.195 + throw new IllegalArgumentException(); 1.196 + } 1.197 + } 1.198 features.addAll(this.features); 1.199 1.200 SEIPortInfo spi = addSEI(portName, portInterface, features); 1.201 return createEndpointIFBaseProxy(wsepr,portName,portInterface,features, spi); 1.202 } 1.203 1.204 + @Override 1.205 public <T> T getPort(Class<T> portInterface, WebServiceFeature... features) { 1.206 //get the portType from SEI 1.207 - QName portTypeName = RuntimeModeler.getPortTypeName(portInterface); 1.208 - WSDLServiceImpl wsdlService = this.wsdlService; 1.209 - if(wsdlService == null) { 1.210 + QName portTypeName = RuntimeModeler.getPortTypeName(portInterface, getMetadadaReader(new WebServiceFeatureList(features), portInterface.getClassLoader())); 1.211 + WSDLServiceImpl tmpWsdlService = this.wsdlService; 1.212 + if (tmpWsdlService == null) { 1.213 // assigning it to local variable and not setting it back to this.wsdlService intentionally 1.214 // as we don't want to include the service instance with information gathered from sei 1.215 - wsdlService = getWSDLModelfromSEI(portInterface); 1.216 + tmpWsdlService = getWSDLModelfromSEI(portInterface); 1.217 //still null? throw error need wsdl metadata to create a proxy 1.218 - if(wsdlService == null) { 1.219 + if(tmpWsdlService == null) { 1.220 throw new WebServiceException(ProviderApiMessages.NO_WSDL_NO_PORT(portInterface.getName())); 1.221 } 1.222 } 1.223 //get the first port corresponding to the SEI 1.224 - WSDLPortImpl port = wsdlService.getMatchingPort(portTypeName); 1.225 - if (port == null) 1.226 - throw new WebServiceException(ClientMessages.UNDEFINED_PORT_TYPE(portTypeName)); 1.227 + WSDLPortImpl port = tmpWsdlService.getMatchingPort(portTypeName); 1.228 + if (port == null) { 1.229 + throw new WebServiceException(ClientMessages.UNDEFINED_PORT_TYPE(portTypeName)); 1.230 + } 1.231 QName portName = port.getName(); 1.232 return getPort(portName, portInterface,features); 1.233 } 1.234 @@ -424,6 +486,13 @@ 1.235 if (cf != null && !Target.STUB.equals(cf.getTarget())) { 1.236 throw new IllegalArgumentException(); 1.237 } 1.238 + ComponentsFeature csf = features.get(ComponentsFeature.class); 1.239 + if (csf != null) { 1.240 + for (ComponentFeature cfi : csf.getComponentFeatures()) { 1.241 + if (!Target.STUB.equals(cfi.getTarget())) 1.242 + throw new IllegalArgumentException(); 1.243 + } 1.244 + } 1.245 features.addAll(this.features); 1.246 1.247 BindingImpl binding = port.createBinding(features, null, null); 1.248 @@ -507,6 +576,13 @@ 1.249 if (cf != null && !Target.STUB.equals(cf.getTarget())) { 1.250 throw new IllegalArgumentException(); 1.251 } 1.252 + ComponentsFeature csf = features.get(ComponentsFeature.class); 1.253 + if (csf != null) { 1.254 + for (ComponentFeature cfi : csf.getComponentFeatures()) { 1.255 + if (!Target.STUB.equals(cfi.getTarget())) 1.256 + throw new IllegalArgumentException(); 1.257 + } 1.258 + } 1.259 features.addAll(this.features); 1.260 1.261 BindingImpl binding = port.createBinding(features, null, null); 1.262 @@ -664,6 +740,7 @@ 1.263 return ports.keySet().iterator(); 1.264 } 1.265 1.266 + @Override 1.267 public URL getWSDLDocumentLocation() { 1.268 if(wsdlService==null) return null; 1.269 try { 1.270 @@ -676,8 +753,9 @@ 1.271 private <T> T createEndpointIFBaseProxy(@Nullable WSEndpointReference epr,QName portName, Class<T> portInterface, 1.272 WebServiceFeatureList webServiceFeatures, SEIPortInfo eif) { 1.273 //fail if service doesnt have WSDL 1.274 - if (wsdlService == null) 1.275 + if (wsdlService == null) { 1.276 throw new WebServiceException(ClientMessages.INVALID_SERVICE_NO_WSDL(serviceName)); 1.277 + } 1.278 1.279 if (wsdlService.get(portName)==null) { 1.280 throw new WebServiceException( 1.281 @@ -706,7 +784,6 @@ 1.282 } 1.283 1.284 protected InvocationHandler getStubHandler(BindingImpl binding, SEIPortInfo eif, @Nullable WSEndpointReference epr) { 1.285 - SEIPortInfo spi = (SEIPortInfo) eif; 1.286 return new SEIStub(eif, binding, eif.model, epr); 1.287 } 1.288 1.289 @@ -715,8 +792,9 @@ 1.290 */ 1.291 private StringBuilder buildWsdlPortNames() { 1.292 Set<QName> wsdlPortNames = new HashSet<QName>(); 1.293 - for (WSDLPortImpl port : wsdlService.getPorts()) 1.294 + for (WSDLPortImpl port : wsdlService.getPorts()) { 1.295 wsdlPortNames.add(port.getName()); 1.296 + } 1.297 return buildNameList(wsdlPortNames); 1.298 } 1.299 1.300 @@ -764,11 +842,24 @@ 1.301 config.setClassLoader(portInterface.getClassLoader()); 1.302 config.getMappingInfo().setPortName(portName); 1.303 1.304 + // if ExternalMetadataFeature present, ExternalMetadataReader will be created ... 1.305 + config.setMetadataReader(getMetadadaReader(features, portInterface.getClassLoader())); 1.306 + 1.307 com.sun.xml.internal.ws.db.DatabindingImpl rt = (com.sun.xml.internal.ws.db.DatabindingImpl)fac.createRuntime(config); 1.308 1.309 return rt.getModel(); 1.310 } 1.311 1.312 + private MetadataReader getMetadadaReader(WebServiceFeatureList features, ClassLoader classLoader) { 1.313 + if (features == null) return null; 1.314 + com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature ef = 1.315 + features.get(com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature.class); 1.316 + // TODO-Miran: would it be necessary to disable secure xml processing? 1.317 + if (ef != null) 1.318 + return ef.getMetadataReader(classLoader, false); 1.319 + return null; 1.320 + } 1.321 + 1.322 private SEIPortInfo createSEIPortInfo(QName portName, Class portInterface, WebServiceFeatureList features) { 1.323 WSDLPortImpl wsdlPort = getPortModel(wsdlService, portName); 1.324 SEIModel model = buildRuntimeModel(serviceName, portName, portInterface, wsdlPort, features); 1.325 @@ -784,7 +875,8 @@ 1.326 return wsdlService; 1.327 } 1.328 1.329 - class DaemonThreadFactory implements ThreadFactory { 1.330 + static class DaemonThreadFactory implements ThreadFactory { 1.331 + @Override 1.332 public Thread newThread(Runnable r) { 1.333 Thread daemonThread = new Thread(r); 1.334 daemonThread.setDaemon(Boolean.TRUE); 1.335 @@ -800,26 +892,53 @@ 1.336 return new DelegatingLoader(loader1, loader2); 1.337 } 1.338 1.339 - private static final class DelegatingLoader 1.340 - extends ClassLoader 1.341 - { 1.342 - private final ClassLoader loader; 1.343 + private static final class DelegatingLoader extends ClassLoader { 1.344 + private final ClassLoader loader; 1.345 1.346 - DelegatingLoader(ClassLoader loader1, ClassLoader loader2) 1.347 - { 1.348 - super(loader2); 1.349 - this.loader = loader1; 1.350 - } 1.351 + @Override 1.352 + public int hashCode() { 1.353 + final int prime = 31; 1.354 + int result = 1; 1.355 + result = prime * result 1.356 + + ((loader == null) ? 0 : loader.hashCode()); 1.357 + result = prime * result 1.358 + + ((getParent() == null) ? 0 : getParent().hashCode()); 1.359 + return result; 1.360 + } 1.361 1.362 - protected Class findClass(String name) 1.363 - throws ClassNotFoundException 1.364 - { 1.365 - return loader.loadClass(name); 1.366 - } 1.367 + @Override 1.368 + public boolean equals(Object obj) { 1.369 + if (this == obj) 1.370 + return true; 1.371 + if (obj == null) 1.372 + return false; 1.373 + if (getClass() != obj.getClass()) 1.374 + return false; 1.375 + DelegatingLoader other = (DelegatingLoader) obj; 1.376 + if (loader == null) { 1.377 + if (other.loader != null) 1.378 + return false; 1.379 + } else if (!loader.equals(other.loader)) 1.380 + return false; 1.381 + if (getParent() == null) { 1.382 + if (other.getParent() != null) 1.383 + return false; 1.384 + } else if (!getParent().equals(other.getParent())) 1.385 + return false; 1.386 + return true; 1.387 + } 1.388 1.389 - protected URL findResource(String name) 1.390 - { 1.391 - return loader.getResource(name); 1.392 - } 1.393 + DelegatingLoader(ClassLoader loader1, ClassLoader loader2) { 1.394 + super(loader2); 1.395 + this.loader = loader1; 1.396 + } 1.397 + 1.398 + protected Class findClass(String name) throws ClassNotFoundException { 1.399 + return loader.loadClass(name); 1.400 + } 1.401 + 1.402 + protected URL findResource(String name) { 1.403 + return loader.getResource(name); 1.404 + } 1.405 } 1.406 }