This is an automated email from the ASF dual-hosted git repository. struberg pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
commit 78050fea75592ee2a312c77cfe18723570fa78fd Author: Mark Struberg <[email protected]> AuthorDate: Tue Jan 24 19:06:32 2023 +0100 OWB-1417 remove webbeans-resources module This was used to 'fake' Java EE @Resource injection. But it was not really working in a portable way anyway. --- webbeans-resource/pom.xml | 78 --------- .../spi/se/StandaloneResourceInjectionService.java | 173 -------------------- .../spi/se/StandaloneResourceProcessor.java | 179 --------------------- .../META-INF/openwebbeans/openwebbeans.properties | 30 ---- webbeans-resource/src/site/site.xml | 47 ------ 5 files changed, 507 deletions(-) diff --git a/webbeans-resource/pom.xml b/webbeans-resource/pom.xml deleted file mode 100644 index be7c9edcc..000000000 --- a/webbeans-resource/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.openwebbeans</groupId> - <artifactId>openwebbeans</artifactId> - <version>4.0.0-SNAPSHOT</version> - </parent> - <artifactId>openwebbeans-resource</artifactId> - <name>EE Resource plugin</name> - <description>Apache OpenWebBeans EE Resource Integration</description> - <dependencies> - - <dependency> - <groupId>org.apache.openwebbeans</groupId> - <artifactId>openwebbeans-impl</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - <optional>true</optional> - </dependency> - - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jcdi_2.0_spec</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-atinject_1.0_spec</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>jakarta.annotation</groupId> - <artifactId>jakarta.annotation-api</artifactId> - <optional>true</optional> - </dependency> - - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jaxws_2.2_spec</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.openwebbeans</groupId> - <artifactId>openwebbeans-spi</artifactId> - <optional>true</optional> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> - - -</project> diff --git a/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java b/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java deleted file mode 100644 index 798309b45..000000000 --- a/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.webbeans.resource.spi.se; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.text.MessageFormat; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import jakarta.annotation.Resource; -import jakarta.enterprise.inject.Produces; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceUnit; -import javax.xml.ws.WebServiceRef; - -import org.apache.webbeans.config.OWBLogConst; -import org.apache.webbeans.config.WebBeansContext; -import org.apache.webbeans.exception.WebBeansException; -import org.apache.webbeans.logger.WebBeansLoggerFacade; -import org.apache.webbeans.spi.ResourceInjectionService; -import org.apache.webbeans.spi.api.ResourceReference; -import org.apache.webbeans.util.AnnotationUtil; - -public class StandaloneResourceInjectionService implements ResourceInjectionService -{ - /** - * When ResourceProxyHandler deserialized, this will instruct owb to create a new actual instance, if - * the actual resource is not serializable. - */ - private static final String DUMMY_STRING = "owb.actual.resource.dummy"; - - private final StandaloneResourceProcessor processor = StandaloneResourceProcessor.getProcessor(); - - private static final Logger logger = WebBeansLoggerFacade.getLogger(StandaloneResourceInjectionService.class); - - private final WebBeansContext webBeansContext; - - /** - * Cache the information if a certain class contains any EE resource at all - */ - private final Map<Class<?>, Boolean> classContainsEEResources = new ConcurrentHashMap<>(); - - public StandaloneResourceInjectionService(WebBeansContext webBeansContext) - { - this.webBeansContext = webBeansContext; - } - - protected WebBeansContext getWebBeansContext() - { - return webBeansContext; - } - - @Override - public <X, T extends Annotation> X getResourceReference(ResourceReference<X, T> resourceReference) - { - if(resourceReference.supports(Resource.class)) - { - Resource resource = resourceReference.getAnnotation(Resource.class); - return processor.getResource(resource, resourceReference.getResourceType()); - } - - if(resourceReference.supports(WebServiceRef.class)) - { - WebServiceRef resource = resourceReference.getAnnotation(WebServiceRef.class); - return processor.getWebServiceResource(resource, resourceReference.getResourceType()); - - } - - if(resourceReference.supports(PersistenceContext.class)) - { - PersistenceContext persistenceContext = resourceReference.getAnnotation(PersistenceContext.class); - return processor.getEntityManager(persistenceContext, resourceReference.getResourceType()); - } - - if(resourceReference.supports(PersistenceUnit.class)) - { - PersistenceUnit persistenceUnit = resourceReference.getAnnotation(PersistenceUnit.class); - return processor.getEntityManagerFactory(persistenceUnit, resourceReference.getResourceType()); - } - - return null; - } - - @Override - public void injectJavaEEResources(Object managedBeanInstance) - { - Class currentClass = managedBeanInstance.getClass(); - Boolean containsEeResource = classContainsEEResources.get(currentClass); - if (containsEeResource != null && !containsEeResource) - { - // nothing to do it seems. - return; - } - - - while (currentClass != null && !Object.class.getName().equals(currentClass.getName())) - { - Field[] fields = webBeansContext.getSecurityService().doPrivilegedGetDeclaredFields(currentClass); - - for(Field field : fields) - { - if(!field.isAnnotationPresent(Produces.class)) - { - if(!Modifier.isStatic(field.getModifiers())) - { - Annotation ann = AnnotationUtil.hasOwbInjectableResource(field.getDeclaredAnnotations()); - if(ann != null) - { - @SuppressWarnings("unchecked") - ResourceReference<Object, ?> resourceRef = new ResourceReference(field.getDeclaringClass(), field.getName(), field.getType(), ann); - try - { - Object resourceToInject = getResourceReference(resourceRef); - if (resourceToInject != null) - { - if(!field.isAccessible()) - { - webBeansContext.getSecurityService().doPrivilegedSetAccessible(field, true); - } - - field.set(managedBeanInstance, resourceToInject); - } - - containsEeResource = Boolean.TRUE; - } - catch(Exception e) - { - logger.log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0025, e, field)); - throw new WebBeansException(MessageFormat.format(WebBeansLoggerFacade.getTokenString(OWBLogConst.ERROR_0025), field), e); - } - } - } - } - } - - currentClass = currentClass.getSuperclass(); - } - - if (containsEeResource == null) - { - containsEeResource = Boolean.FALSE; - } - - classContainsEEResources.put(managedBeanInstance.getClass(), containsEeResource); - } - - @Override - public void clear() - { - processor.clear(); - } - -} diff --git a/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java b/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java deleted file mode 100644 index 471f6fc7e..000000000 --- a/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.webbeans.resource.spi.se; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import jakarta.annotation.Resource; -import javax.naming.InitialContext; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Persistence; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceUnit; -import javax.xml.ws.WebServiceRef; -import org.apache.webbeans.config.OWBLogConst; -import org.apache.webbeans.logger.WebBeansLoggerFacade; - -public class StandaloneResourceProcessor -{ - private static InitialContext context; - - private static Logger logger = WebBeansLoggerFacade.getLogger(StandaloneResourceProcessor.class); - - private static StandaloneResourceProcessor processor = new StandaloneResourceProcessor(); - - /** - * A cache for EntityManagerFactories. - */ - private Map<String, EntityManagerFactory> factoryCache = new ConcurrentHashMap<>(); - - static - { - try - { - context = new InitialContext(); - - } - catch(Exception e) - { - throw new ExceptionInInitializerError(e); - } - } - - public static StandaloneResourceProcessor getProcessor() - { - return processor; - } - - public <X> X getEntityManager(PersistenceContext persistenceContext, Class<X> clazz) - { - EntityManager obj = getPersistenceContext(persistenceContext.unitName()); - if (obj == null) - { - logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0014, "@PersistenceContext", persistenceContext.unitName())); - } - - return clazz.cast(obj); - } - - public <X> X getEntityManagerFactory(PersistenceUnit persistenceUnit, Class<X> clazz) - { - EntityManagerFactory factory = getPersistenceUnit(persistenceUnit.unitName()); - if (factory == null) - { - logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0014, "@PersistenceUnit", persistenceUnit.unitName())); - } - - return clazz.cast(factory); - } - - public <X> X getResource(Resource resource, Class<X> resourceType) - { - Object obj = null; - try - { - obj = context.lookup("java:/comp/env/"+ resource.name()); - if (obj == null) - { - logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0014, "@Resource", resource.name())); - } - - } - catch(Exception e) - { - logger.log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0001, resource)); - } - - return resourceType.cast(obj); - } - - public <X> X getWebServiceResource(WebServiceRef resource, Class<X> resourceType) - { - Object obj = null; - try - { - obj = context.lookup("java:/comp/env/"+ resource.name()); - if (obj == null) - { - logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0014, "@WebServiceRef", resource.name())); - } - - } - catch(Exception e) - { - logger.log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0001, resource)); - } - - return resourceType.cast(obj); - } - - /** - * {@inheritDoc} - * - */ - private EntityManagerFactory getPersistenceUnit(String unitName) - { - if(factoryCache.get(unitName) != null) - { - return factoryCache.get(unitName); - } - - EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName); - factoryCache.put(unitName, emf); - - return emf; - } - - /** - * TODO: currently this returns an extended EntityManager, so we have to wrap it - * We have to create a Proxy for injecting entity managers. So, whenever method is called - * on the entity managers, look at current Transaction, if exist call joinTransaction(); - */ - private EntityManager getPersistenceContext(String unitName) - { - EntityManagerFactory emf = getPersistenceUnit(unitName); - EntityManager em = emf.createEntityManager(); - - return em; - } - - public void clear() - { - Set<String> keys = this.factoryCache.keySet(); - for(String key : keys) - { - EntityManagerFactory factory = this.factoryCache.get(key); - try - { - factory.close(); - - } - catch(Exception e) - { - logger.log(Level.WARNING, WebBeansLoggerFacade.constructMessage(OWBLogConst.WARN_0006, e, key)); - } - } - } - -} diff --git a/webbeans-resource/src/main/resources/META-INF/openwebbeans/openwebbeans.properties b/webbeans-resource/src/main/resources/META-INF/openwebbeans/openwebbeans.properties deleted file mode 100644 index 4a2b4ef34..000000000 --- a/webbeans-resource/src/main/resources/META-INF/openwebbeans/openwebbeans.properties +++ /dev/null @@ -1,30 +0,0 @@ -#Licensed to the Apache Software Foundation (ASF) under one -#or more contributor license agreements. See the NOTICE file -#distributed with this work for additional information -#regarding copyright ownership. The ASF licenses this file -#to you under the Apache License, Version 2.0 (the -#"License"); you may not use this file except in compliance -#with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, -#software distributed under the License is distributed on an -#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#KIND, either express or implied. See the License for the -#specific language governing permissions and limitations -#under the License. -#--------------------------------------------------------------- -# The configuration for OpenWebBeans Web container integration -#--------------------------------------------------------------- - -################################################################################################ -############################# Resource Plugin SPI CONFIGURATION SECTION ######################## -################################################################################################ - -configuration.ordinal=10 - -################################### Default Resource Injection Service ######################### -#Default implementation of org.apache.webbeans.corespi.ResourceInjectionService -org.apache.webbeans.spi.ResourceInjectionService=org.apache.webbeans.resource.spi.se.StandaloneResourceInjectionService -################################################################################################ diff --git a/webbeans-resource/src/site/site.xml b/webbeans-resource/src/site/site.xml deleted file mode 100644 index f27edbeac..000000000 --- a/webbeans-resource/src/site/site.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> - -<project name="OpenWebBeans"> - <bannerLeft> - <name>Apache OpenWebBeans</name> - <src>https://openwebbeans.apache.org/owb/images/logos/openwebbeans_hor.png</src> - <href>https://openwebbeans.apache.org</href> - </bannerLeft> - - <bannerRight> - <name>Apache Banner</name> - <src>https://www.apache.org/images/asf-logo.gif</src> - <href>https://www.apache.org</href> - </bannerRight> - - <publishDate format="dd MMM yyyy" /> - <version position="left"/> - - <body> - <breadcrumbs> - <item name="Apache" href="https://www.apache.org"/> - <item name="OpenWebBeans" href="https://openwebbeans.apache.org"/> - <item name="OWB-Resource" href="https://openwebbeans.apache.org/${project.version}/openwebbeans-resource"/> - </breadcrumbs> - - <menu ref="reports"/> - </body> -</project> -
