You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2016/01/15 21:58:20 UTC
svn commit: r1724876 - in /openwebbeans/trunk:
webbeans-impl/src/main/java/org/apache/webbeans/config/
webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/
webbeans-impl/src/main/java/org/apache/webbeans/util/
webbeans-impl/src/main/java/or...
Author: struberg
Date: Fri Jan 15 20:58:20 2016
New Revision: 1724876
URL: http://svn.apache.org/viewvc?rev=1724876&view=rev
Log:
OWB-1110 implement allowProxying logic
User can now define that classes are proxyable - even if they have final methods
* comma separated class list in java sytem prop -Djavax.enterprise.inject.allowProxying.classes=...
* or an environment key with the name JAVAX_ENTERPRISE_INJECT_ALLOWPROXYING_CLASSES=...
* or via beans.xml:
<beans>
<allowProxying>
<class>Class1</class>
<class>some.OtherClass</class>
</allowProxying>
</beans>
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/AllowProxyingTest.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/
openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/allowproxying.xml (with props)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveInformation.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/BeanArchiveService.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java Fri Jan 15 20:58:20 2016
@@ -1179,6 +1179,7 @@ public class BeansDeployer
configureInterceptors(url, beanArchiveInformation.getInterceptors());
configureAlternatives(url, beanArchiveInformation.getAlternativeClasses(), false, preProcessing);
configureAlternatives(url, beanArchiveInformation.getAlternativeStereotypes(), true, preProcessing);
+ configureAllowProxying(url, beanArchiveInformation.getAllowProxyingClasses());
}
logger.fine("Deploying configurations from XML has ended successfully.");
@@ -1345,6 +1346,15 @@ public class BeansDeployer
}
}
+ private void configureAllowProxying(URL url, List<String> allowProxyingClasses)
+ {
+ OpenWebBeansConfiguration owbConfiguration = webBeansContext.getOpenWebBeansConfiguration();
+ for (String allowProxyingClass : allowProxyingClasses)
+ {
+ owbConfiguration.addConfigListValue(OpenWebBeansConfiguration.ALLOW_PROXYING_PARAM, allowProxyingClass);
+ }
+ }
+
/**
* Gets error message for XML parsing of the current XML file.
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java Fri Jan 15 20:58:20 2016
@@ -25,6 +25,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Set;
+import java.util.logging.Logger;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.TransientReference;
@@ -42,14 +43,23 @@ import org.apache.webbeans.component.Pro
import org.apache.webbeans.exception.WebBeansDeploymentException;
import org.apache.webbeans.exception.helper.ViolationMessageBuilder;
import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
import org.apache.webbeans.portable.InjectionTargetImpl;
import org.apache.webbeans.util.SecurityUtil;
public class DeploymentValidationService
{
+ /**Logger instance*/
+ private static final Logger logger = WebBeansLoggerFacade.getLogger(DeploymentValidationService.class);
private WebBeansContext webBeansContext;
+ /**
+ * Classes which are allowed to be proxies despite having a non-private, non-static final method
+ */
+ private Set<String> allowProxyingClasses = null;
+
+
public DeploymentValidationService(WebBeansContext webBeansContext)
{
this.webBeansContext = webBeansContext;
@@ -62,13 +72,19 @@ public class DeploymentValidationService
*/
public UnproxyableResolutionException validateProxyable(OwbBean<?> bean)
{
+ if (allowProxyingClasses == null)
+ {
+ allowProxyingClasses = webBeansContext.getOpenWebBeansConfiguration().getConfigListValues(OpenWebBeansConfiguration.ALLOW_PROXYING_PARAM);
+ }
+
// Unproxyable test for NormalScoped beans
if (webBeansContext.getBeanManagerImpl().isNormalScope(bean.getScope()))
{
ViolationMessageBuilder violationMessage = ViolationMessageBuilder.newViolation();
Class<?> beanClass = bean.getReturnType();
-
+
+
if(!beanClass.isInterface() && beanClass != Object.class)
{
if(beanClass.isPrimitive())
@@ -91,7 +107,16 @@ public class DeploymentValidationService
String finalMethodName = hasNonPrivateFinalMethod(beanClass);
if (finalMethodName != null)
{
- violationMessage.addLine(beanClass.getName(), " has final method "+ finalMethodName + " CDI doesn't allow to proxy that.");
+ if (allowProxyingClasses.contains(beanClass.getName()))
+ {
+ logger.info(beanClass.getName() + " has final method " + finalMethodName + ". CDI doesn't allow to proxy that." +
+ " Continuing because the class is explicitly configured to be treated as proxyable." +
+ " Final methods shall not get invoked on this proxy!");
+ }
+ else
+ {
+ violationMessage.addLine(beanClass.getName(), " has final method " + finalMethodName + " CDI doesn't allow to proxy that.");
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java Fri Jan 15 20:58:20 2016
@@ -18,14 +18,19 @@
*/
package org.apache.webbeans.config;
+import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.webbeans.exception.WebBeansConfigurationException;
@@ -59,6 +64,12 @@ public class OpenWebBeansConfiguration
public static final String CONVERSATION_TIMEOUT_INTERVAL = "org.apache.webbeans.conversation.Conversation.timeoutInterval";
/**
+ * Environment property which comma separated list of classes which
+ * should NOT fail with UnproxyableResolutionException
+ */
+ public static final String ALLOW_PROXYING_PARAM = "javax.enterprise.inject.allowProxying.classes";
+
+ /**
* Lifycycle methods like {@link javax.annotation.PostConstruct} and
* {@link javax.annotation.PreDestroy} must not define a checked Exception
* regarding to the spec. But this is often unnecessary restrictive so we
@@ -165,6 +176,23 @@ public class OpenWebBeansConfiguration
private Set<String> ignoredInterfaces;
/**
+ * All configured lists per key.
+ *
+ * For a single key the following configuration sources will get parsed:
+ * <ul>
+ * <li>all {@link #DEFAULT_CONFIG_PROPERTIES_NAME} files</li>
+ * <li>{@code System.getProperties()}</li>
+ * <li>{@code System.env()}</li>
+ * </ul>
+ *
+ * All the found values will get split by comma (',') and all trimmed values
+ * will get stored in a Set.
+ *
+ */
+ private Map<String, Set<String>> configuredLists = new HashMap<String, Set<String>>();
+
+
+ /**
* you can configure this externally as well.
*
* @param properties
@@ -186,6 +214,7 @@ public class OpenWebBeansConfiguration
}
+
/**
* (re)read the configuration from the resources in the classpath.
* @see #DEFAULT_CONFIG_PROPERTIES_NAME
@@ -207,6 +236,27 @@ public class OpenWebBeansConfiguration
}
+ /**
+ * Take the given commaSeparatedVals and spit them by ',' and trim them.
+ * @return all trimmed values or an empty list
+ */
+ public List<String> splitValues(String commaSeparatedVals)
+ {
+ ArrayList<String> values = new ArrayList<String>();
+ if (commaSeparatedVals != null)
+ {
+ for (String value : commaSeparatedVals.split(","))
+ {
+ value = value.trim();
+ if (!value.isEmpty())
+ {
+ values.add(value);
+ }
+ }
+ }
+ return values;
+ }
+
private void overrideWithGlobalSettings(Properties configProperties)
{
logger.fine("Overriding properties from System and Env properties");
@@ -323,6 +373,68 @@ public class OpenWebBeansConfiguration
return ignoredInterfaces;
}
+ /**
+ * Scan all openwebbeans.properties files + system properties +
+ * syste.env for the given key.
+ * If the key is comma separated then use the separate tokens.
+ * All the values get put into a big set.
+ */
+ public synchronized Set<String> getConfigListValues(String keyName)
+ {
+ Set<String> allValues = configuredLists.get(keyName);
+ if (allValues != null)
+ {
+ return allValues;
+ }
+
+ allValues = new HashSet<String>();
+ try
+ {
+ List<Properties> properties = PropertyLoader.loadAllProperties(DEFAULT_CONFIG_PROPERTIES_NAME);
+ if (properties != null)
+ {
+ for (Properties property : properties)
+ {
+ String values = (String) property.get(keyName);
+ allValues.addAll(splitValues(values));
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ logger.log(Level.SEVERE, "Error while loading the propertyFile " + DEFAULT_CONFIG_PROPERTIES_NAME, e);
+ return Collections.EMPTY_SET;
+ }
+
+ // search for the key in the properties
+ String value = System.getProperty(keyName);
+ allValues.addAll(splitValues(value));
+
+ // search for the key in the environment
+ String envKeyName = keyName.toUpperCase().replace(".", "_");
+ value = System.getenv(envKeyName);
+ allValues.addAll(splitValues(value));
+
+ configuredLists.put(keyName, allValues);
+
+ return allValues;
+ }
+
+ /**
+ * Add a configuration value to the Set of configured values registered
+ * under the keyName.
+ *
+ * Calling this method ensures that all the configured values are first
+ * read from the environment and configuration properties.
+ *
+ * @see #getConfigListValues(String) get's called internally to insure the list is initialised
+ */
+ public synchronized void addConfigListValue(String keyName, String value)
+ {
+ Set<String> configListValues = getConfigListValues(keyName);
+ configListValues.add(value);
+ }
+
public boolean supportsInterceptionOnProducers()
{
return "true".equals(getProperty(PRODUCER_INTERCEPTION_SUPPORT, "true"));
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java Fri Jan 15 20:58:20 2016
@@ -95,7 +95,7 @@ public final class PropertyLoader
}
}
- private static List<Properties> loadAllProperties(String propertyFileName)
+ public static List<Properties> loadAllProperties(String propertyFileName)
throws IOException
{
ClassLoader cl = WebBeansUtil.getCurrentClassLoader();
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java Fri Jan 15 20:58:20 2016
@@ -39,12 +39,12 @@ import org.apache.xbean.finder.ClassLoad
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
@@ -315,21 +315,10 @@ public abstract class AbstractMetaDataDi
{
if (scanningExcludes == null)
{
- String scanningExcludesProperty =
- WebBeansContext.currentInstance().getOpenWebBeansConfiguration().getProperty(OpenWebBeansConfiguration.SCAN_EXCLUSION_PATHS);
- ArrayList<String> scanningExcludesList = new ArrayList<String>();
- if (scanningExcludesProperty != null)
- {
- for (String scanningExclude : scanningExcludesProperty.split(","))
- {
- scanningExclude = scanningExclude.trim();
- if (!scanningExclude.isEmpty())
- {
- scanningExcludesList.add(scanningExclude);
- }
- }
- }
- scanningExcludes = scanningExcludesList.toArray(new String[scanningExcludesList.size()]);
+ OpenWebBeansConfiguration owbConfiguration = WebBeansContext.currentInstance().getOpenWebBeansConfiguration();
+ String scanningExcludesProperty = owbConfiguration.getProperty(OpenWebBeansConfiguration.SCAN_EXCLUSION_PATHS);
+ List<String> excludes = owbConfiguration.splitValues(scanningExcludesProperty);
+ scanningExcludes = excludes.toArray(new String[excludes.size()]);
}
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java Fri Jan 15 20:58:20 2016
@@ -40,6 +40,7 @@ public final class WebBeansConstants
public static final String WEB_BEANS_XML_INTERCEPTORS_ELEMENT = "interceptors";
public static final String WEB_BEANS_XML_DECORATORS_ELEMENT = "decorators";
+ public static final String WEB_BEANS_XML_ALLOW_PROXYING_ELEMENT = "allowProxying";
public static final String WEB_BEANS_XML_ALTERNATIVES_ELEMENT = "alternatives";
public static final String WEB_BEANS_XML_SCAN_ELEMENT = "scan";
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveInformation.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveInformation.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveInformation.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveInformation.java Fri Jan 15 20:58:20 2016
@@ -38,7 +38,7 @@ public class DefaultBeanArchiveInformati
/** Exclude all subpackages (exclude= .**) */
private List<String> excludedPackages = null;
-
+ private List<String> allowProxyingClasses = new ArrayList<String>();
@Override
@@ -188,4 +188,11 @@ public class DefaultBeanArchiveInformati
{
this.excludedPackages = excludedPackages;
}
+
+ @Override
+ public List<String> getAllowProxyingClasses()
+ {
+ return allowProxyingClasses;
+ }
+
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java Fri Jan 15 20:58:20 2016
@@ -149,6 +149,8 @@ public class DefaultBeanArchiveService i
mergedBdaInfo.getAlternativeClasses().addAll(mergeLists(bdaWebClasses.getAlternativeClasses(), bdaWebInf.getAlternativeClasses()));
mergedBdaInfo.getAlternativeStereotypes().addAll(mergeLists(bdaWebClasses.getAlternativeStereotypes(), bdaWebInf.getAlternativeStereotypes()));
+ // we do NOT merge the allowProxying as they just stack up anyway
+
return mergedBdaInfo;
}
@@ -343,6 +345,10 @@ public class DefaultBeanArchiveService i
{
fillExcludes(bdaInfo, child);
}
+ else if (WebBeansConstants.WEB_BEANS_XML_ALLOW_PROXYING_ELEMENT.equalsIgnoreCase(child.getLocalName()))
+ {
+ fillAllowProxying(bdaInfo, child);
+ }
}
}
@@ -489,6 +495,26 @@ public class DefaultBeanArchiveService i
}
}
+ private void fillAllowProxying(DefaultBeanArchiveInformation bdaInfo, Element allowProxyingElement)
+ {
+ ElementIterator elit = new ElementIterator(allowProxyingElement);
+ while (elit.hasNext())
+ {
+ Element child = elit.next();
+ if (WebBeansConstants.WEB_BEANS_XML_CLASS.equalsIgnoreCase(child.getLocalName()))
+ {
+ String clazz = child.getTextContent().trim();
+ if (clazz.isEmpty())
+ {
+ throw new WebBeansConfigurationException("allowProxying <class> element must not be empty!");
+ }
+ bdaInfo.getAllowProxyingClasses().add(clazz);
+ }
+ }
+ }
+
+
+
private static boolean isClassAvailable(final ClassLoader loader, final String name)
{
try
Modified: openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties Fri Jan 15 20:58:20 2016
@@ -220,3 +220,15 @@ org.apache.webbeans.scanExclusionPaths=/
/jetty-, \
/plexus-
################################################################################################
+
+
+######################### Bean Scanning ########################################################
+# A list of known classes which might contain final methods but should be proxyable nonetheless
+# Some of those classes are from the JDK and have been proxyable in older versions.
+# This setting can be overridden as jvm param via -Djavax.enterprise.inject.allowProxying.classes=...
+# or an environment key with the name JAVAX_ENTERPRISE_INJECT_ALLOWPROXYING_CLASSES=...
+javax.enterprise.inject.allowProxying.classes=\
+ java.util.HashMap, \
+ java.util.Calendar
+################################################################################################
+
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/AllowProxyingTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/AllowProxyingTest.java?rev=1724876&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/AllowProxyingTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/AllowProxyingTest.java Fri Jan 15 20:58:20 2016
@@ -0,0 +1,123 @@
+/*
+ * 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.test.proxy.unproxyable;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.DefinitionException;
+import javax.inject.Inject;
+import java.util.HashMap;
+
+import junit.framework.Assert;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AllowProxyingTest extends AbstractUnitTest
+{
+
+ @Before
+ public void resetSettings()
+ {
+ System.setProperty(OpenWebBeansConfiguration.ALLOW_PROXYING_PARAM, "");
+ // there is no portable way to set environment variables from within java.
+ // and this is probably a good thing ;)
+ }
+
+
+ @Test(expected = DefinitionException.class)
+ public void testNonProxyableException()
+ {
+ startContainer(SomeClassWithFinalMethods.class);
+
+ // should blow up with UnproxyableResolutionException wrapped in a DefinitionException
+ getInstance(SomeClassWithFinalMethods.class);
+ }
+
+ @Test
+ public void testAllowProxyingDefaults()
+ {
+ startContainer(ProducerOwner.class, HashMapConsumer.class);
+ HashMapConsumer consumer = getInstance(HashMapConsumer.class);
+ Assert.assertEquals("B", consumer.getA());
+ }
+
+ @Test
+ public void testAllowProxyingViaSystemProps()
+ {
+ System.setProperty(OpenWebBeansConfiguration.ALLOW_PROXYING_PARAM,
+ "some.other.Class," + SomeClassWithFinalMethods.class.getName());
+
+ startContainer(SomeClassWithFinalMethods.class);
+
+ // should blow up with UnproxyableResolutionException wrapped in a DefinitionException
+ SomeClassWithFinalMethods instance = getInstance(SomeClassWithFinalMethods.class);
+ Assert.assertEquals("X", instance.getX());
+ }
+
+ @Test
+ public void testAllowProxyingViaBeansXml()
+ {
+ startContainer("org/apache/webbeans/test/xml/allowproxying/allowproxying.xml", SomeClassWithFinalMethods.class);
+
+ // should blow up with UnproxyableResolutionException wrapped in a DefinitionException
+ SomeClassWithFinalMethods instance = getInstance(SomeClassWithFinalMethods.class);
+ Assert.assertEquals("X", instance.getX());
+ }
+
+
+
+ @Dependent
+ public static class ProducerOwner
+ {
+ @Produces
+ @RequestScoped
+ public HashMap produceHashMap()
+ {
+ HashMap hm = new HashMap();
+ hm.put("A", "B");
+ return hm;
+ }
+ }
+
+ @RequestScoped
+ public static class HashMapConsumer
+ {
+ private @Inject HashMap theHashMap;
+
+ public String getA()
+ {
+ return (String) theHashMap.get("A");
+ }
+ }
+
+ @RequestScoped
+ public static class SomeClassWithFinalMethods
+ {
+ public String getX()
+ {
+ return "X";
+ }
+
+ final void crazyFinalMethod()
+ {
+ // nothing to do
+ }
+ }
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/proxy/unproxyable/AllowProxyingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/allowproxying.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/allowproxying.xml?rev=1724876&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/allowproxying.xml (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/allowproxying.xml Fri Jan 15 20:58:20 2016
@@ -0,0 +1,25 @@
+<?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.
+-->
+<beans>
+ <allowProxying>
+ <class>org.apache.webbeans.test.proxy.unproxyable.AllowProxyingTest$SomeClassWithFinalMethods</class>
+ <class>org.apache.webbeans.test.proxy.unproxyable.SomeOtherRandomClass</class>
+ </allowProxying>
+</beans>
Propchange: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/allowproxying/allowproxying.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/BeanArchiveService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/BeanArchiveService.java?rev=1724876&r1=1724875&r2=1724876&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/BeanArchiveService.java (original)
+++ openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/BeanArchiveService.java Fri Jan 15 20:58:20 2016
@@ -154,6 +154,7 @@ public interface BeanArchiveService
List<String> getExcludedClasses();
List<String> getExcludedPackages();
+ List<String> getAllowProxyingClasses();
}