25 |
25 |
26 package com.sun.xml.internal.ws.server; |
26 package com.sun.xml.internal.ws.server; |
27 |
27 |
28 import com.sun.istack.internal.NotNull; |
28 import com.sun.istack.internal.NotNull; |
29 import com.sun.istack.internal.Nullable; |
29 import com.sun.istack.internal.Nullable; |
|
30 import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer; |
30 import com.sun.xml.internal.ws.api.BindingID; |
31 import com.sun.xml.internal.ws.api.BindingID; |
31 import com.sun.xml.internal.ws.api.WSBinding; |
32 import com.sun.xml.internal.ws.api.WSBinding; |
32 import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory; |
33 import com.sun.xml.internal.ws.api.WSFeatureList; |
33 import com.sun.xml.internal.ws.api.policy.PolicyResolver; |
34 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; |
|
35 import com.sun.xml.internal.ws.api.databinding.DatabindingFactory; |
|
36 import com.sun.xml.internal.ws.api.databinding.MetadataReader; |
34 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo; |
37 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo; |
35 import com.sun.xml.internal.ws.api.databinding.DatabindingFactory; |
|
36 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; |
|
37 import com.sun.xml.internal.ws.api.model.SEIModel; |
38 import com.sun.xml.internal.ws.api.model.SEIModel; |
38 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
39 import com.sun.xml.internal.ws.api.pipe.Tube; |
40 import com.sun.xml.internal.ws.api.policy.PolicyResolver; |
40 import com.sun.xml.internal.ws.api.server.*; |
41 import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory; |
|
42 import com.sun.xml.internal.ws.api.server.AsyncProvider; |
|
43 import com.sun.xml.internal.ws.api.server.Container; |
|
44 import com.sun.xml.internal.ws.api.server.ContainerResolver; |
|
45 import com.sun.xml.internal.ws.api.server.InstanceResolver; |
|
46 import com.sun.xml.internal.ws.api.server.Invoker; |
|
47 import com.sun.xml.internal.ws.api.server.SDDocument; |
|
48 import com.sun.xml.internal.ws.api.server.SDDocumentSource; |
|
49 import com.sun.xml.internal.ws.api.server.WSEndpoint; |
|
50 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory; |
41 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; |
51 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; |
42 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver; |
52 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver; |
43 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver.Parser; |
53 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver.Parser; |
44 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension; |
54 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension; |
45 import com.sun.xml.internal.ws.binding.BindingImpl; |
55 import com.sun.xml.internal.ws.binding.BindingImpl; |
46 import com.sun.xml.internal.ws.binding.SOAPBindingImpl; |
56 import com.sun.xml.internal.ws.binding.SOAPBindingImpl; |
47 import com.sun.xml.internal.ws.binding.WebServiceFeatureList; |
57 import com.sun.xml.internal.ws.binding.WebServiceFeatureList; |
48 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; |
58 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; |
|
59 import com.sun.xml.internal.ws.model.ReflectAnnotationReader; |
49 import com.sun.xml.internal.ws.model.RuntimeModeler; |
60 import com.sun.xml.internal.ws.model.RuntimeModeler; |
50 import com.sun.xml.internal.ws.model.SOAPSEIModel; |
61 import com.sun.xml.internal.ws.model.SOAPSEIModel; |
51 import com.sun.xml.internal.ws.model.wsdl.WSDLModelImpl; |
62 import com.sun.xml.internal.ws.model.wsdl.WSDLModelImpl; |
52 import com.sun.xml.internal.ws.model.wsdl.WSDLPortImpl; |
63 import com.sun.xml.internal.ws.model.wsdl.WSDLPortImpl; |
53 import com.sun.xml.internal.ws.model.wsdl.WSDLServiceImpl; |
64 import com.sun.xml.internal.ws.model.wsdl.WSDLServiceImpl; |
|
65 import com.sun.xml.internal.ws.policy.PolicyMap; |
|
66 import com.sun.xml.internal.ws.policy.jaxws.PolicyUtil; |
54 import com.sun.xml.internal.ws.resources.ServerMessages; |
67 import com.sun.xml.internal.ws.resources.ServerMessages; |
55 import com.sun.xml.internal.ws.server.provider.ProviderInvokerTube; |
68 import com.sun.xml.internal.ws.server.provider.ProviderInvokerTube; |
56 import com.sun.xml.internal.ws.server.sei.SEIInvokerTube; |
69 import com.sun.xml.internal.ws.server.sei.SEIInvokerTube; |
57 import com.sun.xml.internal.ws.util.HandlerAnnotationInfo; |
70 import com.sun.xml.internal.ws.util.HandlerAnnotationInfo; |
58 import com.sun.xml.internal.ws.util.HandlerAnnotationProcessor; |
71 import com.sun.xml.internal.ws.util.HandlerAnnotationProcessor; |
59 import com.sun.xml.internal.ws.util.ServiceConfigurationError; |
72 import com.sun.xml.internal.ws.util.ServiceConfigurationError; |
60 import com.sun.xml.internal.ws.util.ServiceFinder; |
73 import com.sun.xml.internal.ws.util.ServiceFinder; |
|
74 import com.sun.xml.internal.ws.util.xml.XmlUtil; |
61 import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser; |
75 import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser; |
62 import com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator; |
|
63 import com.sun.xml.internal.ws.policy.PolicyMap; |
|
64 import com.sun.xml.internal.ws.policy.jaxws.PolicyUtil; |
|
65 import org.xml.sax.EntityResolver; |
76 import org.xml.sax.EntityResolver; |
|
77 import org.xml.sax.InputSource; |
66 import org.xml.sax.SAXException; |
78 import org.xml.sax.SAXException; |
67 |
79 |
68 import javax.jws.WebService; |
80 import javax.jws.WebService; |
69 import javax.xml.namespace.QName; |
81 import javax.xml.namespace.QName; |
70 import javax.xml.stream.XMLStreamException; |
82 import javax.xml.stream.XMLStreamException; |
|
83 import javax.xml.stream.XMLStreamReader; |
71 import javax.xml.ws.Provider; |
84 import javax.xml.ws.Provider; |
72 import javax.xml.ws.WebServiceException; |
85 import javax.xml.ws.WebServiceException; |
|
86 import javax.xml.ws.WebServiceFeature; |
73 import javax.xml.ws.WebServiceProvider; |
87 import javax.xml.ws.WebServiceProvider; |
74 import javax.xml.ws.WebServiceFeature; |
|
75 import javax.xml.ws.soap.SOAPBinding; |
88 import javax.xml.ws.soap.SOAPBinding; |
76 import java.io.IOException; |
89 import java.io.IOException; |
77 import java.net.URL; |
90 import java.net.URL; |
78 import java.util.ArrayList; |
91 import java.util.ArrayList; |
79 import java.util.Collection; |
92 import java.util.Collection; |
205 verifyPrimaryWSDL(primaryWsdl, serviceName); |
220 verifyPrimaryWSDL(primaryWsdl, serviceName); |
206 } |
221 } |
207 |
222 |
208 QName portTypeName = null; |
223 QName portTypeName = null; |
209 if (isStandard && implType.getAnnotation(WebServiceProvider.class)==null) { |
224 if (isStandard && implType.getAnnotation(WebServiceProvider.class)==null) { |
210 portTypeName = RuntimeModeler.getPortTypeName(implType); |
225 portTypeName = RuntimeModeler.getPortTypeName(implType, metadataReader); |
211 } |
226 } |
212 |
227 |
213 // Categorises the documents as WSDL, Schema etc |
228 // Categorises the documents as WSDL, Schema etc |
214 List<SDDocumentImpl> docList = categoriseMetadata(md, serviceName, portTypeName); |
229 List<SDDocumentImpl> docList = categoriseMetadata(md, serviceName, portTypeName); |
215 // Finds the primary WSDL and makes sure that metadata doesn't have |
230 // Finds the primary WSDL and makes sure that metadata doesn't have |
216 // two concrete or abstract WSDLs |
231 // two concrete or abstract WSDLs |
217 SDDocumentImpl primaryDoc = findPrimary(docList); |
232 SDDocumentImpl primaryDoc = primaryWsdl != null ? SDDocumentImpl.create(primaryWsdl,serviceName,portTypeName) : findPrimary(docList); |
218 |
233 |
219 EndpointAwareTube terminal; |
234 EndpointAwareTube terminal; |
220 WSDLPortImpl wsdlPort = null; |
235 WSDLPortImpl wsdlPort = null; |
221 AbstractSEIModelImpl seiModel = null; |
236 AbstractSEIModelImpl seiModel = null; |
222 // create WSDL model |
237 // create WSDL model |
223 if (primaryDoc != null) { |
238 if (primaryDoc != null) { |
224 wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container); |
239 wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver); |
225 } |
240 } |
226 |
241 |
227 WebServiceFeatureList features=((BindingImpl)binding).getFeatures(); |
242 WebServiceFeatureList features=((BindingImpl)binding).getFeatures(); |
228 if (isStandard) { |
243 if (isStandard) { |
229 features.parseAnnotations(implType); |
244 features.parseAnnotations(implType); |
245 policyMap = PolicyResolverFactory.create().resolve( |
260 policyMap = PolicyResolverFactory.create().resolve( |
246 new PolicyResolver.ServerContext(null, container, implType, false)); |
261 new PolicyResolver.ServerContext(null, container, implType, false)); |
247 configFtrs = PolicyUtil.getPortScopedFeatures(policyMap,serviceName,portName); |
262 configFtrs = PolicyUtil.getPortScopedFeatures(policyMap,serviceName,portName); |
248 } |
263 } |
249 features.mergeFeatures(configFtrs, true); |
264 features.mergeFeatures(configFtrs, true); |
250 terminal = createProviderInvokerTube(implType,binding,invoker); |
265 terminal = createProviderInvokerTube(implType, binding, invoker, container); |
251 } else { |
266 } else { |
252 // Create runtime model for non Provider endpoints |
267 // Create runtime model for non Provider endpoints |
253 seiModel = createSEIModel(wsdlPort, implType, serviceName, portName, binding); |
268 seiModel = createSEIModel(wsdlPort, implType, serviceName, portName, binding); |
254 if(binding instanceof SOAPBindingImpl){ |
269 if(binding instanceof SOAPBindingImpl){ |
255 //set portKnownHeaders on Binding, so that they can be used for MU processing |
270 //set portKnownHeaders on Binding, so that they can be used for MU processing |
275 if (processHandlerAnnotation) { |
290 if (processHandlerAnnotation) { |
276 processHandlerAnnotation(binding, implType, serviceName, portName); |
291 processHandlerAnnotation(binding, implType, serviceName, portName); |
277 } |
292 } |
278 // Selects only required metadata for this endpoint from the passed-in metadata |
293 // Selects only required metadata for this endpoint from the passed-in metadata |
279 if (primaryDoc != null) { |
294 if (primaryDoc != null) { |
280 docList = findMetadataClosure(primaryDoc, docList); |
295 docList = findMetadataClosure(primaryDoc, docList, resolver); |
281 } |
296 } |
|
297 |
282 ServiceDefinitionImpl serviceDefiniton = (primaryDoc != null) ? new ServiceDefinitionImpl(docList, primaryDoc) : null; |
298 ServiceDefinitionImpl serviceDefiniton = (primaryDoc != null) ? new ServiceDefinitionImpl(docList, primaryDoc) : null; |
283 |
299 |
284 return create(serviceName, portName, binding, container, seiModel, wsdlPort, implType, serviceDefiniton, |
300 return create(serviceName, portName, binding, container, seiModel, wsdlPort, implType, serviceDefiniton, |
285 terminal, isTransportSynchronous, policyMap); |
301 terminal, isTransportSynchronous, policyMap); |
286 } |
302 } |
296 |
312 |
297 protected EndpointAwareTube createSEIInvokerTube(AbstractSEIModelImpl seiModel, Invoker invoker, WSBinding binding) { |
313 protected EndpointAwareTube createSEIInvokerTube(AbstractSEIModelImpl seiModel, Invoker invoker, WSBinding binding) { |
298 return new SEIInvokerTube(seiModel,invoker,binding); |
314 return new SEIInvokerTube(seiModel,invoker,binding); |
299 } |
315 } |
300 |
316 |
301 protected <T> EndpointAwareTube createProviderInvokerTube(Class<T> implType, WSBinding binding, Invoker invoker) { |
317 protected <T> EndpointAwareTube createProviderInvokerTube(final Class<T> implType, final WSBinding binding, |
302 return ProviderInvokerTube.create(implType, binding, invoker); |
318 final Invoker invoker, final Container container) { |
303 } |
319 return ProviderInvokerTube.create(implType, binding, invoker, container); |
304 |
320 } |
305 /** |
321 /** |
306 * Goes through the original metadata documents and collects the required ones. |
322 * Goes through the original metadata documents and collects the required ones. |
307 * This done traversing from primary WSDL and its imports until it builds a |
323 * This done traversing from primary WSDL and its imports until it builds a |
308 * complete set of documents(transitive closure) for the endpoint. |
324 * complete set of documents(transitive closure) for the endpoint. |
309 * |
325 * |
310 * @param primaryDoc primary WSDL doc |
326 * @param primaryDoc primary WSDL doc |
311 * @param docList complete metadata |
327 * @param docList complete metadata |
312 * @return new metadata that doesn't contain extraneous documnets. |
328 * @return new metadata that doesn't contain extraneous documnets. |
313 */ |
329 */ |
314 private static List<SDDocumentImpl> findMetadataClosure(SDDocumentImpl primaryDoc, List<SDDocumentImpl> docList) { |
330 private static List<SDDocumentImpl> findMetadataClosure(SDDocumentImpl primaryDoc, List<SDDocumentImpl> docList, EntityResolver resolver) { |
315 // create a map for old metadata |
331 // create a map for old metadata |
316 Map<String, SDDocumentImpl> oldMap = new HashMap<String, SDDocumentImpl>(); |
332 Map<String, SDDocumentImpl> oldMap = new HashMap<String, SDDocumentImpl>(); |
317 for(SDDocumentImpl doc : docList) { |
333 for(SDDocumentImpl doc : docList) { |
318 oldMap.put(doc.getSystemId().toString(), doc); |
334 oldMap.put(doc.getSystemId().toString(), doc); |
319 } |
335 } |
326 while(!remaining.isEmpty()) { |
342 while(!remaining.isEmpty()) { |
327 String url = remaining.remove(0); |
343 String url = remaining.remove(0); |
328 SDDocumentImpl doc = oldMap.get(url); |
344 SDDocumentImpl doc = oldMap.get(url); |
329 if (doc == null) { |
345 if (doc == null) { |
330 // old metadata doesn't have this imported doc, may be external |
346 // old metadata doesn't have this imported doc, may be external |
331 continue; |
347 if (resolver != null) { |
|
348 try { |
|
349 InputSource source = resolver.resolveEntity(null, url); |
|
350 if (source != null) { |
|
351 MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer(); |
|
352 XMLStreamReader reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(source.getByteStream()); |
|
353 xsb.createFromXMLStreamReader(reader); |
|
354 |
|
355 SDDocumentSource sdocSource = SDDocumentImpl.create(new URL(url), xsb); |
|
356 doc = SDDocumentImpl.create(sdocSource, null, null); |
|
357 } |
|
358 } catch (Exception ex) { |
|
359 ex.printStackTrace(); |
|
360 } |
|
361 } |
332 } |
362 } |
333 // Check if new metadata already contains this doc |
363 // Check if new metadata already contains this doc |
334 if (!newMap.containsKey(url)) { |
364 if (doc != null && !newMap.containsKey(url)) { |
335 newMap.put(url, doc); |
365 newMap.put(url, doc); |
336 remaining.addAll(doc.getImports()); |
366 remaining.addAll(doc.getImports()); |
337 } |
367 } |
338 } |
368 } |
339 List<SDDocumentImpl> newMetadata = new ArrayList<SDDocumentImpl>(); |
369 List<SDDocumentImpl> newMetadata = new ArrayList<SDDocumentImpl>(); |
364 * @throws java.lang.IllegalArgumentException |
394 * @throws java.lang.IllegalArgumentException |
365 * If it doesn't have any one of @WebService or @WebServiceProvider |
395 * If it doesn't have any one of @WebService or @WebServiceProvider |
366 * If it has both @WebService and @WebServiceProvider annotations |
396 * If it has both @WebService and @WebServiceProvider annotations |
367 */ |
397 */ |
368 public static boolean verifyImplementorClass(Class<?> clz) { |
398 public static boolean verifyImplementorClass(Class<?> clz) { |
369 WebServiceProvider wsProvider = clz.getAnnotation(WebServiceProvider.class); |
399 return verifyImplementorClass(clz, null); |
370 WebService ws = clz.getAnnotation(WebService.class); |
400 } |
|
401 |
|
402 /** |
|
403 * Verifies if the endpoint implementor class has @WebService or @WebServiceProvider |
|
404 * annotation; passing MetadataReader instance allows to read annotations from |
|
405 * xml descriptor instead of class's annotations |
|
406 * |
|
407 * @return |
|
408 * true if it is a Provider or AsyncProvider endpoint |
|
409 * false otherwise |
|
410 * @throws java.lang.IllegalArgumentException |
|
411 * If it doesn't have any one of @WebService or @WebServiceProvider |
|
412 * If it has both @WebService and @WebServiceProvider annotations |
|
413 */ |
|
414 public static boolean verifyImplementorClass(Class<?> clz, MetadataReader metadataReader) { |
|
415 |
|
416 if (metadataReader == null) { |
|
417 metadataReader = new ReflectAnnotationReader(); |
|
418 } |
|
419 |
|
420 WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, clz); |
|
421 WebService ws = metadataReader.getAnnotation(WebService.class, clz); |
371 if (wsProvider == null && ws == null) { |
422 if (wsProvider == null && ws == null) { |
372 throw new IllegalArgumentException(clz +" has neither @WebService nor @WebServiceProvider annotation"); |
423 throw new IllegalArgumentException(clz +" has neither @WebService nor @WebServiceProvider annotation"); |
373 } |
424 } |
374 if (wsProvider != null && ws != null) { |
425 if (wsProvider != null && ws != null) { |
375 throw new IllegalArgumentException(clz +" has both @WebService and @WebServiceProvider annotations"); |
426 throw new IllegalArgumentException(clz +" has both @WebService and @WebServiceProvider annotations"); |
413 config.setWSBinding(binding); |
464 config.setWSBinding(binding); |
414 // config.setFeatures(binding.getFeatures().toArray()); |
465 // config.setFeatures(binding.getFeatures().toArray()); |
415 // config.getMappingInfo().setBindingID(binding.getBindingId()); |
466 // config.getMappingInfo().setBindingID(binding.getBindingId()); |
416 config.setClassLoader(implType.getClassLoader()); |
467 config.setClassLoader(implType.getClassLoader()); |
417 config.getMappingInfo().setPortName(portName); |
468 config.getMappingInfo().setPortName(portName); |
|
469 |
|
470 config.setMetadataReader(getExternalMetadatReader(implType, binding)); |
|
471 |
418 com.sun.xml.internal.ws.db.DatabindingImpl rt = (com.sun.xml.internal.ws.db.DatabindingImpl)fac.createRuntime(config); |
472 com.sun.xml.internal.ws.db.DatabindingImpl rt = (com.sun.xml.internal.ws.db.DatabindingImpl)fac.createRuntime(config); |
419 return (AbstractSEIModelImpl) rt.getModel(); |
473 return (AbstractSEIModelImpl) rt.getModel(); |
|
474 } |
|
475 |
|
476 public static MetadataReader getExternalMetadatReader(Class<?> implType, WSBinding binding) { |
|
477 com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature ef = binding.getFeature( |
|
478 com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature.class); |
|
479 // TODO-Miran: would it be necessary to disable secure xml processing? |
|
480 if (ef != null) |
|
481 return ef.getMetadataReader(implType.getClassLoader(), false); |
|
482 return null; |
420 } |
483 } |
421 |
484 |
422 /** |
485 /** |
423 *Set the mtom enable setting from wsdl model (mtom policy assertion) on to @link WSBinding} if DD has |
486 *Set the mtom enable setting from wsdl model (mtom policy assertion) on to @link WSBinding} if DD has |
424 * not already set it on BindingID. Also check conflicts. |
487 * not already set it on BindingID. Also check conflicts. |
441 * annotations {@link WebServiceProvider}, {@link WebService} on implementorClass to get PortName. |
504 * annotations {@link WebServiceProvider}, {@link WebService} on implementorClass to get PortName. |
442 * |
505 * |
443 * @return non-null service name |
506 * @return non-null service name |
444 */ |
507 */ |
445 public static @NotNull QName getDefaultServiceName(Class<?> implType) { |
508 public static @NotNull QName getDefaultServiceName(Class<?> implType) { |
446 return getDefaultServiceName(implType, true); |
509 return getDefaultServiceName(implType, null); |
|
510 } |
|
511 |
|
512 public static @NotNull QName getDefaultServiceName(Class<?> implType, MetadataReader metadataReader) { |
|
513 return getDefaultServiceName(implType, true, metadataReader); |
447 } |
514 } |
448 |
515 |
449 public static @NotNull QName getDefaultServiceName(Class<?> implType, boolean isStandard) { |
516 public static @NotNull QName getDefaultServiceName(Class<?> implType, boolean isStandard) { |
|
517 return getDefaultServiceName(implType, isStandard, null); |
|
518 } |
|
519 |
|
520 public static @NotNull QName getDefaultServiceName(Class<?> implType, boolean isStandard, MetadataReader metadataReader) { |
|
521 if (metadataReader == null) { |
|
522 metadataReader = new ReflectAnnotationReader(); |
|
523 } |
450 QName serviceName; |
524 QName serviceName; |
451 WebServiceProvider wsProvider = implType.getAnnotation(WebServiceProvider.class); |
525 WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, implType); |
452 if (wsProvider!=null) { |
526 if (wsProvider!=null) { |
453 String tns = wsProvider.targetNamespace(); |
527 String tns = wsProvider.targetNamespace(); |
454 String local = wsProvider.serviceName(); |
528 String local = wsProvider.serviceName(); |
455 serviceName = new QName(tns, local); |
529 serviceName = new QName(tns, local); |
456 } else { |
530 } else { |
457 serviceName = RuntimeModeler.getServiceName(implType, isStandard); |
531 serviceName = RuntimeModeler.getServiceName(implType, metadataReader, isStandard); |
458 } |
532 } |
459 assert serviceName != null; |
533 assert serviceName != null; |
460 return serviceName; |
534 return serviceName; |
461 } |
535 } |
462 |
536 |
465 * annotations on implementorClass to get PortName. |
539 * annotations on implementorClass to get PortName. |
466 * |
540 * |
467 * @return non-null port name |
541 * @return non-null port name |
468 */ |
542 */ |
469 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType) { |
543 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType) { |
470 return getDefaultPortName(serviceName, implType, true); |
544 return getDefaultPortName(serviceName, implType, null); |
|
545 } |
|
546 |
|
547 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, MetadataReader metadataReader) { |
|
548 return getDefaultPortName(serviceName, implType, true, metadataReader); |
471 } |
549 } |
472 |
550 |
473 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, boolean isStandard) { |
551 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, boolean isStandard) { |
|
552 return getDefaultPortName(serviceName, implType, isStandard, null); |
|
553 } |
|
554 |
|
555 public static @NotNull QName getDefaultPortName(QName serviceName, Class<?> implType, boolean isStandard, MetadataReader metadataReader) { |
|
556 if (metadataReader == null) { |
|
557 metadataReader = new ReflectAnnotationReader(); |
|
558 } |
474 QName portName; |
559 QName portName; |
475 WebServiceProvider wsProvider = implType.getAnnotation(WebServiceProvider.class); |
560 WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, implType); |
476 if (wsProvider!=null) { |
561 if (wsProvider!=null) { |
477 String tns = wsProvider.targetNamespace(); |
562 String tns = wsProvider.targetNamespace(); |
478 String local = wsProvider.portName(); |
563 String local = wsProvider.portName(); |
479 portName = new QName(tns, local); |
564 portName = new QName(tns, local); |
480 } else { |
565 } else { |
481 portName = RuntimeModeler.getPortName(implType, serviceName.getNamespaceURI(), isStandard); |
566 portName = RuntimeModeler.getPortName(implType, metadataReader, serviceName.getNamespaceURI(), isStandard); |
482 } |
567 } |
483 assert portName != null; |
568 assert portName != null; |
484 return portName; |
569 return portName; |
485 } |
570 } |
486 |
571 |
492 * endpoint implementation class |
577 * endpoint implementation class |
493 * make sure that you called {@link #verifyImplementorClass} on it. |
578 * make sure that you called {@link #verifyImplementorClass} on it. |
494 * @return wsdl if there is wsdlLocation, else null |
579 * @return wsdl if there is wsdlLocation, else null |
495 */ |
580 */ |
496 public static @Nullable String getWsdlLocation(Class<?> implType) { |
581 public static @Nullable String getWsdlLocation(Class<?> implType) { |
497 String wsdl; |
582 return getWsdlLocation(implType, new ReflectAnnotationReader()); |
498 WebService ws = implType.getAnnotation(WebService.class); |
583 } |
|
584 |
|
585 /** |
|
586 * Returns the wsdl from @WebService, or @WebServiceProvider annotation using |
|
587 * wsdlLocation element. |
|
588 * |
|
589 * @param implType |
|
590 * endpoint implementation class |
|
591 * make sure that you called {@link #verifyImplementorClass} on it. |
|
592 * @return wsdl if there is wsdlLocation, else null |
|
593 */ |
|
594 public static @Nullable String getWsdlLocation(Class<?> implType, MetadataReader metadataReader) { |
|
595 |
|
596 if (metadataReader == null) { |
|
597 metadataReader = new ReflectAnnotationReader(); |
|
598 } |
|
599 |
|
600 WebService ws = metadataReader.getAnnotation(WebService.class, implType); |
499 if (ws != null) { |
601 if (ws != null) { |
500 wsdl = ws.wsdlLocation(); |
602 return nullIfEmpty(ws.wsdlLocation()); |
501 } else { |
603 } else { |
502 WebServiceProvider wsProvider = implType.getAnnotation(WebServiceProvider.class); |
604 WebServiceProvider wsProvider = implType.getAnnotation(WebServiceProvider.class); |
503 assert wsProvider != null; |
605 assert wsProvider != null; |
504 wsdl = wsProvider.wsdlLocation(); |
606 return nullIfEmpty(wsProvider.wsdlLocation()); |
505 } |
607 } |
506 if (wsdl.length() < 1) { |
608 } |
507 wsdl = null; |
609 |
508 } |
610 private static String nullIfEmpty(String string) { |
509 return wsdl; |
611 if (string.length() < 1) { |
|
612 string = null; |
|
613 } |
|
614 return string; |
510 } |
615 } |
511 |
616 |
512 /** |
617 /** |
513 * Generates the WSDL and XML Schema for the endpoint if necessary |
618 * Generates the WSDL and XML Schema for the endpoint if necessary |
514 * It generates WSDL only for SOAP1.1, and for XSOAP1.2 bindings |
619 * It generates WSDL only for SOAP1.1, and for XSOAP1.2 bindings |
530 WSDLGenInfo wsdlGenInfo = new WSDLGenInfo(); |
635 WSDLGenInfo wsdlGenInfo = new WSDLGenInfo(); |
531 wsdlGenInfo.setWsdlResolver(wsdlResolver); |
636 wsdlGenInfo.setWsdlResolver(wsdlResolver); |
532 wsdlGenInfo.setContainer(container); |
637 wsdlGenInfo.setContainer(container); |
533 wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray()); |
638 wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray()); |
534 wsdlGenInfo.setInlineSchemas(false); |
639 wsdlGenInfo.setInlineSchemas(false); |
|
640 wsdlGenInfo.setSecureXmlProcessingDisabled(isSecureXmlProcessingDisabled(binding.getFeatures())); |
535 seiModel.getDatabinding().generateWSDL(wsdlGenInfo); |
641 seiModel.getDatabinding().generateWSDL(wsdlGenInfo); |
536 // WSDLGenerator wsdlGen = new WSDLGenerator(seiModel, wsdlResolver, binding, container, implType, false, |
642 // WSDLGenerator wsdlGen = new WSDLGenerator(seiModel, wsdlResolver, binding, container, implType, false, |
537 // ServiceFinder.find(WSDLGeneratorExtension.class).toArray()); |
643 // ServiceFinder.find(WSDLGeneratorExtension.class).toArray()); |
538 // wsdlGen.doGeneration(); |
644 // wsdlGen.doGeneration(); |
539 return wsdlResolver.updateDocs(); |
645 return wsdlResolver.updateDocs(); |
|
646 } |
|
647 |
|
648 private static boolean isSecureXmlProcessingDisabled(WSFeatureList featureList) { |
|
649 // TODO-Miran: would it be necessary to disable secure xml processing? |
|
650 return false; |
540 } |
651 } |
541 |
652 |
542 /** |
653 /** |
543 * Builds {@link SDDocumentImpl} from {@link SDDocumentSource}. |
654 * Builds {@link SDDocumentImpl} from {@link SDDocumentSource}. |
544 */ |
655 */ |
617 * @param portName port name in WSDL |
728 * @param portName port name in WSDL |
618 * @param container container in which this service is running |
729 * @param container container in which this service is running |
619 * @return non-null wsdl port object |
730 * @return non-null wsdl port object |
620 */ |
731 */ |
621 private static @NotNull WSDLPortImpl getWSDLPort(SDDocumentSource primaryWsdl, List<? extends SDDocumentSource> metadata, |
732 private static @NotNull WSDLPortImpl getWSDLPort(SDDocumentSource primaryWsdl, List<? extends SDDocumentSource> metadata, |
622 @NotNull QName serviceName, @NotNull QName portName, Container container) { |
733 @NotNull QName serviceName, @NotNull QName portName, Container container, |
|
734 EntityResolver resolver) { |
623 URL wsdlUrl = primaryWsdl.getSystemId(); |
735 URL wsdlUrl = primaryWsdl.getSystemId(); |
624 try { |
736 try { |
625 // TODO: delegate to another entity resolver |
737 // TODO: delegate to another entity resolver |
626 WSDLModelImpl wsdlDoc = RuntimeWSDLParser.parse( |
738 WSDLModelImpl wsdlDoc = RuntimeWSDLParser.parse( |
627 new Parser(primaryWsdl), new EntityResolverImpl(metadata), |
739 new Parser(primaryWsdl), new EntityResolverImpl(metadata, resolver), |
628 false, container, ServiceFinder.find(WSDLParserExtension.class).toArray()); |
740 false, container, ServiceFinder.find(WSDLParserExtension.class).toArray()); |
629 if(wsdlDoc.getServices().size() == 0) { |
741 if(wsdlDoc.getServices().size() == 0) { |
630 throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_NOSERVICE_IN_WSDLMODEL(wsdlUrl)); |
742 throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_NOSERVICE_IN_WSDLMODEL(wsdlUrl)); |
631 } |
743 } |
632 WSDLServiceImpl wsdlService = wsdlDoc.getService(serviceName); |
744 WSDLServiceImpl wsdlService = wsdlDoc.getService(serviceName); |
652 /** |
764 /** |
653 * {@link XMLEntityResolver} that can resolve to {@link SDDocumentSource}s. |
765 * {@link XMLEntityResolver} that can resolve to {@link SDDocumentSource}s. |
654 */ |
766 */ |
655 private static final class EntityResolverImpl implements XMLEntityResolver { |
767 private static final class EntityResolverImpl implements XMLEntityResolver { |
656 private Map<String,SDDocumentSource> metadata = new HashMap<String,SDDocumentSource>(); |
768 private Map<String,SDDocumentSource> metadata = new HashMap<String,SDDocumentSource>(); |
657 |
769 private EntityResolver resolver; |
658 public EntityResolverImpl(List<? extends SDDocumentSource> metadata) { |
770 |
|
771 public EntityResolverImpl(List<? extends SDDocumentSource> metadata, EntityResolver resolver) { |
659 for (SDDocumentSource doc : metadata) { |
772 for (SDDocumentSource doc : metadata) { |
660 this.metadata.put(doc.getSystemId().toExternalForm(),doc); |
773 this.metadata.put(doc.getSystemId().toExternalForm(),doc); |
661 } |
774 } |
|
775 this.resolver = resolver; |
662 } |
776 } |
663 |
777 |
664 public Parser resolveEntity (String publicId, String systemId) throws IOException, XMLStreamException { |
778 public Parser resolveEntity (String publicId, String systemId) throws IOException, XMLStreamException { |
665 if (systemId != null) { |
779 if (systemId != null) { |
666 SDDocumentSource doc = metadata.get(systemId); |
780 SDDocumentSource doc = metadata.get(systemId); |
667 if (doc != null) |
781 if (doc != null) |
668 return new Parser(doc); |
782 return new Parser(doc); |
669 } |
783 } |
|
784 if (resolver != null) { |
|
785 try { |
|
786 InputSource source = resolver.resolveEntity(publicId, systemId); |
|
787 if (source != null) { |
|
788 Parser p = new Parser(null, XMLStreamReaderFactory.create(source, true)); |
|
789 return p; |
|
790 } |
|
791 } catch (SAXException e) { |
|
792 throw new XMLStreamException(e); |
|
793 } |
|
794 } |
670 return null; |
795 return null; |
671 } |
796 } |
672 |
797 |
673 } |
798 } |
674 |
799 |