src/share/jaxws_classes/com/sun/xml/internal/ws/server/EndpointFactory.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 384
8f2986ff0235
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.server;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.istack.internal.Nullable;
alanb@368 30 import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
ohair@286 31 import com.sun.xml.internal.ws.api.BindingID;
ohair@286 32 import com.sun.xml.internal.ws.api.WSBinding;
alanb@368 33 import com.sun.xml.internal.ws.api.WSFeatureList;
alanb@368 34 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
alanb@368 35 import com.sun.xml.internal.ws.api.databinding.DatabindingFactory;
alanb@368 36 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
ohair@286 37 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
ohair@286 38 import com.sun.xml.internal.ws.api.model.SEIModel;
mkos@408 39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel;
ohair@286 40 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
mkos@408 41 import com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
alanb@368 42 import com.sun.xml.internal.ws.api.policy.PolicyResolver;
alanb@368 43 import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory;
alanb@368 44 import com.sun.xml.internal.ws.api.server.AsyncProvider;
alanb@368 45 import com.sun.xml.internal.ws.api.server.Container;
alanb@368 46 import com.sun.xml.internal.ws.api.server.ContainerResolver;
alanb@368 47 import com.sun.xml.internal.ws.api.server.InstanceResolver;
alanb@368 48 import com.sun.xml.internal.ws.api.server.Invoker;
alanb@368 49 import com.sun.xml.internal.ws.api.server.SDDocument;
alanb@368 50 import com.sun.xml.internal.ws.api.server.SDDocumentSource;
alanb@368 51 import com.sun.xml.internal.ws.api.server.WSEndpoint;
alanb@368 52 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
ohair@286 53 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension;
ohair@286 54 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver;
ohair@286 55 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver.Parser;
ohair@286 56 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension;
ohair@286 57 import com.sun.xml.internal.ws.binding.BindingImpl;
ohair@286 58 import com.sun.xml.internal.ws.binding.SOAPBindingImpl;
ohair@286 59 import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
ohair@286 60 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
alanb@368 61 import com.sun.xml.internal.ws.model.ReflectAnnotationReader;
ohair@286 62 import com.sun.xml.internal.ws.model.RuntimeModeler;
ohair@286 63 import com.sun.xml.internal.ws.model.SOAPSEIModel;
alanb@368 64 import com.sun.xml.internal.ws.policy.PolicyMap;
alanb@368 65 import com.sun.xml.internal.ws.policy.jaxws.PolicyUtil;
ohair@286 66 import com.sun.xml.internal.ws.resources.ServerMessages;
ohair@286 67 import com.sun.xml.internal.ws.server.provider.ProviderInvokerTube;
ohair@286 68 import com.sun.xml.internal.ws.server.sei.SEIInvokerTube;
ohair@286 69 import com.sun.xml.internal.ws.util.HandlerAnnotationInfo;
ohair@286 70 import com.sun.xml.internal.ws.util.HandlerAnnotationProcessor;
ohair@286 71 import com.sun.xml.internal.ws.util.ServiceConfigurationError;
ohair@286 72 import com.sun.xml.internal.ws.util.ServiceFinder;
alanb@368 73 import com.sun.xml.internal.ws.util.xml.XmlUtil;
ohair@286 74 import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser;
mkos@408 75
ohair@286 76 import org.xml.sax.EntityResolver;
alanb@368 77 import org.xml.sax.InputSource;
ohair@286 78 import org.xml.sax.SAXException;
ohair@286 79
ohair@286 80 import javax.jws.WebService;
ohair@286 81 import javax.xml.namespace.QName;
ohair@286 82 import javax.xml.stream.XMLStreamException;
alanb@368 83 import javax.xml.stream.XMLStreamReader;
ohair@286 84 import javax.xml.ws.Provider;
ohair@286 85 import javax.xml.ws.WebServiceException;
alanb@368 86 import javax.xml.ws.WebServiceFeature;
ohair@286 87 import javax.xml.ws.WebServiceProvider;
ohair@286 88 import javax.xml.ws.soap.SOAPBinding;
mkos@408 89
ohair@286 90 import java.io.IOException;
ohair@286 91 import java.net.URL;
ohair@286 92 import java.util.ArrayList;
ohair@286 93 import java.util.Collection;
ohair@286 94 import java.util.HashMap;
ohair@286 95 import java.util.List;
ohair@286 96 import java.util.Map;
ohair@286 97 import java.util.logging.Logger;
ohair@286 98
ohair@286 99 /**
ohair@286 100 * Entry point to the JAX-WS RI server-side runtime.
ohair@286 101 *
ohair@286 102 * @author Kohsuke Kawaguchi
ohair@286 103 * @author Jitendra Kotamraju
ohair@286 104 */
ohair@286 105 public class EndpointFactory {
ohair@286 106 private static final EndpointFactory instance = new EndpointFactory();
ohair@286 107
ohair@286 108 public static EndpointFactory getInstance() {
ohair@286 109 return instance;
ohair@286 110 }
ohair@286 111
ohair@286 112 /**
ohair@286 113 * Implements {@link WSEndpoint#create}.
ohair@286 114 *
ohair@286 115 * No need to take WebServiceContext implementation. When InvokerPipe is
ohair@286 116 * instantiated, it calls InstanceResolver to set up a WebServiceContext.
ohair@286 117 * We shall only take delegate to getUserPrincipal and isUserInRole from adapter.
ohair@286 118 *
ohair@286 119 * <p>
ohair@286 120 * Nobody else should be calling this method.
ohair@286 121 */
ohair@286 122 public static <T> WSEndpoint<T> createEndpoint(
ohair@286 123 Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker,
ohair@286 124 @Nullable QName serviceName, @Nullable QName portName,
ohair@286 125 @Nullable Container container, @Nullable WSBinding binding,
ohair@286 126 @Nullable SDDocumentSource primaryWsdl,
ohair@286 127 @Nullable Collection<? extends SDDocumentSource> metadata,
ohair@286 128 EntityResolver resolver, boolean isTransportSynchronous) {
ohair@286 129 return createEndpoint(implType, processHandlerAnnotation, invoker, serviceName,
ohair@286 130 portName, container, binding, primaryWsdl, metadata, resolver, isTransportSynchronous, true);
ohair@286 131 }
ohair@286 132
ohair@286 133 public static <T> WSEndpoint<T> createEndpoint(
ohair@286 134 Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker,
ohair@286 135 @Nullable QName serviceName, @Nullable QName portName,
ohair@286 136 @Nullable Container container, @Nullable WSBinding binding,
ohair@286 137 @Nullable SDDocumentSource primaryWsdl,
ohair@286 138 @Nullable Collection<? extends SDDocumentSource> metadata,
ohair@286 139 EntityResolver resolver, boolean isTransportSynchronous, boolean isStandard) {
ohair@286 140 EndpointFactory factory = container != null ? container.getSPI(EndpointFactory.class) : null;
ohair@286 141 if (factory == null)
ohair@286 142 factory = EndpointFactory.getInstance();
ohair@286 143
ohair@286 144 return factory.create(
ohair@286 145 implType,processHandlerAnnotation, invoker,serviceName,portName,container,binding,primaryWsdl,metadata,resolver,isTransportSynchronous,isStandard);
ohair@286 146 }
ohair@286 147
ohair@286 148 /**
ohair@286 149 * Implements {@link WSEndpoint#create}.
ohair@286 150 *
ohair@286 151 * No need to take WebServiceContext implementation. When InvokerPipe is
ohair@286 152 * instantiated, it calls InstanceResolver to set up a WebServiceContext.
ohair@286 153 * We shall only take delegate to getUserPrincipal and isUserInRole from adapter.
ohair@286 154 *
ohair@286 155 * <p>
ohair@286 156 * Nobody else should be calling this method.
ohair@286 157 */
ohair@286 158 public <T> WSEndpoint<T> create(
ohair@286 159 Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker,
ohair@286 160 @Nullable QName serviceName, @Nullable QName portName,
ohair@286 161 @Nullable Container container, @Nullable WSBinding binding,
ohair@286 162 @Nullable SDDocumentSource primaryWsdl,
ohair@286 163 @Nullable Collection<? extends SDDocumentSource> metadata,
ohair@286 164 EntityResolver resolver, boolean isTransportSynchronous) {
ohair@286 165 return create(implType, processHandlerAnnotation, invoker, serviceName,
ohair@286 166 portName, container, binding, primaryWsdl, metadata, resolver, isTransportSynchronous,
ohair@286 167 true);
ohair@286 168
ohair@286 169 }
ohair@286 170
ohair@286 171 public <T> WSEndpoint<T> create(
ohair@286 172 Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker,
ohair@286 173 @Nullable QName serviceName, @Nullable QName portName,
ohair@286 174 @Nullable Container container, @Nullable WSBinding binding,
ohair@286 175 @Nullable SDDocumentSource primaryWsdl,
ohair@286 176 @Nullable Collection<? extends SDDocumentSource> metadata,
ohair@286 177 EntityResolver resolver, boolean isTransportSynchronous, boolean isStandard) {
ohair@286 178
ohair@286 179 if(implType ==null)
ohair@286 180 throw new IllegalArgumentException();
ohair@286 181
alanb@368 182 MetadataReader metadataReader = getExternalMetadatReader(implType, binding);
alanb@368 183
ohair@286 184 if (isStandard) {
alanb@368 185 verifyImplementorClass(implType, metadataReader);
ohair@286 186 }
ohair@286 187
ohair@286 188 if (invoker == null) {
ohair@286 189 invoker = InstanceResolver.createDefault(implType).createInvoker();
ohair@286 190 }
ohair@286 191
ohair@286 192 List<SDDocumentSource> md = new ArrayList<SDDocumentSource>();
ohair@286 193 if(metadata!=null)
ohair@286 194 md.addAll(metadata);
ohair@286 195
ohair@286 196 if(primaryWsdl!=null && !md.contains(primaryWsdl))
ohair@286 197 md.add(primaryWsdl);
ohair@286 198
ohair@286 199 if(container==null)
ohair@286 200 container = ContainerResolver.getInstance().getContainer();
ohair@286 201
ohair@286 202 if(serviceName==null)
alanb@368 203 serviceName = getDefaultServiceName(implType, metadataReader);
ohair@286 204
ohair@286 205 if(portName==null)
alanb@368 206 portName = getDefaultPortName(serviceName,implType, metadataReader);
ohair@286 207
ohair@286 208 {// error check
ohair@286 209 String serviceNS = serviceName.getNamespaceURI();
ohair@286 210 String portNS = portName.getNamespaceURI();
ohair@286 211 if (!serviceNS.equals(portNS)) {
ohair@286 212 throw new ServerRtException("wrong.tns.for.port",portNS, serviceNS);
ohair@286 213 }
ohair@286 214 }
ohair@286 215
ohair@286 216 // setting a default binding
ohair@286 217 if (binding == null)
ohair@286 218 binding = BindingImpl.create(BindingID.parse(implType));
ohair@286 219
ohair@286 220 if ( isStandard && primaryWsdl != null) {
ohair@286 221 verifyPrimaryWSDL(primaryWsdl, serviceName);
ohair@286 222 }
ohair@286 223
ohair@286 224 QName portTypeName = null;
ohair@286 225 if (isStandard && implType.getAnnotation(WebServiceProvider.class)==null) {
alanb@368 226 portTypeName = RuntimeModeler.getPortTypeName(implType, metadataReader);
ohair@286 227 }
ohair@286 228
ohair@286 229 // Categorises the documents as WSDL, Schema etc
ohair@286 230 List<SDDocumentImpl> docList = categoriseMetadata(md, serviceName, portTypeName);
ohair@286 231 // Finds the primary WSDL and makes sure that metadata doesn't have
ohair@286 232 // two concrete or abstract WSDLs
alanb@368 233 SDDocumentImpl primaryDoc = primaryWsdl != null ? SDDocumentImpl.create(primaryWsdl,serviceName,portTypeName) : findPrimary(docList);
ohair@286 234
ohair@286 235 EndpointAwareTube terminal;
mkos@408 236 WSDLPort wsdlPort = null;
ohair@286 237 AbstractSEIModelImpl seiModel = null;
ohair@286 238 // create WSDL model
ohair@286 239 if (primaryDoc != null) {
alanb@368 240 wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
ohair@286 241 }
ohair@286 242
ohair@286 243 WebServiceFeatureList features=((BindingImpl)binding).getFeatures();
ohair@286 244 if (isStandard) {
ohair@286 245 features.parseAnnotations(implType);
ohair@286 246 }
ohair@286 247 PolicyMap policyMap = null;
ohair@286 248 // create terminal pipe that invokes the application
ohair@286 249 if (isUseProviderTube(implType, isStandard)) {
ohair@286 250 //TODO incase of Provider, provide a way to User for complete control of the message processing by giving
ohair@286 251 // ability to turn off the WSDL/Policy based features and its associated tubes.
ohair@286 252
ohair@286 253 //Even in case of Provider, merge all features configured via WSDL/Policy or deployment configuration
ohair@286 254 Iterable<WebServiceFeature> configFtrs;
ohair@286 255 if(wsdlPort != null) {
ohair@286 256 policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
ohair@286 257 //Merge features from WSDL and other policy configuration
ohair@286 258 configFtrs = wsdlPort.getFeatures();
ohair@286 259 } else {
ohair@286 260 //No WSDL, so try to merge features from Policy configuration
ohair@286 261 policyMap = PolicyResolverFactory.create().resolve(
ohair@286 262 new PolicyResolver.ServerContext(null, container, implType, false));
ohair@286 263 configFtrs = PolicyUtil.getPortScopedFeatures(policyMap,serviceName,portName);
ohair@286 264 }
ohair@286 265 features.mergeFeatures(configFtrs, true);
alanb@368 266 terminal = createProviderInvokerTube(implType, binding, invoker, container);
ohair@286 267 } else {
ohair@286 268 // Create runtime model for non Provider endpoints
mkos@384 269 seiModel = createSEIModel(wsdlPort, implType, serviceName, portName, binding, primaryDoc);
ohair@286 270 if(binding instanceof SOAPBindingImpl){
ohair@286 271 //set portKnownHeaders on Binding, so that they can be used for MU processing
ohair@286 272 ((SOAPBindingImpl)binding).setPortKnownHeaders(
ohair@286 273 ((SOAPSEIModel)seiModel).getKnownHeaders());
ohair@286 274 }
ohair@286 275 // Generate WSDL for SEI endpoints(not for Provider endpoints)
ohair@286 276 if (primaryDoc == null) {
ohair@286 277 primaryDoc = generateWSDL(binding, seiModel, docList, container, implType);
ohair@286 278 // create WSDL model
alanb@368 279 wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
ohair@286 280 seiModel.freeze(wsdlPort);
ohair@286 281 }
ohair@286 282 policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
ohair@286 283 // New Features might have been added in WSDL through Policy.
ohair@286 284 //Merge features from WSDL and other policy configuration
ohair@286 285 // This sets only the wsdl features that are not already set(enabled/disabled)
ohair@286 286 features.mergeFeatures(wsdlPort.getFeatures(), true);
ohair@286 287 terminal = createSEIInvokerTube(seiModel,invoker,binding);
ohair@286 288 }
ohair@286 289
ohair@286 290 // Process @HandlerChain, if handler-chain is not set via Deployment Descriptor
ohair@286 291 if (processHandlerAnnotation) {
ohair@286 292 processHandlerAnnotation(binding, implType, serviceName, portName);
ohair@286 293 }
ohair@286 294 // Selects only required metadata for this endpoint from the passed-in metadata
ohair@286 295 if (primaryDoc != null) {
alanb@368 296 docList = findMetadataClosure(primaryDoc, docList, resolver);
ohair@286 297 }
alanb@368 298
ohair@286 299 ServiceDefinitionImpl serviceDefiniton = (primaryDoc != null) ? new ServiceDefinitionImpl(docList, primaryDoc) : null;
ohair@286 300
ohair@286 301 return create(serviceName, portName, binding, container, seiModel, wsdlPort, implType, serviceDefiniton,
ohair@286 302 terminal, isTransportSynchronous, policyMap);
ohair@286 303 }
ohair@286 304
ohair@286 305 protected <T> WSEndpoint<T> create(QName serviceName, QName portName, WSBinding binding, Container container, SEIModel seiModel, WSDLPort wsdlPort, Class<T> implType, ServiceDefinitionImpl serviceDefinition, EndpointAwareTube terminal, boolean isTransportSynchronous, PolicyMap policyMap) {
ohair@286 306 return new WSEndpointImpl<T>(serviceName, portName, binding, container, seiModel,
ohair@286 307 wsdlPort, implType, serviceDefinition, terminal, isTransportSynchronous, policyMap);
ohair@286 308 }
ohair@286 309
ohair@286 310 protected boolean isUseProviderTube(Class<?> implType, boolean isStandard) {
ohair@286 311 return !isStandard || implType.getAnnotation(WebServiceProvider.class)!=null;
ohair@286 312 }
ohair@286 313
ohair@286 314 protected EndpointAwareTube createSEIInvokerTube(AbstractSEIModelImpl seiModel, Invoker invoker, WSBinding binding) {
ohair@286 315 return new SEIInvokerTube(seiModel,invoker,binding);
ohair@286 316 }
ohair@286 317
alanb@368 318 protected <T> EndpointAwareTube createProviderInvokerTube(final Class<T> implType, final WSBinding binding,
alanb@368 319 final Invoker invoker, final Container container) {
alanb@368 320 return ProviderInvokerTube.create(implType, binding, invoker, container);
ohair@286 321 }
ohair@286 322 /**
ohair@286 323 * Goes through the original metadata documents and collects the required ones.
ohair@286 324 * This done traversing from primary WSDL and its imports until it builds a
ohair@286 325 * complete set of documents(transitive closure) for the endpoint.
ohair@286 326 *
ohair@286 327 * @param primaryDoc primary WSDL doc
ohair@286 328 * @param docList complete metadata
ohair@286 329 * @return new metadata that doesn't contain extraneous documnets.
ohair@286 330 */
alanb@368 331 private static List<SDDocumentImpl> findMetadataClosure(SDDocumentImpl primaryDoc, List<SDDocumentImpl> docList, EntityResolver resolver) {
ohair@286 332 // create a map for old metadata
ohair@286 333 Map<String, SDDocumentImpl> oldMap = new HashMap<String, SDDocumentImpl>();
ohair@286 334 for(SDDocumentImpl doc : docList) {
ohair@286 335 oldMap.put(doc.getSystemId().toString(), doc);
ohair@286 336 }
ohair@286 337 // create a map for new metadata
ohair@286 338 Map<String, SDDocumentImpl> newMap = new HashMap<String, SDDocumentImpl>();
ohair@286 339 newMap.put(primaryDoc.getSystemId().toString(), primaryDoc);
ohair@286 340
ohair@286 341 List<String> remaining = new ArrayList<String>();
ohair@286 342 remaining.addAll(primaryDoc.getImports());
ohair@286 343 while(!remaining.isEmpty()) {
ohair@286 344 String url = remaining.remove(0);
ohair@286 345 SDDocumentImpl doc = oldMap.get(url);
ohair@286 346 if (doc == null) {
ohair@286 347 // old metadata doesn't have this imported doc, may be external
alanb@368 348 if (resolver != null) {
alanb@368 349 try {
alanb@368 350 InputSource source = resolver.resolveEntity(null, url);
alanb@368 351 if (source != null) {
alanb@368 352 MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
alanb@368 353 XMLStreamReader reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(source.getByteStream());
alanb@368 354 xsb.createFromXMLStreamReader(reader);
alanb@368 355
alanb@368 356 SDDocumentSource sdocSource = SDDocumentImpl.create(new URL(url), xsb);
alanb@368 357 doc = SDDocumentImpl.create(sdocSource, null, null);
alanb@368 358 }
alanb@368 359 } catch (Exception ex) {
alanb@368 360 ex.printStackTrace();
alanb@368 361 }
alanb@368 362 }
ohair@286 363 }
ohair@286 364 // Check if new metadata already contains this doc
alanb@368 365 if (doc != null && !newMap.containsKey(url)) {
ohair@286 366 newMap.put(url, doc);
ohair@286 367 remaining.addAll(doc.getImports());
ohair@286 368 }
ohair@286 369 }
ohair@286 370 List<SDDocumentImpl> newMetadata = new ArrayList<SDDocumentImpl>();
ohair@286 371 newMetadata.addAll(newMap.values());
ohair@286 372 return newMetadata;
ohair@286 373 }
ohair@286 374
ohair@286 375 private static <T> void processHandlerAnnotation(WSBinding binding, Class<T> implType, QName serviceName, QName portName) {
ohair@286 376 HandlerAnnotationInfo chainInfo =
ohair@286 377 HandlerAnnotationProcessor.buildHandlerInfo(
ohair@286 378 implType, serviceName, portName, binding);
ohair@286 379 if (chainInfo != null) {
ohair@286 380 binding.setHandlerChain(chainInfo.getHandlers());
ohair@286 381 if (binding instanceof SOAPBinding) {
ohair@286 382 ((SOAPBinding) binding).setRoles(chainInfo.getRoles());
ohair@286 383 }
ohair@286 384 }
ohair@286 385
ohair@286 386 }
ohair@286 387
ohair@286 388 /**
ohair@286 389 * Verifies if the endpoint implementor class has @WebService or @WebServiceProvider
ohair@286 390 * annotation
ohair@286 391 *
ohair@286 392 * @return
ohair@286 393 * true if it is a Provider or AsyncProvider endpoint
ohair@286 394 * false otherwise
ohair@286 395 * @throws java.lang.IllegalArgumentException
ohair@286 396 * If it doesn't have any one of @WebService or @WebServiceProvider
ohair@286 397 * If it has both @WebService and @WebServiceProvider annotations
ohair@286 398 */
ohair@286 399 public static boolean verifyImplementorClass(Class<?> clz) {
alanb@368 400 return verifyImplementorClass(clz, null);
alanb@368 401 }
alanb@368 402
alanb@368 403 /**
alanb@368 404 * Verifies if the endpoint implementor class has @WebService or @WebServiceProvider
alanb@368 405 * annotation; passing MetadataReader instance allows to read annotations from
alanb@368 406 * xml descriptor instead of class's annotations
alanb@368 407 *
alanb@368 408 * @return
alanb@368 409 * true if it is a Provider or AsyncProvider endpoint
alanb@368 410 * false otherwise
alanb@368 411 * @throws java.lang.IllegalArgumentException
alanb@368 412 * If it doesn't have any one of @WebService or @WebServiceProvider
alanb@368 413 * If it has both @WebService and @WebServiceProvider annotations
alanb@368 414 */
alanb@368 415 public static boolean verifyImplementorClass(Class<?> clz, MetadataReader metadataReader) {
alanb@368 416
alanb@368 417 if (metadataReader == null) {
alanb@368 418 metadataReader = new ReflectAnnotationReader();
alanb@368 419 }
alanb@368 420
alanb@368 421 WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, clz);
alanb@368 422 WebService ws = metadataReader.getAnnotation(WebService.class, clz);
ohair@286 423 if (wsProvider == null && ws == null) {
ohair@286 424 throw new IllegalArgumentException(clz +" has neither @WebService nor @WebServiceProvider annotation");
ohair@286 425 }
ohair@286 426 if (wsProvider != null && ws != null) {
ohair@286 427 throw new IllegalArgumentException(clz +" has both @WebService and @WebServiceProvider annotations");
ohair@286 428 }
ohair@286 429 if (wsProvider != null) {
ohair@286 430 if (Provider.class.isAssignableFrom(clz) || AsyncProvider.class.isAssignableFrom(clz)) {
ohair@286 431 return true;
ohair@286 432 }
ohair@286 433 throw new IllegalArgumentException(clz +" doesn't implement Provider or AsyncProvider interface");
ohair@286 434 }
ohair@286 435 return false;
ohair@286 436 }
ohair@286 437
ohair@286 438
ohair@286 439 private static AbstractSEIModelImpl createSEIModel(WSDLPort wsdlPort,
mkos@384 440 Class<?> implType, @NotNull QName serviceName, @NotNull QName portName, WSBinding binding,
mkos@384 441 SDDocumentSource primaryWsdl) {
ohair@286 442 DatabindingFactory fac = DatabindingFactory.newInstance();
ohair@286 443 DatabindingConfig config = new DatabindingConfig();
ohair@286 444 config.setEndpointClass(implType);
ohair@286 445 config.getMappingInfo().setServiceName(serviceName);
ohair@286 446 config.setWsdlPort(wsdlPort);
ohair@286 447 config.setWSBinding(binding);
ohair@286 448 config.setClassLoader(implType.getClassLoader());
ohair@286 449 config.getMappingInfo().setPortName(portName);
mkos@384 450 if (primaryWsdl != null) config.setWsdlURL(primaryWsdl.getSystemId());
alanb@368 451 config.setMetadataReader(getExternalMetadatReader(implType, binding));
alanb@368 452
ohair@286 453 com.sun.xml.internal.ws.db.DatabindingImpl rt = (com.sun.xml.internal.ws.db.DatabindingImpl)fac.createRuntime(config);
ohair@286 454 return (AbstractSEIModelImpl) rt.getModel();
ohair@286 455 }
ohair@286 456
alanb@368 457 public static MetadataReader getExternalMetadatReader(Class<?> implType, WSBinding binding) {
alanb@368 458 com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature ef = binding.getFeature(
alanb@368 459 com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature.class);
alanb@368 460 // TODO-Miran: would it be necessary to disable secure xml processing?
alanb@368 461 if (ef != null)
alanb@368 462 return ef.getMetadataReader(implType.getClassLoader(), false);
alanb@368 463 return null;
alanb@368 464 }
alanb@368 465
ohair@286 466 /**
ohair@286 467 *Set the mtom enable setting from wsdl model (mtom policy assertion) on to @link WSBinding} if DD has
ohair@286 468 * not already set it on BindingID. Also check conflicts.
ohair@286 469 */
ohair@286 470 /*
ohair@286 471 private static void applyEffectiveMtomSetting(WSDLBoundPortType wsdlBinding, WSBinding binding){
ohair@286 472 if(wsdlBinding.isMTOMEnabled()){
ohair@286 473 BindingID bindingId = binding.getBindingId();
ohair@286 474 if(bindingId.isMTOMEnabled() == null){
ohair@286 475 binding.setMTOMEnabled(true);
ohair@286 476 }else if (bindingId.isMTOMEnabled() != null && bindingId.isMTOMEnabled() == Boolean.FALSE){
ohair@286 477 //TODO: i18N
ohair@286 478 throw new ServerRtException("Deployment failed! Mtom policy assertion in WSDL is enabled whereas the deplyment descriptor setting wants to disable it!");
ohair@286 479 }
ohair@286 480 }
ohair@286 481 }
ohair@286 482 */
ohair@286 483 /**
ohair@286 484 * If service name is not already set via DD or programmatically, it uses
ohair@286 485 * annotations {@link WebServiceProvider}, {@link WebService} on implementorClass to get PortName.
ohair@286 486 *
ohair@286 487 * @return non-null service name
ohair@286 488 */
ohair@286 489 public static @NotNull QName getDefaultServiceName(Class<?> implType) {
alanb@368 490 return getDefaultServiceName(implType, null);
alanb@368 491 }
alanb@368 492
alanb@368 493 public static @NotNull QName getDefaultServiceName(Class<?> implType, MetadataReader metadataReader) {
alanb@368 494 return getDefaultServiceName(implType, true, metadataReader);
ohair@286 495 }
ohair@286 496
ohair@286 497 public static @NotNull QName getDefaultServiceName(Class<?> implType, boolean isStandard) {
alanb@368 498 return getDefaultServiceName(implType, isStandard, null);
alanb@368 499 }
alanb@368 500
alanb@368 501 public static @NotNull QName getDefaultServiceName(Class<?> implType, boolean isStandard, MetadataReader metadataReader) {
alanb@368 502 if (metadataReader == null) {
alanb@368 503 metadataReader = new ReflectAnnotationReader();
alanb@368 504 }
ohair@286 505 QName serviceName;
alanb@368 506 WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, implType);
ohair@286 507 if (wsProvider!=null) {
ohair@286 508 String tns = wsProvider.targetNamespace();
ohair@286 509 String local = wsProvider.serviceName();
ohair@286 510 serviceName = new QName(tns, local);
ohair@286 511 } else {
alanb@368 512 serviceName = RuntimeModeler.getServiceName(implType, metadataReader, isStandard);
ohair@286 513 }
ohair@286 514 assert serviceName != null;
ohair@286 515 return serviceName;
ohair@286 516 }
ohair@286 517
ohair@286 518 /**
ohair@286 519 * If portName is not already set via DD or programmatically, it uses
ohair@286 520 * annotations on implementorClass to get PortName.
ohair@286 521 *
ohair@286 522 * @return non-null port name
ohair@286 523 */
ohair@286 524 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType) {
alanb@368 525 return getDefaultPortName(serviceName, implType, null);
alanb@368 526 }
alanb@368 527
alanb@368 528 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, MetadataReader metadataReader) {
alanb@368 529 return getDefaultPortName(serviceName, implType, true, metadataReader);
ohair@286 530 }
ohair@286 531
ohair@286 532 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, boolean isStandard) {
alanb@368 533 return getDefaultPortName(serviceName, implType, isStandard, null);
alanb@368 534 }
alanb@368 535
alanb@368 536 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, boolean isStandard, MetadataReader metadataReader) {
alanb@368 537 if (metadataReader == null) {
alanb@368 538 metadataReader = new ReflectAnnotationReader();
alanb@368 539 }
ohair@286 540 QName portName;
alanb@368 541 WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, implType);
ohair@286 542 if (wsProvider!=null) {
ohair@286 543 String tns = wsProvider.targetNamespace();
ohair@286 544 String local = wsProvider.portName();
ohair@286 545 portName = new QName(tns, local);
ohair@286 546 } else {
alanb@368 547 portName = RuntimeModeler.getPortName(implType, metadataReader, serviceName.getNamespaceURI(), isStandard);
ohair@286 548 }
ohair@286 549 assert portName != null;
ohair@286 550 return portName;
ohair@286 551 }
ohair@286 552
ohair@286 553 /**
ohair@286 554 * Returns the wsdl from @WebService, or @WebServiceProvider annotation using
ohair@286 555 * wsdlLocation element.
ohair@286 556 *
ohair@286 557 * @param implType
ohair@286 558 * endpoint implementation class
ohair@286 559 * make sure that you called {@link #verifyImplementorClass} on it.
ohair@286 560 * @return wsdl if there is wsdlLocation, else null
ohair@286 561 */
ohair@286 562 public static @Nullable String getWsdlLocation(Class<?> implType) {
alanb@368 563 return getWsdlLocation(implType, new ReflectAnnotationReader());
alanb@368 564 }
alanb@368 565
alanb@368 566 /**
alanb@368 567 * Returns the wsdl from @WebService, or @WebServiceProvider annotation using
alanb@368 568 * wsdlLocation element.
alanb@368 569 *
alanb@368 570 * @param implType
alanb@368 571 * endpoint implementation class
alanb@368 572 * make sure that you called {@link #verifyImplementorClass} on it.
alanb@368 573 * @return wsdl if there is wsdlLocation, else null
alanb@368 574 */
alanb@368 575 public static @Nullable String getWsdlLocation(Class<?> implType, MetadataReader metadataReader) {
alanb@368 576
alanb@368 577 if (metadataReader == null) {
alanb@368 578 metadataReader = new ReflectAnnotationReader();
alanb@368 579 }
alanb@368 580
alanb@368 581 WebService ws = metadataReader.getAnnotation(WebService.class, implType);
ohair@286 582 if (ws != null) {
alanb@368 583 return nullIfEmpty(ws.wsdlLocation());
ohair@286 584 } else {
ohair@286 585 WebServiceProvider wsProvider = implType.getAnnotation(WebServiceProvider.class);
ohair@286 586 assert wsProvider != null;
alanb@368 587 return nullIfEmpty(wsProvider.wsdlLocation());
ohair@286 588 }
alanb@368 589 }
alanb@368 590
alanb@368 591 private static String nullIfEmpty(String string) {
alanb@368 592 if (string.length() < 1) {
alanb@368 593 string = null;
ohair@286 594 }
alanb@368 595 return string;
ohair@286 596 }
ohair@286 597
ohair@286 598 /**
ohair@286 599 * Generates the WSDL and XML Schema for the endpoint if necessary
ohair@286 600 * It generates WSDL only for SOAP1.1, and for XSOAP1.2 bindings
ohair@286 601 */
ohair@286 602 private static SDDocumentImpl generateWSDL(WSBinding binding, AbstractSEIModelImpl seiModel, List<SDDocumentImpl> docs,
ohair@286 603 Container container, Class implType) {
ohair@286 604 BindingID bindingId = binding.getBindingId();
ohair@286 605 if (!bindingId.canGenerateWSDL()) {
ohair@286 606 throw new ServerRtException("can.not.generate.wsdl", bindingId);
ohair@286 607 }
ohair@286 608
ohair@286 609 if (bindingId.toString().equals(SOAPBindingImpl.X_SOAP12HTTP_BINDING)) {
ohair@286 610 String msg = ServerMessages.GENERATE_NON_STANDARD_WSDL();
ohair@286 611 logger.warning(msg);
ohair@286 612 }
ohair@286 613
ohair@286 614 // Generate WSDL and schema documents using runtime model
ohair@286 615 WSDLGenResolver wsdlResolver = new WSDLGenResolver(docs,seiModel.getServiceQName(),seiModel.getPortTypeName());
ohair@286 616 WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
ohair@286 617 wsdlGenInfo.setWsdlResolver(wsdlResolver);
ohair@286 618 wsdlGenInfo.setContainer(container);
ohair@286 619 wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
ohair@286 620 wsdlGenInfo.setInlineSchemas(false);
alanb@368 621 wsdlGenInfo.setSecureXmlProcessingDisabled(isSecureXmlProcessingDisabled(binding.getFeatures()));
ohair@286 622 seiModel.getDatabinding().generateWSDL(wsdlGenInfo);
ohair@286 623 // WSDLGenerator wsdlGen = new WSDLGenerator(seiModel, wsdlResolver, binding, container, implType, false,
ohair@286 624 // ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
ohair@286 625 // wsdlGen.doGeneration();
ohair@286 626 return wsdlResolver.updateDocs();
ohair@286 627 }
ohair@286 628
alanb@368 629 private static boolean isSecureXmlProcessingDisabled(WSFeatureList featureList) {
alanb@368 630 // TODO-Miran: would it be necessary to disable secure xml processing?
alanb@368 631 return false;
alanb@368 632 }
alanb@368 633
ohair@286 634 /**
ohair@286 635 * Builds {@link SDDocumentImpl} from {@link SDDocumentSource}.
ohair@286 636 */
ohair@286 637 private static List<SDDocumentImpl> categoriseMetadata(
ohair@286 638 List<SDDocumentSource> src, QName serviceName, QName portTypeName) {
ohair@286 639
ohair@286 640 List<SDDocumentImpl> r = new ArrayList<SDDocumentImpl>(src.size());
ohair@286 641 for (SDDocumentSource doc : src) {
ohair@286 642 r.add(SDDocumentImpl.create(doc,serviceName,portTypeName));
ohair@286 643 }
ohair@286 644 return r;
ohair@286 645 }
ohair@286 646
ohair@286 647 /**
ohair@286 648 * Verifies whether the given primaryWsdl contains the given serviceName.
ohair@286 649 * If the WSDL doesn't have the service, it throws an WebServiceException.
ohair@286 650 */
ohair@286 651 private static void verifyPrimaryWSDL(@NotNull SDDocumentSource primaryWsdl, @NotNull QName serviceName) {
ohair@286 652 SDDocumentImpl primaryDoc = SDDocumentImpl.create(primaryWsdl,serviceName,null);
ohair@286 653 if (!(primaryDoc instanceof SDDocument.WSDL)) {
ohair@286 654 throw new WebServiceException(primaryWsdl.getSystemId()+
ohair@286 655 " is not a WSDL. But it is passed as a primary WSDL");
ohair@286 656 }
ohair@286 657 SDDocument.WSDL wsdlDoc = (SDDocument.WSDL)primaryDoc;
ohair@286 658 if (!wsdlDoc.hasService()) {
ohair@286 659 if(wsdlDoc.getAllServices().isEmpty())
ohair@286 660 throw new WebServiceException("Not a primary WSDL="+primaryWsdl.getSystemId()+
ohair@286 661 " since it doesn't have Service "+serviceName);
ohair@286 662 else
ohair@286 663 throw new WebServiceException("WSDL "+primaryDoc.getSystemId()
ohair@286 664 +" has the following services "+wsdlDoc.getAllServices()
ohair@286 665 +" but not "+serviceName+". Maybe you forgot to specify a serviceName and/or targetNamespace in @WebService/@WebServiceProvider?");
ohair@286 666 }
ohair@286 667 }
ohair@286 668
ohair@286 669 /**
ohair@286 670 * Finds the primary WSDL document from the list of metadata documents. If
ohair@286 671 * there are two metadata documents that qualify for primary, it throws an
ohair@286 672 * exception. If there are two metadata documents that qualify for porttype,
ohair@286 673 * it throws an exception.
ohair@286 674 *
ohair@286 675 * @return primay wsdl document, null if is not there in the docList
ohair@286 676 *
ohair@286 677 */
ohair@286 678 private static @Nullable SDDocumentImpl findPrimary(@NotNull List<SDDocumentImpl> docList) {
ohair@286 679 SDDocumentImpl primaryDoc = null;
ohair@286 680 boolean foundConcrete = false;
ohair@286 681 boolean foundAbstract = false;
ohair@286 682 for(SDDocumentImpl doc : docList) {
ohair@286 683 if (doc instanceof SDDocument.WSDL) {
ohair@286 684 SDDocument.WSDL wsdlDoc = (SDDocument.WSDL)doc;
ohair@286 685 if (wsdlDoc.hasService()) {
ohair@286 686 primaryDoc = doc;
ohair@286 687 if (foundConcrete) {
ohair@286 688 throw new ServerRtException("duplicate.primary.wsdl", doc.getSystemId() );
ohair@286 689 }
ohair@286 690 foundConcrete = true;
ohair@286 691 }
ohair@286 692 if (wsdlDoc.hasPortType()) {
ohair@286 693 if (foundAbstract) {
ohair@286 694 throw new ServerRtException("duplicate.abstract.wsdl", doc.getSystemId());
ohair@286 695 }
ohair@286 696 foundAbstract = true;
ohair@286 697 }
ohair@286 698 }
ohair@286 699 }
ohair@286 700 return primaryDoc;
ohair@286 701 }
ohair@286 702
ohair@286 703 /**
ohair@286 704 * Parses the primary WSDL and returns the {@link WSDLPort} for the given service and port names
ohair@286 705 *
ohair@286 706 * @param primaryWsdl Primary WSDL
ohair@286 707 * @param metadata it may contain imported WSDL and schema documents
ohair@286 708 * @param serviceName service name in wsdl
ohair@286 709 * @param portName port name in WSDL
ohair@286 710 * @param container container in which this service is running
ohair@286 711 * @return non-null wsdl port object
ohair@286 712 */
mkos@408 713 private static @NotNull WSDLPort getWSDLPort(SDDocumentSource primaryWsdl, List<? extends SDDocumentSource> metadata,
alanb@368 714 @NotNull QName serviceName, @NotNull QName portName, Container container,
alanb@368 715 EntityResolver resolver) {
ohair@286 716 URL wsdlUrl = primaryWsdl.getSystemId();
ohair@286 717 try {
ohair@286 718 // TODO: delegate to another entity resolver
mkos@408 719 WSDLModel wsdlDoc = RuntimeWSDLParser.parse(
alanb@368 720 new Parser(primaryWsdl), new EntityResolverImpl(metadata, resolver),
ohair@286 721 false, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
ohair@286 722 if(wsdlDoc.getServices().size() == 0) {
ohair@286 723 throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_NOSERVICE_IN_WSDLMODEL(wsdlUrl));
ohair@286 724 }
mkos@408 725 WSDLService wsdlService = wsdlDoc.getService(serviceName);
ohair@286 726 if (wsdlService == null) {
ohair@286 727 throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICE(serviceName,wsdlUrl));
ohair@286 728 }
mkos@408 729 WSDLPort wsdlPort = wsdlService.get(portName);
ohair@286 730 if (wsdlPort == null) {
ohair@286 731 throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICEPORT(serviceName, portName, wsdlUrl));
ohair@286 732 }
ohair@286 733 return wsdlPort;
ohair@286 734 } catch (IOException e) {
ohair@286 735 throw new ServerRtException("runtime.parser.wsdl", wsdlUrl,e);
ohair@286 736 } catch (XMLStreamException e) {
ohair@286 737 throw new ServerRtException("runtime.saxparser.exception", e.getMessage(), e.getLocation(), e);
ohair@286 738 } catch (SAXException e) {
ohair@286 739 throw new ServerRtException("runtime.parser.wsdl", wsdlUrl,e);
ohair@286 740 } catch (ServiceConfigurationError e) {
ohair@286 741 throw new ServerRtException("runtime.parser.wsdl", wsdlUrl,e);
ohair@286 742 }
ohair@286 743 }
ohair@286 744
ohair@286 745 /**
ohair@286 746 * {@link XMLEntityResolver} that can resolve to {@link SDDocumentSource}s.
ohair@286 747 */
ohair@286 748 private static final class EntityResolverImpl implements XMLEntityResolver {
ohair@286 749 private Map<String,SDDocumentSource> metadata = new HashMap<String,SDDocumentSource>();
alanb@368 750 private EntityResolver resolver;
ohair@286 751
alanb@368 752 public EntityResolverImpl(List<? extends SDDocumentSource> metadata, EntityResolver resolver) {
ohair@286 753 for (SDDocumentSource doc : metadata) {
ohair@286 754 this.metadata.put(doc.getSystemId().toExternalForm(),doc);
ohair@286 755 }
alanb@368 756 this.resolver = resolver;
ohair@286 757 }
ohair@286 758
ohair@286 759 public Parser resolveEntity (String publicId, String systemId) throws IOException, XMLStreamException {
ohair@286 760 if (systemId != null) {
ohair@286 761 SDDocumentSource doc = metadata.get(systemId);
ohair@286 762 if (doc != null)
ohair@286 763 return new Parser(doc);
ohair@286 764 }
alanb@368 765 if (resolver != null) {
alanb@368 766 try {
alanb@368 767 InputSource source = resolver.resolveEntity(publicId, systemId);
alanb@368 768 if (source != null) {
alanb@368 769 Parser p = new Parser(null, XMLStreamReaderFactory.create(source, true));
alanb@368 770 return p;
alanb@368 771 }
alanb@368 772 } catch (SAXException e) {
alanb@368 773 throw new XMLStreamException(e);
alanb@368 774 }
alanb@368 775 }
ohair@286 776 return null;
ohair@286 777 }
ohair@286 778
ohair@286 779 }
ohair@286 780
ohair@286 781 private static final Logger logger = Logger.getLogger(
ohair@286 782 com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".server.endpoint");
ohair@286 783 }

mercurial