You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2011/11/21 16:42:41 UTC
svn commit: r1204548 - in /aries/trunk/blueprint/blueprint-core: ./
src/main/java/org/apache/aries/blueprint/container/
src/test/java/org/apache/aries/blueprint/ src/test/resources/
Author: gnodet
Date: Mon Nov 21 15:42:41 2011
New Revision: 1204548
URL: http://svn.apache.org/viewvc?rev=1204548&view=rev
Log:
[ARIES-787] Class proxying should not be enabled by default
Added:
aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ReferencesTest.java
aries/trunk/blueprint/blueprint-core/src/test/resources/test-references.xml
Modified:
aries/trunk/blueprint/blueprint-core/pom.xml
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
Modified: aries/trunk/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/pom.xml?rev=1204548&r1=1204547&r2=1204548&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-core/pom.xml Mon Nov 21 15:42:41 2011
@@ -163,6 +163,12 @@
<version>0.4</version>
</dependency>
<dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.impl</artifactId>
+ <version>0.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java?rev=1204548&r1=1204547&r2=1204548&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java Mon Nov 21 15:42:41 2011
@@ -226,7 +226,19 @@ public abstract class AbstractServiceRef
if (!interfaces.iterator().hasNext()) {
return new Object();
} else {
- //We don't use the #getBundleContextForServiceLookup() method here, the bundle requesting the proxy is the
+ // Check class proxying
+ boolean proxyClass = false;
+ if (metadata instanceof ExtendedServiceReferenceMetadata) {
+ proxyClass = (((ExtendedServiceReferenceMetadata) metadata).getProxyMethod() & ExtendedServiceReferenceMetadata.PROXY_METHOD_CLASSES) != 0;
+ }
+ if (!proxyClass) {
+ for (Class cl : interfaces) {
+ if (!cl.isInterface()) {
+ throw new ComponentDefinitionException("A class " + cl.getName() + " was found in the interfaces list, but class proxying is not allowed by default. The ext:proxy-method='classes' attribute needs to be added to this service reference.");
+ }
+ }
+ }
+ //We don't use the #getBundleContextForServiceLookup() method here, the bundle requesting the proxy is the
//blueprint client, not the context of the lookup
return blueprintContainer.getProxyManager().createDelegatingProxy(blueprintContainer.getBundleContext().getBundle(), interfaces, dispatcher, null);
}
Added: aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ReferencesTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ReferencesTest.java?rev=1204548&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ReferencesTest.java (added)
+++ aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ReferencesTest.java Mon Nov 21 15:42:41 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.aries.blueprint;
+
+import java.lang.reflect.InvocationHandler;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.apache.aries.blueprint.di.Repository;
+import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl;
+import org.apache.aries.proxy.InvocationListener;
+import org.apache.aries.proxy.ProxyManager;
+import org.apache.aries.proxy.UnableToProxyException;
+import org.apache.aries.proxy.impl.AbstractProxyManager;
+import org.osgi.framework.Bundle;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+public class ReferencesTest extends AbstractBlueprintTest {
+
+
+
+ public void testWiring() throws Exception {
+ ComponentDefinitionRegistryImpl registry = parse("/test-references.xml");
+ ProxyManager proxyManager = new AbstractProxyManager() {
+ @Override
+ protected Object createNewProxy(Bundle bundle, Collection<Class<?>> classes, Callable<Object> objectCallable, InvocationListener invocationListener) throws UnableToProxyException {
+ return new Object();
+ }
+
+ @Override
+ protected InvocationHandler getInvocationHandler(Object o) {
+ return null;
+ }
+
+ @Override
+ protected boolean isProxyClass(Class<?> aClass) {
+ return false;
+ }
+ };
+ Repository repository = new TestBlueprintContainer(registry, proxyManager).getRepository();
+
+ repository.create("refItf");
+
+ try {
+ repository.create("refClsErr");
+ fail("Should have failed");
+ } catch (ComponentDefinitionException e) {
+
+ }
+
+ repository.create("refClsOk");
+ }
+
+ static class ProxyGenerationException extends RuntimeException {
+ }
+
+}
Modified: aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java?rev=1204548&r1=1204547&r2=1204548&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java Mon Nov 21 15:42:41 2011
@@ -21,13 +21,18 @@ package org.apache.aries.blueprint;
import org.apache.aries.blueprint.container.BlueprintContainerImpl;
import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl;
import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
+import org.apache.aries.proxy.ProxyManager;
public class TestBlueprintContainer extends BlueprintContainerImpl {
private ComponentDefinitionRegistryImpl registry;
public TestBlueprintContainer(ComponentDefinitionRegistryImpl registry) {
- super(new TestBundleContext(), null, null, null, null, null, null);
+ this(registry, null);
+ }
+
+ public TestBlueprintContainer(ComponentDefinitionRegistryImpl registry, ProxyManager proxyManager) {
+ super(new TestBundleContext(), null, null, null, null, null, proxyManager);
this.registry = registry;
if (registry != null) {
registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintContainer", this));
Added: aries/trunk/blueprint/blueprint-core/src/test/resources/test-references.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/test/resources/test-references.xml?rev=1204548&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/resources/test-references.xml (added)
+++ aries/trunk/blueprint/blueprint-core/src/test/resources/test-references.xml Mon Nov 21 15:42:41 2011
@@ -0,0 +1,28 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
+
+ <reference id="refItf" interface="org.apache.aries.blueprint.pojos.InterfaceA"/>
+
+ <reference id="refClsErr" interface="org.apache.aries.blueprint.pojos.PojoA"/>
+
+ <reference id="refClsOk" interface="org.apache.aries.blueprint.pojos.PojoA" ext:proxy-method="classes" />
+
+
+</blueprint>
\ No newline at end of file