Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Revert "Remove incomplete JNDI support"

  • Loading branch information...
commit d09a0f82eee41a1c4439224dd257028c0d33e4b2 1 parent ab2d626
Thomas Diesler authored July 30, 2012
4  distribution/installer/pom.xml
@@ -91,6 +91,10 @@
91 91
 			<artifactId>org.apache.aries.jmx</artifactId>
92 92
 		</dependency>
93 93
 		<dependency>
  94
+			<groupId>org.apache.aries.jndi</groupId>
  95
+			<artifactId>org.apache.aries.jndi</artifactId>
  96
+		</dependency>
  97
+		<dependency>
94 98
 			<groupId>org.apache.aries.proxy</groupId>
95 99
 			<artifactId>org.apache.aries.proxy</artifactId>
96 100
 		</dependency>
6  pom.xml
@@ -43,6 +43,7 @@
43 43
         <version.apache.ant>1.7.0</version.apache.ant>
44 44
         <version.apache.aries.blueprint>0.4</version.apache.aries.blueprint>
45 45
         <version.apache.aries.jmx>0.3</version.apache.aries.jmx>
  46
+        <version.apache.aries.jndi>0.3.1</version.apache.aries.jndi>
46 47
         <version.apache.aries.proxy>0.4</version.apache.aries.proxy>
47 48
         <version.apache.aries.util>0.4</version.apache.aries.util>
48 49
         <version.apache.felix.configadmin>1.2.8</version.apache.felix.configadmin>
@@ -125,6 +126,11 @@
125 126
                 <version>${version.apache.aries.jmx}</version>
126 127
             </dependency>
127 128
             <dependency>
  129
+                <groupId>org.apache.aries.jndi</groupId>
  130
+                <artifactId>org.apache.aries.jndi</artifactId>
  131
+                <version>${version.apache.aries.jndi}</version>
  132
+            </dependency>
  133
+            <dependency>
128 134
                 <groupId>org.apache.aries.proxy</groupId>
129 135
                 <artifactId>org.apache.aries.proxy</artifactId>
130 136
                 <version>${version.apache.aries.proxy}</version>
5  testsuite/example/pom.xml
@@ -45,6 +45,11 @@
45 45
             <scope>provided</scope>
46 46
         </dependency>
47 47
         <dependency>
  48
+            <groupId>org.apache.aries.jndi</groupId>
  49
+            <artifactId>org.apache.aries.jndi</artifactId>
  50
+            <scope>provided</scope>
  51
+        </dependency>
  52
+        <dependency>
48 53
             <groupId>org.apache.aries.proxy</groupId>
49 54
             <artifactId>org.apache.aries.proxy</artifactId>
50 55
             <scope>provided</scope>
49  testsuite/example/src/main/java/org/jboss/test/osgi/NamingSupport.java
... ...
@@ -0,0 +1,49 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
  4
+ * by the @authors tag. See the copyright.txt in the distribution for a
  5
+ * full listing of individual contributors.
  6
+ *
  7
+ * This is free software; you can redistribute it and/or modify it
  8
+ * under the terms of the GNU Lesser General Public License as
  9
+ * published by the Free Software Foundation; either version 2.1 of
  10
+ * the License, or (at your option) any later version.
  11
+ *
  12
+ * This software is distributed in the hope that it will be useful,
  13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15
+ * Lesser General Public License for more details.
  16
+ *
  17
+ * You should have received a copy of the GNU Lesser General Public
  18
+ * License along with this software; if not, write to the Free
  19
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21
+ */
  22
+package org.jboss.test.osgi;
  23
+
  24
+import org.osgi.framework.Bundle;
  25
+import org.osgi.framework.BundleContext;
  26
+import org.osgi.framework.BundleException;
  27
+import org.osgi.framework.ServiceReference;
  28
+import org.osgi.service.jndi.JNDIContextManager;
  29
+
  30
+/**
  31
+ * @author David Bosschaert
  32
+ */
  33
+public class NamingSupport extends RepositorySupport {
  34
+    public static final String APACHE_ARIES_JNDI = "org.apache.aries.jndi:org.apache.aries.jndi";
  35
+
  36
+    public static JNDIContextManager provideJNDIIntegration(BundleContext syscontext, Bundle bundle) throws BundleException {
  37
+        ServiceReference sref = syscontext.getServiceReference(JNDIContextManager.class.getName());
  38
+        if (sref == null) {
  39
+            AriesSupport.provideAriesUtil(syscontext, bundle);
  40
+
  41
+            // Version 0.3.1 of Aries JNDI depends on Aries Blueprint.
  42
+            BlueprintSupport.provideBlueprint(syscontext, bundle);
  43
+
  44
+            installSupportBundle(syscontext, getCoordinates(bundle, APACHE_ARIES_JNDI)).start();
  45
+            sref = syscontext.getServiceReference(JNDIContextManager.class.getName());
  46
+        }
  47
+        return (JNDIContextManager) syscontext.getService(sref);
  48
+    }
  49
+}
105  testsuite/example/src/test/java/org/jboss/test/osgi/example/jbossas/JNDIIntegrationTestCase.java
... ...
@@ -0,0 +1,105 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
  4
+ * by the @authors tag. See the copyright.txt in the distribution for a
  5
+ * full listing of individual contributors.
  6
+ *
  7
+ * This is free software; you can redistribute it and/or modify it
  8
+ * under the terms of the GNU Lesser General Public License as
  9
+ * published by the Free Software Foundation; either version 2.1 of
  10
+ * the License, or (at your option) any later version.
  11
+ *
  12
+ * This software is distributed in the hope that it will be useful,
  13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15
+ * Lesser General Public License for more details.
  16
+ *
  17
+ * You should have received a copy of the GNU Lesser General Public
  18
+ * License along with this software; if not, write to the Free
  19
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21
+ */
  22
+package org.jboss.test.osgi.example.jbossas;
  23
+
  24
+import java.io.InputStream;
  25
+
  26
+import javax.inject.Inject;
  27
+import javax.naming.Context;
  28
+import javax.naming.NameClassPair;
  29
+import javax.naming.NamingEnumeration;
  30
+
  31
+import org.jboss.arquillian.container.test.api.Deployment;
  32
+import org.jboss.arquillian.junit.Arquillian;
  33
+import org.jboss.osgi.repository.XRequirementBuilder;
  34
+import org.jboss.osgi.spi.OSGiManifestBuilder;
  35
+import org.jboss.shrinkwrap.api.ShrinkWrap;
  36
+import org.jboss.shrinkwrap.api.asset.Asset;
  37
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
  38
+import org.jboss.test.osgi.AriesSupport;
  39
+import org.jboss.test.osgi.BlueprintSupport;
  40
+import org.jboss.test.osgi.NamingSupport;
  41
+import org.jboss.test.osgi.RepositorySupport;
  42
+import org.junit.Assert;
  43
+import org.junit.Test;
  44
+import org.junit.runner.RunWith;
  45
+import org.osgi.framework.Bundle;
  46
+import org.osgi.framework.BundleContext;
  47
+import org.osgi.resource.Resource;
  48
+import org.osgi.service.jndi.JNDIContextManager;
  49
+import org.osgi.service.packageadmin.PackageAdmin;
  50
+import org.osgi.service.repository.Repository;
  51
+
  52
+/**
  53
+ * This test exercises the OSGi-JNDI integration and ensures it shares the naming system with JavaEE
  54
+ *
  55
+ * @author David Bosschaert
  56
+ */
  57
+@RunWith(Arquillian.class)
  58
+public class JNDIIntegrationTestCase {
  59
+
  60
+    @Inject
  61
+    public BundleContext context;
  62
+
  63
+    @Inject
  64
+    public Bundle bundle;
  65
+
  66
+    @Deployment
  67
+    public static JavaArchive createdeployment() {
  68
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "example-jndi");
  69
+        archive.addClasses(RepositorySupport.class, NamingSupport.class, AriesSupport.class, BlueprintSupport.class);
  70
+        archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
  71
+        archive.setManifest(new Asset() {
  72
+            @Override
  73
+            public InputStream openStream() {
  74
+                OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
  75
+                builder.addBundleSymbolicName(archive.getName());
  76
+                builder.addBundleManifestVersion(2);
  77
+                builder.addImportPackages(PackageAdmin.class);
  78
+                builder.addImportPackages(Context.class, JNDIContextManager.class);
  79
+                builder.addImportPackages(XRequirementBuilder.class, Repository.class, Resource.class);
  80
+                return builder.openStream();
  81
+            }
  82
+        });
  83
+        return archive;
  84
+    }
  85
+
  86
+    @Test
  87
+    public void testOSGiNamingContext() throws Exception {
  88
+        JNDIContextManager mgr = NamingSupport.provideJNDIIntegration(context, bundle);
  89
+
  90
+        Context ictx = mgr.newInitialContext();
  91
+
  92
+        Object jbossContext = ictx.lookup("java:jboss");
  93
+        Assert.assertNotNull("Should be able to find the java:jboss context", jbossContext);
  94
+
  95
+        Context svcCtx = (Context) ictx.lookup("osgi:servicelist/javax.naming.spi.ObjectFactory");
  96
+        NamingEnumeration<NameClassPair> ne = svcCtx.list("");
  97
+
  98
+        int count = 0;
  99
+        while (ne.hasMoreElements()) {
  100
+            ne.next();
  101
+            count++;
  102
+        }
  103
+        Assert.assertTrue("Should be at least one ObjectFactory found", count > 0);
  104
+    }
  105
+}
103  testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/JNDITestCase.java
... ...
@@ -0,0 +1,103 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
  4
+ * by the @authors tag. See the copyright.txt in the distribution for a
  5
+ * full listing of individual contributors.
  6
+ *
  7
+ * This is free software; you can redistribute it and/or modify it
  8
+ * under the terms of the GNU Lesser General Public License as
  9
+ * published by the Free Software Foundation; either version 2.1 of
  10
+ * the License, or (at your option) any later version.
  11
+ *
  12
+ * This software is distributed in the hope that it will be useful,
  13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15
+ * Lesser General Public License for more details.
  16
+ *
  17
+ * You should have received a copy of the GNU Lesser General Public
  18
+ * License along with this software; if not, write to the Free
  19
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21
+ */
  22
+package org.jboss.test.osgi.example.jndi;
  23
+
  24
+import java.io.InputStream;
  25
+
  26
+import javax.inject.Inject;
  27
+import javax.naming.Context;
  28
+import javax.naming.spi.InitialContextFactory;
  29
+
  30
+import org.jboss.arquillian.container.test.api.Deployment;
  31
+import org.jboss.arquillian.junit.Arquillian;
  32
+import org.jboss.osgi.repository.XRequirementBuilder;
  33
+import org.jboss.osgi.resolver.MavenCoordinates;
  34
+import org.jboss.osgi.spi.OSGiManifestBuilder;
  35
+import org.jboss.shrinkwrap.api.ShrinkWrap;
  36
+import org.jboss.shrinkwrap.api.asset.Asset;
  37
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
  38
+import org.jboss.test.osgi.AriesSupport;
  39
+import org.jboss.test.osgi.BlueprintSupport;
  40
+import org.jboss.test.osgi.NamingSupport;
  41
+import org.jboss.test.osgi.RepositorySupport;
  42
+import org.jboss.test.osgi.example.jndi.bundle.MyInterface;
  43
+import org.junit.Assert;
  44
+import org.junit.Test;
  45
+import org.junit.runner.RunWith;
  46
+import org.osgi.framework.Bundle;
  47
+import org.osgi.framework.BundleContext;
  48
+import org.osgi.resource.Resource;
  49
+import org.osgi.service.jndi.JNDIContextManager;
  50
+import org.osgi.service.packageadmin.ExportedPackage;
  51
+import org.osgi.service.packageadmin.PackageAdmin;
  52
+import org.osgi.service.repository.Repository;
  53
+
  54
+/**
  55
+ * This test exercises the OSGi-JNDI integration
  56
+ *
  57
+ * @author David Bosschaert
  58
+ */
  59
+@RunWith(Arquillian.class)
  60
+public class JNDITestCase {
  61
+
  62
+    @Inject
  63
+    public BundleContext context;
  64
+
  65
+    @Inject
  66
+    public Bundle bundle;
  67
+
  68
+    @Deployment
  69
+    public static JavaArchive createdeployment() {
  70
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "example-jndi");
  71
+        archive.addClasses(RepositorySupport.class, NamingSupport.class, AriesSupport.class, BlueprintSupport.class);
  72
+        archive.addClasses(MyInterface.class);
  73
+        archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
  74
+        archive.setManifest(new Asset() {
  75
+            @Override
  76
+            public InputStream openStream() {
  77
+                OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
  78
+                builder.addBundleSymbolicName(archive.getName());
  79
+                builder.addBundleManifestVersion(2);
  80
+                builder.addImportPackages(PackageAdmin.class);
  81
+                builder.addImportPackages(Context.class, InitialContextFactory.class, JNDIContextManager.class);
  82
+                builder.addImportPackages(XRequirementBuilder.class, MavenCoordinates.class, Repository.class, Resource.class);
  83
+                builder.addExportPackages(MyInterface.class);
  84
+                return builder.openStream();
  85
+            }
  86
+        });
  87
+        return archive;
  88
+    }
  89
+
  90
+    @Test
  91
+    public void testOSGiNamingContext() throws Exception {
  92
+        JNDIContextManager mgr = NamingSupport.provideJNDIIntegration(context, bundle);
  93
+
  94
+        // Get the InitialContext and lookup the PackageAdmin OSGi service through JNDI
  95
+        Context ictx = mgr.newInitialContext();
  96
+        Object viaJNDI = ictx.lookup("osgi:service/" + PackageAdmin.class.getName());
  97
+
  98
+        // Make an invocation on PackageAdmin
  99
+        PackageAdmin pa = (PackageAdmin) viaJNDI;
  100
+        ExportedPackage ep = pa.getExportedPackage(MyInterface.class.getPackage().getName());
  101
+        Assert.assertEquals(bundle, ep.getExportingBundle());
  102
+    }
  103
+}
29  testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/bundle/MyInterface.java
... ...
@@ -0,0 +1,29 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
  4
+ * by the @authors tag. See the copyright.txt in the distribution for a
  5
+ * full listing of individual contributors.
  6
+ *
  7
+ * This is free software; you can redistribute it and/or modify it
  8
+ * under the terms of the GNU Lesser General Public License as
  9
+ * published by the Free Software Foundation; either version 2.1 of
  10
+ * the License, or (at your option) any later version.
  11
+ *
  12
+ * This software is distributed in the hope that it will be useful,
  13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15
+ * Lesser General Public License for more details.
  16
+ *
  17
+ * You should have received a copy of the GNU Lesser General Public
  18
+ * License along with this software; if not, write to the Free
  19
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21
+ */
  22
+package org.jboss.test.osgi.example.jndi.bundle;
  23
+
  24
+/**
  25
+ * @author David Bosschaert
  26
+ */
  27
+public interface MyInterface {
  28
+    String getValue();
  29
+}

0 notes on commit d09a0f8

Please sign in to comment.
Something went wrong with that request. Please try again.