/** * Verifies if the endpoint implementor class has @WebService or @WebServiceProvider * annotation * * @return * true if it is a Provider or AsyncProvider endpoint * false otherwise * @throws java.lang.IllegalArgumentException * If it doesn't have any one of @WebService or @WebServiceProvider * If it has both @WebService and @WebServiceProvider annotations */ public static boolean verifyImplementorClass(Class<?> clz) { WebServiceProvider wsProvider = clz.getAnnotation(WebServiceProvider.class); WebService ws = clz.getAnnotation(WebService.class); if (wsProvider == null && ws == null) { throw new IllegalArgumentException(clz +" has neither @WebService nor @WebServiceProvider annotation"); } if (wsProvider != null && ws != null) { throw new IllegalArgumentException(clz +" has both @WebService and @WebServiceProvider annotations"); } if (wsProvider != null) { if (Provider.class.isAssignableFrom(clz) || AsyncProvider.class.isAssignableFrom(clz)) { return true; } throw new IllegalArgumentException(clz +" doesn't implement Provider or AsyncProvider interface"); } return false; }
public static String getName(final Class<?> clazz) { final WebService webService = clazz.getAnnotation(WebService.class); if (webService != null) { final String sei = webService.endpointInterface(); if (sei != null && sei.trim().length() != 0) { try { final Class seiClass = clazz.getClassLoader().loadClass(sei.trim()); return getNameFromInterface(seiClass); } catch (final ClassNotFoundException e) { throw new OpenEJBRuntimeException("Unable to load SEI class: " + sei, e); } } return getName(clazz, webService.name()); } final WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class); if (webServiceProvider != null) { return clazz.getName(); } throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated"); }
/** * Publish all {@link javax.jws.WebService} annotated beans in the * containing BeanFactory. * @see #publishEndpoint */ public void publishEndpoints() { Set<String> beanNames = new LinkedHashSet<String>(this.beanFactory.getBeanDefinitionCount()); beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames())); if (this.beanFactory instanceof ConfigurableBeanFactory) { beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames())); } for (String beanName : beanNames) { try { Class<?> type = this.beanFactory.getType(beanName); if (type != null && !type.isInterface()) { WebService wsAnnotation = type.getAnnotation(WebService.class); WebServiceProvider wsProviderAnnotation = type.getAnnotation(WebServiceProvider.class); if (wsAnnotation != null || wsProviderAnnotation != null) { Endpoint endpoint = createEndpoint(this.beanFactory.getBean(beanName)); if (this.endpointProperties != null) { endpoint.setProperties(this.endpointProperties); } if (this.executor != null) { endpoint.setExecutor(this.executor); } if (wsAnnotation != null) { publishEndpoint(endpoint, wsAnnotation); } else { publishEndpoint(endpoint, wsProviderAnnotation); } this.publishedEndpoints.add(endpoint); } } } catch (CannotLoadBeanClassException ex) { // ignore beans where the class is not resolvable } } }
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (context.getRound() != 1) { return true; } context.incrementRound(); WebService webService; WebServiceProvider webServiceProvider; WebServiceVisitor webServiceVisitor = new WebServiceWrapperGenerator(this, context); boolean processedEndpoint = false; Collection<TypeElement> classes = new ArrayList<TypeElement>(); filterClasses(classes, roundEnv.getRootElements()); for (TypeElement element : classes) { webServiceProvider = element.getAnnotation(WebServiceProvider.class); webService = element.getAnnotation(WebService.class); if (webServiceProvider != null) { if (webService != null) { processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_AND_WEBSERVICEPROVIDER(element.getQualifiedName())); } processedEndpoint = true; } if (webService == null) { continue; } element.accept(webServiceVisitor, null); processedEndpoint = true; } if (!processedEndpoint) { if (isCommandLineInvocation) { if (!ignoreNoWebServiceFoundWarning) { processWarning(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND()); } } else { processError(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND()); } } return true; }
/** * This method will be used to attach @WebServiceProvider annotation data to the * <code>DescriptionBuilderComposite</code> * * @param composite - <code>DescriptionBuildercomposite</code> */ private void attachWebServiceProviderAnnotation(DescriptionBuilderComposite composite) { WebServiceProvider webServiceProvider = (WebServiceProvider)ConverterUtils. getAnnotation(WebServiceProvider.class, serviceClass); if (webServiceProvider != null) { // Attach @WebServiceProvider annotation data WebServiceProviderAnnot wspAnnot = WebServiceProviderAnnot. createWebServiceAnnotImpl(); wspAnnot.setPortName(webServiceProvider.portName()); wspAnnot.setServiceName(webServiceProvider.serviceName()); wspAnnot.setTargetNamespace(webServiceProvider.targetNamespace()); wspAnnot.setWsdlLocation(webServiceProvider.wsdlLocation()); composite.setWebServiceProviderAnnot(wspAnnot); } }
private void buildModel() { WebService webService; WebServiceProvider webServiceProvider; WebServiceVisitor wrapperGenerator = createWrapperGenerator(); boolean processedEndpoint = false; for (TypeDeclaration typedecl: apEnv.getTypeDeclarations()) { if (!(typedecl instanceof ClassDeclaration)) continue; webServiceProvider = typedecl.getAnnotation(WebServiceProvider.class); webService = typedecl.getAnnotation(WebService.class); if (webServiceProvider != null) { if (webService != null) { onError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_AND_WEBSERVICEPROVIDER(typedecl.getQualifiedName())); } processedEndpoint = true; } if (!shouldProcessWebService(webService)) continue; typedecl.accept(wrapperGenerator); processedEndpoint = true; } if (!processedEndpoint) { if (isAPTInvocation) onWarning(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND()); else onError(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND()); } }
public static QName getServiceQName(final Class<?> clazz) { final WebService webService = clazz.getAnnotation(WebService.class); if (webService != null) { return getServiceQName(clazz, webService.targetNamespace(), webService.serviceName()); } final WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class); if (webServiceProvider != null) { return getServiceQName(clazz, webServiceProvider.targetNamespace(), webServiceProvider.serviceName()); } final WebServiceClient webServiceClient = clazz.getAnnotation(WebServiceClient.class); if (webServiceClient != null) { return getServiceQName(clazz, webServiceClient.targetNamespace(), webServiceClient.name()); } throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated"); }
public static QName getPortQName(final Class<?> clazz) { final WebService webService = clazz.getAnnotation(WebService.class); if (webService != null) { return getPortQName(clazz, webService.targetNamespace(), webService.name(), webService.portName()); } final WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class); if (webServiceProvider != null) { return getPortQName(clazz, webServiceProvider.targetNamespace(), null, webServiceProvider.portName()); } throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated"); }
@Override protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) { endpoint.publish(buildHttpContext(endpoint, annotation.serviceName())); }
@Override protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) { endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName())); }
protected boolean isUseProviderTube(Class<?> implType, boolean isStandard) { return !isStandard || implType.getAnnotation(WebServiceProvider.class)!=null; }
public static boolean hasWebServiceAnnotation(Class<?> cls) { return hasAnnotation(cls, WebService.class) || hasAnnotation(cls, WebServiceProvider.class); }
protected DDEndpoint createDDEndpoint(Class<?> sepClass, ArchiveDeployment dep, Endpoint ep) { WebService anWebService = sepClass.getAnnotation(WebService.class); WebServiceProvider anWebServiceProvider = sepClass.getAnnotation(WebServiceProvider.class); Class<?> seiClass = null; String seiName; String name = (anWebService != null) ? anWebService.name() : ""; if (name.length() == 0) name = JavaUtils.getJustClassName(sepClass); String serviceName = (anWebService != null) ? anWebService.serviceName() : anWebServiceProvider.serviceName(); if (serviceName.length() == 0) { serviceName = JavaUtils.getJustClassName(sepClass) + "Service"; } String serviceNS = (anWebService != null) ? anWebService.targetNamespace() : anWebServiceProvider.targetNamespace(); if (serviceNS.length() == 0) serviceNS = getTypeNamespace(JavaUtils.getPackageName(sepClass)); String portName = (anWebService != null) ? anWebService.portName() : anWebServiceProvider.portName(); if (portName.length() == 0) { portName = name + "Port"; } String annWsdlLocation; if (anWebService != null && anWebService.endpointInterface().length() > 0) { seiName = anWebService.endpointInterface(); ClassLoader runtimeClassLoader = dep.getClassLoader(); if(null == runtimeClassLoader) throw MESSAGES.runtimeLoaderCannotBeNull(dep); try { seiClass = runtimeClassLoader.loadClass(seiName); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } WebService seiAnnotation = seiClass.getAnnotation(WebService.class); if (seiAnnotation == null) throw MESSAGES.webserviceAnnotationNotFound(seiName); if (seiAnnotation.portName().length() > 0 || seiAnnotation.serviceName().length() > 0 || seiAnnotation.endpointInterface().length() > 0) throw MESSAGES.webserviceAnnotationSEIAttributes(seiName); annWsdlLocation = !"".equals(anWebService.wsdlLocation()) ? anWebService.wsdlLocation() : seiAnnotation.wsdlLocation(); } else { annWsdlLocation = (anWebService != null) ? anWebService.wsdlLocation() : anWebServiceProvider.wsdlLocation(); } DDEndpoint result = new DDEndpoint(); result.setId(ep.getShortName()); result.setAddress(SysPropUtils.expandSystemProperty(ep.getAddress())); result.setImplementor(ep.getTargetBeanName()); result.setMtomEnabled(isMtomEnabled(ep.getTargetBeanClass())); result.setEpClass(seiClass != null ? seiClass : sepClass); result.setPortName(new QName(serviceNS, portName)); result.setServiceName(new QName(serviceNS, serviceName)); if (annWsdlLocation.length() > 0) { result.setAnnotationWsdlLocation(annWsdlLocation); } return result; }
/** * @param cls * @return true if this is a JAX-WS or JAX-WS generated class */ public static final boolean isJAXWSClass(Class cls) { // TODO Processing all of these annotations is very expensive. We need to cache the // result in a static WeakHashMap<Class, Boolean> // Kinds of generated classes: Service, Provider, Impl, Exception, Holder // Or the class is in the jaxws.xml.ws package // Check for Impl WebService wsAnn = (WebService)getAnnotation(cls,WebService.class); if (wsAnn != null) { return true; } // Check for service WebServiceClient wscAnn = (WebServiceClient)getAnnotation(cls,WebServiceClient.class); if (wscAnn != null) { return true; } // Check for provider WebServiceProvider wspAnn = (WebServiceProvider) getAnnotation(cls,WebServiceProvider.class); if (wspAnn != null) { return true; } // Check for Exception WebFault wfAnn = (WebFault)getAnnotation(cls,WebFault.class); if (wfAnn != null) { return true; } // Check for Holder if (Holder.class.isAssignableFrom(cls)) { return true; } // Check for a javax.xml.ws.Service class instance if (Service.class.isAssignableFrom(cls)) { return true; } String className = cls.getPackage() == null ? null : cls.getPackage().getName(); if (className != null && className.startsWith("javax.xml.ws") && !className.startsWith("javax.xml.ws.wsaddressing")) { return true; } return false; }
public WebServiceProvider getAnnoWebServiceProvider() { return webServiceProviderAnnotation; }
boolean isWebService(Object bean) { Class<?> beanClass = bean.getClass(); return beanClass.getAnnotation(WebService.class) != null || beanClass.getAnnotation(WebServiceProvider.class) != null; }
public static boolean isWebService(final Class clazz) { return (clazz.isAnnotationPresent(WebService.class) || clazz.isAnnotationPresent(WebServiceProvider.class)) && isProperWebService(clazz); }
/** * Actually publish the given provider endpoint. To be implemented by subclasses. * @param endpoint the JAX-WS Provider Endpoint object * @param annotation the service bean's WebServiceProvider annotation */ protected abstract void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation);
public WebServiceProvider getAnnoWebServiceProvider();