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 2018/02/21 09:04:42 UTC
svn commit: r1824942 [2/4] - in /aries/trunk/jndi:
jndi-api/src/main/java/org/apache/aries/jndi/api/
jndi-api/src/main/java/org/apache/aries/jndi/spi/
jndi-api/src/main/java/org/apache/aries/jndi/urls/
jndi-bundle/src/main/java/org/apache/aries/jndi/pr...
Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/SingleContextProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/SingleContextProvider.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/SingleContextProvider.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/SingleContextProvider.java Wed Feb 21 09:04:41 2018
@@ -18,24 +18,24 @@
*/
package org.apache.aries.jndi;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
public class SingleContextProvider extends ContextProvider {
private final Context context;
- public SingleContextProvider(BundleContext bc, ServiceReference ref, Context ctx) {
+ public SingleContextProvider(BundleContext bc, ServiceReference<?> ref, Context ctx) {
super(bc, ref);
this.context = ctx;
}
-
+
public Context getContext() {
return context;
}
-
+
public void close() throws NamingException {
super.close();
context.close();
Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java Wed Feb 21 09:04:41 2018
@@ -18,12 +18,12 @@
*/
package org.apache.aries.jndi;
-public class Tuple<U,V> {
- public final U first;
- public final V second;
-
- public Tuple(U first, V second) {
- this.first = first;
- this.second = second;
- }
+public class Tuple<U, V> {
+ public final U first;
+ public final V second;
+
+ public Tuple(U first, V second) {
+ this.first = first;
+ this.second = second;
+ }
}
Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/URLContextProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/URLContextProvider.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/URLContextProvider.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/URLContextProvider.java Wed Feb 21 09:04:41 2018
@@ -18,20 +18,19 @@
*/
package org.apache.aries.jndi;
-import java.util.Hashtable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.ObjectFactory;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import java.util.Hashtable;
public class URLContextProvider extends ContextProvider {
private final ObjectFactory factory;
private final Hashtable<?, ?> environment;
-
- public URLContextProvider(BundleContext bc, ServiceReference reference, ObjectFactory factory, Hashtable<?, ?> environment) {
+
+ public URLContextProvider(BundleContext bc, ServiceReference<?> reference, ObjectFactory factory, Hashtable<?, ?> environment) {
super(bc, reference);
this.factory = factory;
this.environment = environment;
@@ -46,5 +45,5 @@ public class URLContextProvider extends
ne.initCause(e);
throw ne;
}
- }
+ }
}
Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java Wed Feb 21 09:04:41 2018
@@ -18,50 +18,38 @@
*/
package org.apache.aries.jndi;
+import org.apache.aries.util.nls.MessageUtil;
+import org.osgi.framework.*;
+import org.osgi.service.jndi.JNDIConstants;
+
+import javax.naming.NamingException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.Comparator;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.naming.NamingException;
-
-import org.apache.aries.util.nls.MessageUtil;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.BundleReference;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.jndi.JNDIConstants;
+import java.util.*;
/**
*/
public final class Utils {
- public static final Comparator<ServiceReference> SERVICE_REFERENCE_COMPARATOR =
- new ServiceReferenceComparator();
+ public static final Comparator<ServiceReference<?>> SERVICE_REFERENCE_COMPARATOR =
+ new ServiceReferenceComparator();
public static final MessageUtil MESSAGES = MessageUtil.createMessageUtil(Utils.class, "org.apache.aries.jndi.nls.jndiMessages");
- /** Ensure no one constructs us */
+ /**
+ * Ensure no one constructs us
+ */
private Utils() {
throw new RuntimeException();
}
-
- private static class StackFinder extends SecurityManager {
- public Class<?>[] getClassContext() {
- return super.getClassContext();
- }
- }
-
+
/**
* @param env
* @return the bundle context for the caller.
* @throws NamingException
*/
- public static BundleContext getBundleContext(final Map<?, ?> env,
+ public static BundleContext getBundleContext(final Map<?, ?> env,
final Class<?> namingClass) {
return AccessController.doPrivileged(new PrivilegedAction<BundleContext>() {
public BundleContext run() {
@@ -69,7 +57,7 @@ public final class Utils {
}
});
}
-
+
private static BundleContext doGetBundleContext(Map<?, ?> env, Class<?> namingClass) {
BundleContext result = null;
@@ -89,14 +77,14 @@ public final class Utils {
// working from the root of the stack look for the first instance in the stack of this class
int i = classStack.length - 1;
for (; i >= 0; i--) {
- if (namingClass.isAssignableFrom(classStack[i])) {
- break;
- }
+ if (namingClass.isAssignableFrom(classStack[i])) {
+ break;
+ }
}
-
+
// then go to the parent of the namingClass down the stack until we find a BundleContext
for (i++; i < classStack.length && result == null; i++) {
- result = getBundleContext(classStack[i].getClassLoader());
+ result = getBundleContext(classStack[i].getClassLoader());
}
}
@@ -108,15 +96,15 @@ public final class Utils {
BundleContext result = null;
while (result == null && cl != null) {
if (cl instanceof BundleReference) {
- Bundle b = ((BundleReference)cl).getBundle();
+ Bundle b = ((BundleReference) cl).getBundle();
result = b.getBundleContext();
if (result == null) {
- try {
- b.start();
- result = b.getBundleContext();
- } catch (BundleException e) {
- }
- break;
+ try {
+ b.start();
+ result = b.getBundleContext();
+ } catch (BundleException e) {
+ }
+ break;
}
} else if (cl != null) {
cl = cl.getParent();
@@ -125,33 +113,27 @@ public final class Utils {
return result;
}
-
- private static class ServiceReferenceComparator implements Comparator<ServiceReference> {
- public int compare(ServiceReference o1, ServiceReference o2) {
- return o2.compareTo(o1);
- }
- }
-
+
public static String getSystemProperty(final String key, final String defaultValue) {
return AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return System.getProperty(key, defaultValue);
- }
+ }
});
}
-
- public static Hashtable<?,?> toHashtable(Map<?,?> map) {
- Hashtable<?,?> env;
- if (map instanceof Hashtable<?,?>) {
- env = (Hashtable<?,?>) map;
+
+ public static Hashtable<?, ?> toHashtable(Map<?, ?> map) {
+ Hashtable<?, ?> env;
+ if (map instanceof Hashtable<?, ?>) {
+ env = (Hashtable<?, ?>) map;
} else if (map == null) {
- env = new Hashtable<Object,Object>();
+ env = new Hashtable<Object, Object>();
} else {
- env = new Hashtable<Object,Object>(map);
+ env = new Hashtable<Object, Object>(map);
}
return env;
}
-
+
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws Exception {
try {
return AccessController.doPrivileged(action);
@@ -160,7 +142,7 @@ public final class Utils {
throw cause;
}
}
-
+
public static <T> T doPrivilegedNaming(PrivilegedExceptionAction<T> action) throws NamingException {
try {
return AccessController.doPrivileged(action);
@@ -175,26 +157,46 @@ public final class Utils {
}
}
}
-
- public static ServiceReference[] getReferencesPrivileged(final BundleContext ctx, final Class<?> clazz) {
- return AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>() {
- public ServiceReference[] run() {
- try {
- return ctx.getServiceReferences(clazz.getName(), null);
- } catch (InvalidSyntaxException ise) {
- // should not happen
- throw new RuntimeException(MESSAGES.getMessage("null.is.invalid.filter"), ise);
- }
- }
- });
- }
-
- public static Object getServicePrivileged(final BundleContext ctx, final ServiceReference ref) {
- return AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- return ctx.getService(ref);
- }
- });
+
+ public static <T> Collection<ServiceReference<T>> getReferencesPrivileged(final BundleContext ctx, final Class<T> clazz) {
+ return AccessController.doPrivileged(new PrivilegedAction<Collection<ServiceReference<T>>>() {
+ public Collection<ServiceReference<T>> run() {
+ try {
+ ServiceReference<?>[] refs = ctx.getServiceReferences(clazz.getName(), null);
+ List<ServiceReference<T>> list = new ArrayList<ServiceReference<T>>();
+ if (refs != null) {
+ for (ServiceReference<?> ref : refs) {
+ list.add((ServiceReference<T>) ref);
+ }
+ }
+ Collections.sort(list, Utils.SERVICE_REFERENCE_COMPARATOR);
+ return list;
+ } catch (InvalidSyntaxException ise) {
+ // should not happen
+ throw new RuntimeException(MESSAGES.getMessage("null.is.invalid.filter"), ise);
+ }
+ }
+ });
+ }
+
+ public static <T> T getServicePrivileged(final BundleContext ctx, final ServiceReference<T> ref) {
+ return AccessController.doPrivileged(new PrivilegedAction<T>() {
+ public T run() {
+ return ctx.getService(ref);
+ }
+ });
+ }
+
+ private static class StackFinder extends SecurityManager {
+ public Class<?>[] getClassContext() {
+ return super.getClassContext();
+ }
+ }
+
+ private static class ServiceReferenceComparator implements Comparator<ServiceReference<?>> {
+ public int compare(ServiceReference<?> o1, ServiceReference<?> o2) {
+ return o2.compareTo(o1);
+ }
}
}
Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java Wed Feb 21 09:04:41 2018
@@ -18,26 +18,10 @@
*/
package org.apache.aries.jndi.startup;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.InitialContextFactoryBuilder;
-import javax.naming.spi.NamingManager;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.apache.aries.jndi.ContextManagerServiceFactory;
-import org.apache.aries.jndi.JREInitialContextFactoryBuilder;
-import org.apache.aries.jndi.OSGiInitialContextFactoryBuilder;
-import org.apache.aries.jndi.OSGiObjectFactoryBuilder;
-import org.apache.aries.jndi.ProviderAdminServiceFactory;
-import org.apache.aries.jndi.Utils;
-import org.apache.aries.jndi.AugmenterInvokerImpl;
+import org.apache.aries.jndi.*;
+import org.apache.aries.jndi.spi.AugmenterInvoker;
import org.apache.aries.jndi.spi.EnvironmentAugmentation;
import org.apache.aries.jndi.spi.EnvironmentUnaugmentation;
-import org.apache.aries.jndi.spi.AugmenterInvoker;
import org.apache.aries.jndi.tracker.ServiceTrackerCustomizers;
import org.apache.aries.jndi.urls.URLObjectFactoryFinder;
import org.osgi.framework.BundleActivator;
@@ -51,6 +35,11 @@ import org.osgi.util.tracker.ServiceTrac
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.naming.NamingException;
+import javax.naming.spi.*;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+
/**
* The activator for this bundle makes sure the static classes in it are
* driven so they can do their magic stuff properly.
@@ -60,24 +49,87 @@ public class Activator implements Bundle
private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class.getName());
private static String FORCE_BUILDER = "org.apache.aries.jndi.force.builder";
-
- private OSGiInitialContextFactoryBuilder icfBuilder;
private static InitialContextFactoryBuilder originalICFBuilder;
- private OSGiObjectFactoryBuilder ofBuilder;
private static ObjectFactoryBuilder originalOFBuilder;
- private static volatile ServiceTracker icfBuilders;
- private static volatile ServiceTracker urlObjectFactoryFinders;
- private static volatile ServiceTracker initialContextFactories;
- private static volatile ServiceTracker objectFactories;
- private static volatile ServiceTracker environmentAugmentors;
- private static volatile ServiceTracker environmentUnaugmentors;
+ private static volatile ServiceTracker<InitialContextFactoryBuilder, ServiceReference<InitialContextFactoryBuilder>> icfBuilders;
+ private static volatile ServiceTracker<URLObjectFactoryFinder, ServiceReference<URLObjectFactoryFinder>> urlObjectFactoryFinders;
+ private static volatile ServiceTracker<InitialContextFactory, ServiceReference<InitialContextFactory>> initialContextFactories;
+ private static volatile ServiceTracker<ObjectFactory, ServiceReference<ObjectFactory>> objectFactories;
+ private static volatile ServiceTracker<EnvironmentAugmentation, ServiceReference<EnvironmentAugmentation>> environmentAugmentors;
+ private static volatile ServiceTracker<EnvironmentUnaugmentation, ServiceReference<EnvironmentUnaugmentation>> environmentUnaugmentors;
+ private OSGiInitialContextFactoryBuilder icfBuilder;
+ private OSGiObjectFactoryBuilder ofBuilder;
+
+ /*
+ * There are no public API to reset the InitialContextFactoryBuilder or
+ * ObjectFactoryBuilder on the NamingManager so try to use reflection.
+ */
+ private static void setField(Class<?> expectedType, Object value, boolean saveOriginal) throws IllegalStateException {
+ try {
+ for (Field field : NamingManager.class.getDeclaredFields()) {
+ if (expectedType.equals(field.getType())) {
+ field.setAccessible(true);
+ if (saveOriginal) {
+ if (expectedType.equals(InitialContextFactoryBuilder.class)) {
+ originalICFBuilder = (InitialContextFactoryBuilder) field.get(null);
+ } else {
+ originalOFBuilder = (ObjectFactoryBuilder) field.get(null);
+ }
+ }
+
+ field.set(null, value);
+ }
+ }
+ } catch (Throwable t) {
+ // Ignore
+ LOGGER.debug("Error setting field.", t);
+ throw new IllegalStateException(t);
+ }
+ }
+
+ public static ServiceReference<InitialContextFactoryBuilder>[] getInitialContextFactoryBuilderServices() {
+ ServiceReference<InitialContextFactoryBuilder>[] refs = icfBuilders.getServiceReferences();
+
+ if (refs != null) {
+ Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
+ }
+
+ return refs;
+ }
+
+ public static ServiceReference<InitialContextFactory>[] getInitialContextFactoryServices() {
+ ServiceReference<InitialContextFactory>[] refs = initialContextFactories.getServiceReferences();
+
+ if (refs != null) {
+ Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
+ }
+
+ return refs;
+ }
+
+ public static ServiceReference<URLObjectFactoryFinder>[] getURLObjectFactoryFinderServices() {
+ ServiceReference<URLObjectFactoryFinder>[] refs = urlObjectFactoryFinders.getServiceReferences();
+
+ if (refs != null) {
+ Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
+ }
+ return refs;
+ }
+
+ public static Object[] getEnvironmentAugmentors() {
+ return environmentAugmentors.getServices();
+ }
+
+ public static Object[] getEnvironmentUnaugmentors() {
+ return environmentUnaugmentors.getServices();
+ }
public void start(BundleContext context) {
initialContextFactories = initServiceTracker(context, InitialContextFactory.class, ServiceTrackerCustomizers.ICF_CACHE);
objectFactories = initServiceTracker(context, ObjectFactory.class, ServiceTrackerCustomizers.URL_FACTORY_CACHE);
- icfBuilders = initServiceTracker(context, InitialContextFactoryBuilder.class, ServiceTrackerCustomizers.LAZY);
- urlObjectFactoryFinders = initServiceTracker(context, URLObjectFactoryFinder.class, ServiceTrackerCustomizers.LAZY);
+ icfBuilders = initServiceTracker(context, InitialContextFactoryBuilder.class, ServiceTrackerCustomizers.<InitialContextFactoryBuilder>LAZY());
+ urlObjectFactoryFinders = initServiceTracker(context, URLObjectFactoryFinder.class, ServiceTrackerCustomizers.<URLObjectFactoryFinder>LAZY());
environmentAugmentors = initServiceTracker(context, EnvironmentAugmentation.class, null);
environmentUnaugmentors = initServiceTracker(context, EnvironmentUnaugmentation.class, null);
@@ -113,7 +165,7 @@ public class Activator implements Bundle
}
ofBuilder = builder;
} catch (NamingException e) {
- LOGGER.info(Utils.MESSAGES.getMessage("unable.to.set.static.OFB"), e);
+ LOGGER.info(Utils.MESSAGES.getMessage("unable.to.set.static.OFB"), e);
} catch (IllegalStateException e) {
// Log the problem at info level, but only log the exception at debug level, as in many cases this is not a real issue and people
// don't want to see stack traces at info level when everything it working as expected.
@@ -122,20 +174,20 @@ public class Activator implements Bundle
}
context.registerService(JNDIProviderAdmin.class.getName(),
- new ProviderAdminServiceFactory(context),
- null);
+ new ProviderAdminServiceFactory(context),
+ null);
context.registerService(InitialContextFactoryBuilder.class.getName(),
- new JREInitialContextFactoryBuilder(),
- null);
+ new JREInitialContextFactoryBuilder(),
+ null);
context.registerService(JNDIContextManager.class.getName(),
- new ContextManagerServiceFactory(),
- null);
+ new ContextManagerServiceFactory(),
+ null);
context.registerService(AugmenterInvoker.class.getName(),
- AugmenterInvokerImpl.getInstance(),
- null);
+ AugmenterInvokerImpl.getInstance(),
+ null);
}
private boolean forceBuilder(BundleContext context) {
@@ -147,8 +199,7 @@ public class Activator implements Bundle
return !(revision.getDeclaredCapabilities(FORCE_BUILDER).isEmpty());
}
- private String getClassName(Class<?> expectedType)
- {
+ private String getClassName(Class<?> expectedType) {
try {
for (Field field : NamingManager.class.getDeclaredFields()) {
if (expectedType.equals(field.getType())) {
@@ -163,10 +214,9 @@ public class Activator implements Bundle
return "";
}
- private ServiceTracker initServiceTracker(BundleContext context,
- Class<?> type, ServiceTrackerCustomizer custom)
- {
- ServiceTracker t = new ServiceTracker(context, type.getName(), custom);
+ private <S, T> ServiceTracker<S, T> initServiceTracker(BundleContext context,
+ Class<S> type, ServiceTrackerCustomizer<S, T> custom) {
+ ServiceTracker<S, T> t = new ServiceTracker<S, T>(context, type, custom);
t.open();
return t;
}
@@ -190,73 +240,4 @@ public class Activator implements Bundle
environmentAugmentors.close();
environmentUnaugmentors.close();
}
-
- /*
- * There are no public API to reset the InitialContextFactoryBuilder or
- * ObjectFactoryBuilder on the NamingManager so try to use reflection.
- */
- private static void setField(Class<?> expectedType, Object value, boolean saveOriginal) throws IllegalStateException {
- try {
- for (Field field : NamingManager.class.getDeclaredFields()) {
- if (expectedType.equals(field.getType())) {
- field.setAccessible(true);
- if (saveOriginal) {
- if (expectedType.equals(InitialContextFactoryBuilder.class)) {
- originalICFBuilder = (InitialContextFactoryBuilder) field.get(null);
- } else {
- originalOFBuilder = (ObjectFactoryBuilder) field.get(null);
- }
- }
-
- field.set(null, value);
- }
- }
- } catch (Throwable t) {
- // Ignore
- LOGGER.debug("Error setting field.", t);
- throw new IllegalStateException(t);
- }
- }
-
- public static ServiceReference[] getInitialContextFactoryBuilderServices()
- {
- ServiceReference[] refs = icfBuilders.getServiceReferences();
-
- if (refs != null) {
- Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
- }
-
- return refs;
- }
-
- public static ServiceReference[] getInitialContextFactoryServices()
- {
- ServiceReference[] refs = initialContextFactories.getServiceReferences();
-
- if (refs != null) {
- Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
- }
-
- return refs;
- }
-
- public static ServiceReference[] getURLObectFactoryFinderServices()
- {
- ServiceReference[] refs = urlObjectFactoryFinders.getServiceReferences();
-
- if (refs != null) {
- Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
- }
- return refs;
- }
-
- public static Object[] getEnvironmentAugmentors()
- {
- return environmentAugmentors.getServices();
- }
-
- public static Object[] getEnvironmentUnaugmentors()
- {
- return environmentUnaugmentors.getServices();
- }
}
Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/tracker/ServiceTrackerCustomizers.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/tracker/ServiceTrackerCustomizers.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/tracker/ServiceTrackerCustomizers.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/tracker/ServiceTrackerCustomizers.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -18,6 +18,13 @@
*/
package org.apache.aries.jndi.tracker;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.jndi.JNDIConstants;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.ObjectFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -25,31 +32,70 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import javax.naming.spi.InitialContextFactory;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.jndi.JNDIConstants;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
+public class ServiceTrackerCustomizers {
+ public static final CachingServiceTracker<InitialContextFactory> ICF_CACHE = new BaseCachingServiceTracker<InitialContextFactory>() {
+ public List<String> getProperty(ServiceReference<InitialContextFactory> ref) {
+ String[] interfaces = (String[]) ref.getProperty(Constants.OBJECTCLASS);
+ List<String> resultList = new ArrayList<String>();
+ for (String interfaceName : interfaces) {
+ if (!InitialContextFactory.class.getName().equals(interfaceName)) {
+ resultList.add(interfaceName);
+ }
+ }
-public class ServiceTrackerCustomizers {
+ return resultList;
+ }
+ };
+ // TODO we should probably cope with the url.scheme property changing.
+ public static final CachingServiceTracker<ObjectFactory> URL_FACTORY_CACHE = new BaseCachingServiceTracker<ObjectFactory>() {
+ protected List<String> getProperty(ServiceReference<ObjectFactory> reference) {
+ Object scheme = reference.getProperty(JNDIConstants.JNDI_URLSCHEME);
+ List<String> result;
+
+ if (scheme instanceof String) {
+ result = new ArrayList<String>();
+ result.add((String) scheme);
+ } else if (scheme instanceof String[]) {
+ result = Arrays.asList((String[]) scheme);
+ } else {
+ result = Collections.emptyList();
+ }
+
+ return result;
+ }
+ };
- public interface CachingServiceTracker extends ServiceTrackerCustomizer {
- ServiceReference find(String identifier);
+ public static final <S> ServiceTrackerCustomizer<S, ServiceReference<S>> LAZY() {
+ return new ServiceTrackerCustomizer<S, ServiceReference<S>>() {
+ public ServiceReference<S> addingService(ServiceReference<S> reference) {
+ return reference;
+ }
+
+ public void modifiedService(ServiceReference<S> reference, ServiceReference<S> service) {
+ }
+
+ public void removedService(ServiceReference<S> reference, ServiceReference<S> service) {
+ }
+ };
}
- private static abstract class BaseCachingServiceTracker implements CachingServiceTracker {
+ public interface CachingServiceTracker<S> extends ServiceTrackerCustomizer<S, ServiceReference<S>> {
+ ServiceReference<S> find(String identifier);
+ }
+
+ private static abstract class BaseCachingServiceTracker<S> implements CachingServiceTracker<S> {
/** The cached references */
- protected ConcurrentMap<String, ServiceReference> cache = new ConcurrentHashMap<String, ServiceReference>();
+ protected ConcurrentMap<String, ServiceReference<S>> cache = new ConcurrentHashMap<String, ServiceReference<S>>();
/** A list of service references that are being tracked */
- protected List<ServiceReference> trackedReferences = new ArrayList<ServiceReference>();
+ protected List<ServiceReference<S>> trackedReferences = new ArrayList<ServiceReference<S>>();
- public ServiceReference find(String identifier) {
+ public ServiceReference<S> find(String identifier) {
return cache.get(identifier);
}
- public synchronized Object addingService(ServiceReference reference) {
+ public synchronized ServiceReference<S> addingService(ServiceReference<S> reference) {
List<String> cacheKeys = getProperty(reference);
for (String key : cacheKeys) {
@@ -61,15 +107,15 @@ public class ServiceTrackerCustomizers {
return reference;
}
- protected abstract List<String> getProperty(ServiceReference reference);
+ protected abstract List<String> getProperty(ServiceReference<S> reference);
- public synchronized void removedService(ServiceReference reference, Object service) {
+ public synchronized void removedService(ServiceReference<S> reference, ServiceReference<S> service) {
trackedReferences.remove(reference);
List<String> keysToProcess = new ArrayList<String>(getProperty(reference));
refLoop:
- for (ServiceReference ref : trackedReferences) {
+ for (ServiceReference<S> ref : trackedReferences) {
List<String> refInt = getProperty(ref);
for (String interfaceName : refInt) {
int index = keysToProcess.indexOf(interfaceName);
@@ -87,52 +133,7 @@ public class ServiceTrackerCustomizers {
}
}
- public void modifiedService(ServiceReference reference, Object service) {
+ public void modifiedService(ServiceReference<S> reference, ServiceReference<S> service) {
}
}
-
- public static final ServiceTrackerCustomizer LAZY = new ServiceTrackerCustomizer() {
- public Object addingService(ServiceReference reference) {
- return reference;
- }
-
- public void modifiedService(ServiceReference reference, Object service) {
- }
-
- public void removedService(ServiceReference reference, Object service) {
- }
- };
-
- public static final CachingServiceTracker ICF_CACHE = new BaseCachingServiceTracker() {
- public List<String> getProperty(ServiceReference ref) {
- String[] interfaces = (String[]) ref.getProperty(Constants.OBJECTCLASS);
- List<String> resultList = new ArrayList<String>();
- for (String interfaceName : interfaces) {
- if (!!!InitialContextFactory.class.getName().equals(interfaceName)) {
- resultList.add(interfaceName);
- }
- }
-
- return resultList;
- }
- };
-
- // TODO we should probably cope with the url.scheme property changing.
- public static final CachingServiceTracker URL_FACTORY_CACHE = new BaseCachingServiceTracker() {
- protected List<String> getProperty(ServiceReference reference) {
- Object scheme = reference.getProperty(JNDIConstants.JNDI_URLSCHEME);
- List<String> result;
-
- if (scheme instanceof String) {
- result = new ArrayList<String>();
- result.add((String) scheme);
- } else if (scheme instanceof String[]) {
- result = Arrays.asList((String[]) scheme);
- } else {
- result = Collections.emptyList();
- }
-
- return result;
- }
- };
}
Modified: aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java (original)
+++ aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -18,30 +18,7 @@
*/
package org.apache.aries.jndi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.NoInitialContextException;
-import javax.naming.ldap.Control;
-import javax.naming.ldap.ExtendedRequest;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.InitialContextFactoryBuilder;
-import javax.naming.spi.ObjectFactory;
-
import junit.framework.Assert;
-
import org.apache.aries.jndi.startup.Activator;
import org.apache.aries.mocks.BundleContextMock;
import org.apache.aries.unittest.mocks.MethodCall;
@@ -52,200 +29,208 @@ import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.service.jndi.JNDIConstants;
-public class InitialContextTest
-{
- private Activator activator;
- private BundleContext bc;
- private InitialContext ic;
-
- /**
- * This method does the setup .
- * @throws NoSuchFieldException
- * @throws SecurityException
- * @throws IllegalAccessException
- * @throws IllegalArgumentException
- */
- @Before
- public void setup() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
- {
- bc = Skeleton.newMock(new BundleContextMock(), BundleContext.class);
- activator = new Activator();
- activator.start(bc);
- }
-
- /**
- * Make sure we clear the caches out before the next test.
- */
- @After
- public void teardown()
- {
- activator.stop(bc);
- BundleContextMock.clear();
- }
-
- @Test
- public void testLookupWithICF() throws NamingException
- {
- InitialContextFactory icf = Skeleton.newMock(InitialContextFactory.class);
- bc.registerService(new String[] {InitialContextFactory.class.getName(), icf.getClass().getName()}, icf, (Dictionary) new Properties());
- Skeleton.getSkeleton(icf).setReturnValue(new MethodCall(Context.class, "lookup", "/"), Skeleton.newMock(Context.class));
-
- Properties props = new Properties();
- props.put(Context.INITIAL_CONTEXT_FACTORY, icf.getClass().getName());
- props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
- InitialContext ctx = new InitialContext(props);
-
- Context namingCtx = (Context) ctx.lookup("/");
- assertTrue("Context returned isn't the raw naming context: " + namingCtx, Skeleton.isSkeleton(namingCtx));
- }
-
- @Test(expected=NoInitialContextException.class)
- public void testLookupWithoutICF() throws NamingException
- {
- Properties props = new Properties();
- props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
- InitialContext ctx = new InitialContext(props);
-
- ctx.lookup("/");
- }
-
- @Test
- public void testLookupWithoutICFButWithURLLookup() throws NamingException
- {
- ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
- Context ctx = Skeleton.newMock(Context.class);
- Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class),
- ctx);
- Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), "someText");
-
- Properties props = new Properties();
- props.put(JNDIConstants.JNDI_URLSCHEME, "testURL");
- bc.registerService(ObjectFactory.class.getName(), factory, (Dictionary) props);
-
-
- props = new Properties();
- props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
- InitialContext initialCtx = new InitialContext(props);
-
- Object someObject = initialCtx.lookup("testURL:somedata");
- assertEquals("Expected to be given a string, but got something else.", "someText", someObject);
- }
-
- @Test
- public void testLookFromLdapICF() throws Exception
- {
- InitialContextFactoryBuilder icf = Skeleton.newMock(InitialContextFactoryBuilder.class);
- bc.registerService(new String[] {InitialContextFactoryBuilder.class.getName(), icf.getClass().getName()}, icf, (Dictionary) new Properties());
-
- LdapContext backCtx = Skeleton.newMock(LdapContext.class);
- InitialContextFactory fac = Skeleton.newMock(InitialContextFactory.class);
- Skeleton.getSkeleton(fac).setReturnValue(
- new MethodCall(InitialContextFactory.class, "getInitialContext", Hashtable.class),
- backCtx);
- Skeleton.getSkeleton(icf).setReturnValue(
- new MethodCall(InitialContextFactoryBuilder.class, "createInitialContextFactory", Hashtable.class),
- fac);
-
- Properties props = new Properties();
- props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
- props.put(Context.INITIAL_CONTEXT_FACTORY, "dummy.factory");
- InitialLdapContext ilc = new InitialLdapContext(props, new Control[0]);
-
- ExtendedRequest req = Skeleton.newMock(ExtendedRequest.class);
- ilc.extendedOperation(req);
- Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation", req));
- }
-
- @Test
- public void testURLLookup() throws Exception {
- ObjectFactory of = new ObjectFactory() {
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
- return dummyContext("result");
- }
- };
-
- registerURLObjectFactory(of, "test");
- ic = initialContext();
-
- assertEquals("result", ic.lookup("test:something"));
- }
-
- @Test
- public void testNoURLContextCaching() throws Exception {
- final AtomicBoolean second = new AtomicBoolean(false);
- final Context ctx = dummyContext("one");
- final Context ctx2 = dummyContext("two");
-
- ObjectFactory of = new ObjectFactory() {
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
- if (second.get()) return ctx2;
- else {
- second.set(true);
- return ctx;
- }
- }
- };
-
- registerURLObjectFactory(of, "test");
- ic = initialContext();
-
- assertEquals("one", ic.lookup("test:something"));
- assertEquals("two", ic.lookup("test:something"));
- }
-
- @Test
- public void testURLContextErrorPropagation() throws Exception {
- ObjectFactory of = new ObjectFactory() {
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?, ?> environment) throws Exception {
- throw new Exception("doh");
+import javax.naming.*;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.ObjectFactory;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.*;
+
+public class InitialContextTest {
+ private Activator activator;
+ private BundleContext bc;
+ private InitialContext ic;
+
+ /**
+ * This method does the setup .
+ * @throws NoSuchFieldException
+ * @throws SecurityException
+ * @throws IllegalAccessException
+ * @throws IllegalArgumentException
+ */
+ @Before
+ public void setup() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+ bc = Skeleton.newMock(new BundleContextMock(), BundleContext.class);
+ activator = new Activator();
+ activator.start(bc);
+ }
+
+ /**
+ * Make sure we clear the caches out before the next test.
+ */
+ @After
+ public void teardown() {
+ activator.stop(bc);
+ BundleContextMock.clear();
+ }
+
+ @Test
+ public void testLookupWithICF() throws NamingException {
+ InitialContextFactory icf = Skeleton.newMock(InitialContextFactory.class);
+ bc.registerService(new String[]{InitialContextFactory.class.getName(), icf.getClass().getName()}, icf, (Dictionary) new Properties());
+ Skeleton.getSkeleton(icf).setReturnValue(new MethodCall(Context.class, "lookup", "/"), Skeleton.newMock(Context.class));
+
+ Properties props = new Properties();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, icf.getClass().getName());
+ props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ InitialContext ctx = new InitialContext(props);
+
+ Context namingCtx = (Context) ctx.lookup("/");
+ assertTrue("Context returned isn't the raw naming context: " + namingCtx, Skeleton.isSkeleton(namingCtx));
+ }
+
+ @Test(expected = NoInitialContextException.class)
+ public void testLookupWithoutICF() throws NamingException {
+ Properties props = new Properties();
+ props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ InitialContext ctx = new InitialContext(props);
+
+ ctx.lookup("/");
+ }
+
+ @Test
+ public void testLookupWithoutICFButWithURLLookup() throws NamingException {
+ ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
+ Context ctx = Skeleton.newMock(Context.class);
+ Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class),
+ ctx);
+ Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), "someText");
+
+ Properties props = new Properties();
+ props.put(JNDIConstants.JNDI_URLSCHEME, "testURL");
+ bc.registerService(ObjectFactory.class.getName(), factory, (Dictionary) props);
+
+
+ props = new Properties();
+ props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ InitialContext initialCtx = new InitialContext(props);
+
+ Object someObject = initialCtx.lookup("testURL:somedata");
+ assertEquals("Expected to be given a string, but got something else.", "someText", someObject);
+ }
+
+ @Test
+ public void testLookFromLdapICF() throws Exception {
+ InitialContextFactoryBuilder icf = Skeleton.newMock(InitialContextFactoryBuilder.class);
+ bc.registerService(new String[]{InitialContextFactoryBuilder.class.getName(), icf.getClass().getName()}, icf, (Dictionary) new Properties());
+
+ LdapContext backCtx = Skeleton.newMock(LdapContext.class);
+ InitialContextFactory fac = Skeleton.newMock(InitialContextFactory.class);
+ Skeleton.getSkeleton(fac).setReturnValue(
+ new MethodCall(InitialContextFactory.class, "getInitialContext", Hashtable.class),
+ backCtx);
+ Skeleton.getSkeleton(icf).setReturnValue(
+ new MethodCall(InitialContextFactoryBuilder.class, "createInitialContextFactory", Hashtable.class),
+ fac);
+
+ Properties props = new Properties();
+ props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ props.put(Context.INITIAL_CONTEXT_FACTORY, "dummy.factory");
+ InitialLdapContext ilc = new InitialLdapContext(props, new Control[0]);
+
+ ExtendedRequest req = Skeleton.newMock(ExtendedRequest.class);
+ ilc.extendedOperation(req);
+ Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation", req));
+ }
+
+ @Test
+ public void testURLLookup() throws Exception {
+ ObjectFactory of = new ObjectFactory() {
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
+ return dummyContext("result");
+ }
+ };
+
+ registerURLObjectFactory(of, "test");
+ ic = initialContext();
+
+ assertEquals("result", ic.lookup("test:something"));
+ }
+
+ @Test
+ public void testNoURLContextCaching() throws Exception {
+ final AtomicBoolean second = new AtomicBoolean(false);
+ final Context ctx = dummyContext("one");
+ final Context ctx2 = dummyContext("two");
+
+ ObjectFactory of = new ObjectFactory() {
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
+ if (second.get()) return ctx2;
+ else {
+ second.set(true);
+ return ctx;
+ }
+ }
+ };
+
+ registerURLObjectFactory(of, "test");
+ ic = initialContext();
+
+ assertEquals("one", ic.lookup("test:something"));
+ assertEquals("two", ic.lookup("test:something"));
+ }
+
+ @Test
+ public void testURLContextErrorPropagation() throws Exception {
+ ObjectFactory of = new ObjectFactory() {
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+ Hashtable<?, ?> environment) throws Exception {
+ throw new Exception("doh");
+ }
+ };
+
+ registerURLObjectFactory(of, "test");
+ ic = initialContext();
+
+ try {
+ ic.lookup("test:something");
+ Assert.fail("Expected NamingException");
+ } catch (NamingException ne) {
+ assertNotNull(ne.getCause());
+ assertEquals("doh", ne.getCause().getMessage());
}
- };
-
- registerURLObjectFactory(of, "test");
- ic = initialContext();
-
- try {
- ic.lookup("test:something");
- Assert.fail("Expected NamingException");
- } catch (NamingException ne) {
- assertNotNull(ne.getCause());
- assertEquals("doh", ne.getCause().getMessage());
- }
- }
-
- /**
- * Create a minimal initial context with just the bundle context in the environment
- * @return
- * @throws Exception
- */
- private InitialContext initialContext() throws Exception {
- Properties props = new Properties();
- props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
- InitialContext ic = new InitialContext(props);
- return ic;
- }
-
- /**
- * Registers an ObjectFactory to be used for creating URLContexts for the given scheme
- * @param of
- * @param scheme
- */
- private void registerURLObjectFactory(ObjectFactory of, String scheme) {
- Properties props = new Properties();
- props.setProperty(JNDIConstants.JNDI_URLSCHEME, "test");
- bc.registerService(ObjectFactory.class.getName(), of, (Dictionary) props);
- }
-
- /**
- * Creates a context that always returns the given object
- * @param toReturn
- * @return
- */
- private Context dummyContext(Object toReturn) {
- Context ctx = Skeleton.newMock(Context.class);
- Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), toReturn);
- Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", Name.class), toReturn);
- return ctx;
- }
+ }
+
+ /**
+ * Create a minimal initial context with just the bundle context in the environment
+ * @return
+ * @throws Exception
+ */
+ private InitialContext initialContext() throws Exception {
+ Properties props = new Properties();
+ props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ InitialContext ic = new InitialContext(props);
+ return ic;
+ }
+
+ /**
+ * Registers an ObjectFactory to be used for creating URLContexts for the given scheme
+ * @param of
+ * @param scheme
+ */
+ private void registerURLObjectFactory(ObjectFactory of, String scheme) {
+ Properties props = new Properties();
+ props.setProperty(JNDIConstants.JNDI_URLSCHEME, "test");
+ bc.registerService(ObjectFactory.class.getName(), of, (Dictionary) props);
+ }
+
+ /**
+ * Creates a context that always returns the given object
+ * @param toReturn
+ * @return
+ */
+ private Context dummyContext(Object toReturn) {
+ Context ctx = Skeleton.newMock(Context.class);
+ Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), toReturn);
+ Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", Name.class), toReturn);
+ return ctx;
+ }
}
Modified: aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/ObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/ObjectFactoryTest.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/ObjectFactoryTest.java (original)
+++ aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/ObjectFactoryTest.java Wed Feb 21 09:04:41 2018
@@ -18,21 +18,6 @@
*/
package org.apache.aries.jndi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.naming.spi.NamingManager;
-import javax.naming.spi.ObjectFactory;
-
import org.apache.aries.jndi.startup.Activator;
import org.apache.aries.jndi.urls.URLObjectFactoryFinder;
import org.apache.aries.mocks.BundleContextMock;
@@ -44,177 +29,179 @@ import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.service.jndi.JNDIConstants;
-public class ObjectFactoryTest
-{
- private Activator activator;
- private BundleContext bc;
- private Hashtable<Object,Object> env;
-
- /**
- * This method does the setup .
- * @throws NoSuchFieldException
- * @throws SecurityException
- * @throws IllegalAccessException
- * @throws IllegalArgumentException
- */
- @Before
- public void setup() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
- {
- bc = Skeleton.newMock(new BundleContextMock(), BundleContext.class);
- activator = new Activator();
- activator.start(bc);
-
- env = new Hashtable<Object, Object>();
- env.put(JNDIConstants.BUNDLE_CONTEXT, bc);
- }
-
- /**
- * Make sure we clear the caches out before the next test.
- */
- @After
- public void teardown()
- {
- activator.stop(bc);
- BundleContextMock.clear();
- }
-
- @Test
- public void testURLReferenceWithNoMatchingHandler() throws Exception
- {
- Reference ref = new Reference(null);
- ref.add(new StringRefAddr("URL", "wibble"));
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertSame("The naming manager should have returned the reference object", ref, obj);
- }
-
- @Test
- public void testURLReferenceWithMatchingHandler() throws Exception
- {
- String testObject = "Test object";
- ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
- Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
-
- Properties props = new Properties();
- props.setProperty("osgi.jndi.urlScheme", "wibble");
-
- bc.registerService(ObjectFactory.class.getName(), factory, (Dictionary) props);
-
- Reference ref = new Reference(null);
- ref.add(new StringRefAddr("URL", "wibble"));
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertEquals("The naming manager should have returned the test object", testObject, obj);
- }
-
- @Test
- public void testURLReferenceUsingURLObjectFactoryFinder() throws Exception
- {
- String testObject = "Test object";
- URLObjectFactoryFinder factory = Skeleton.newMock(URLObjectFactoryFinder.class);
- Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
-
- bc.registerService(URLObjectFactoryFinder.class.getName(), factory, (Dictionary) new Properties());
-
- Reference ref = new Reference(null);
- ref.add(new StringRefAddr("URL", "wibble"));
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertEquals("The naming manager should have returned the test object", testObject, obj);
- }
-
- @Test
- public void testReferenceWithNoClassName() throws Exception
- {
- String testObject = "Test object";
- ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
- Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
-
- bc.registerService(ObjectFactory.class.getName(), factory, null);
-
- Reference ref = new Reference(null);
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertEquals("The naming manager should have returned the test object", testObject, obj);
- }
-
- @Test
- public void testSpecifiedFactoryWithMatchingFactory() throws Exception
- {
- String testObject = "Test object";
- ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
- Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
-
- Reference ref = new Reference("dummy.class.name", factory.getClass().getName(), "");
-
- bc.registerService(new String[] {ObjectFactory.class.getName(), factory.getClass().getName()},
- factory, null);
-
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertEquals("The naming manager should have returned the test object", testObject, obj);
- }
-
- @Test
- public void testSpecifiedFactoryWithRegisteredButNotMatchingFactory() throws Exception
- {
- String testObject = "Test object";
- ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
- Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
-
- Reference ref = new Reference("dummy.class.name", "dummy.factory.class.name", "");
-
- bc.registerService(new String[] {ObjectFactory.class.getName(), factory.getClass().getName()},
- factory, null);
-
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertSame("The naming manager should have returned the reference object", ref, obj);
- }
-
- @Test
- public void testSpecifiedFactoryWithNoMatchingFactory() throws Exception
- {
- Reference ref = new Reference("dummy.class.name");
-
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
-
- assertSame("The naming manager should have returned the reference object", ref, obj);
- }
-
- @Test
- public void testFactoriesThatDoUnsafeCastsAreIgnored() throws Exception {
- Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put("aries.object.factory.requires.reference", Boolean.TRUE);
- bc.registerService(ObjectFactory.class.getName(), new ObjectFactory() {
-
- public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3)
- throws Exception
- {
- return (Reference)arg0;
- }
- }, props);
-
- NamingManager.getObjectInstance("Some dummy data", null, null, env);
- }
-
- public static class DummyObjectFactory implements ObjectFactory {
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.NamingManager;
+import javax.naming.spi.ObjectFactory;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class ObjectFactoryTest {
+ private Activator activator;
+ private BundleContext bc;
+ private Hashtable<Object, Object> env;
+
+ /**
+ * This method does the setup .
+ *
+ * @throws NoSuchFieldException
+ * @throws SecurityException
+ * @throws IllegalAccessException
+ * @throws IllegalArgumentException
+ */
+ @Before
+ public void setup() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+ bc = Skeleton.newMock(new BundleContextMock(), BundleContext.class);
+ activator = new Activator();
+ activator.start(bc);
+
+ env = new Hashtable<Object, Object>();
+ env.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ }
+
+ /**
+ * Make sure we clear the caches out before the next test.
+ */
+ @After
+ public void teardown() {
+ activator.stop(bc);
+ BundleContextMock.clear();
+ }
+
+ @Test
+ public void testURLReferenceWithNoMatchingHandler() throws Exception {
+ Reference ref = new Reference(null);
+ ref.add(new StringRefAddr("URL", "wibble"));
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertSame("The naming manager should have returned the reference object", ref, obj);
+ }
+
+ @Test
+ public void testURLReferenceWithMatchingHandler() throws Exception {
+ String testObject = "Test object";
+ ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
+ Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
+
+ Properties props = new Properties();
+ props.setProperty("osgi.jndi.urlScheme", "wibble");
+
+ bc.registerService(ObjectFactory.class.getName(), factory, (Dictionary) props);
+
+ Reference ref = new Reference(null);
+ ref.add(new StringRefAddr("URL", "wibble"));
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertEquals("The naming manager should have returned the test object", testObject, obj);
+ }
+
+ @Test
+ public void testURLReferenceUsingURLObjectFactoryFinder() throws Exception {
+ String testObject = "Test object";
+ URLObjectFactoryFinder factory = Skeleton.newMock(URLObjectFactoryFinder.class);
+ Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
+
+ bc.registerService(URLObjectFactoryFinder.class.getName(), factory, (Dictionary) new Properties());
+
+ Reference ref = new Reference(null);
+ ref.add(new StringRefAddr("URL", "wibble"));
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertEquals("The naming manager should have returned the test object", testObject, obj);
+ }
+
+ @Test
+ public void testReferenceWithNoClassName() throws Exception {
+ String testObject = "Test object";
+ ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
+ Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
+
+ bc.registerService(ObjectFactory.class.getName(), factory, null);
+
+ Reference ref = new Reference(null);
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertEquals("The naming manager should have returned the test object", testObject, obj);
+ }
+
+ @Test
+ public void testSpecifiedFactoryWithMatchingFactory() throws Exception {
+ String testObject = "Test object";
+ ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
+ Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
+
+ Reference ref = new Reference("dummy.class.name", factory.getClass().getName(), "");
+
+ bc.registerService(new String[]{ObjectFactory.class.getName(), factory.getClass().getName()},
+ factory, null);
+
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertEquals("The naming manager should have returned the test object", testObject, obj);
+ }
+
+ @Test
+ public void testSpecifiedFactoryWithRegisteredButNotMatchingFactory() throws Exception {
+ String testObject = "Test object";
+ ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
+ Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
+
+ Reference ref = new Reference("dummy.class.name", "dummy.factory.class.name", "");
+
+ bc.registerService(new String[]{ObjectFactory.class.getName(), factory.getClass().getName()},
+ factory, null);
+
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertSame("The naming manager should have returned the reference object", ref, obj);
+ }
+
+ @Test
+ public void testSpecifiedFactoryWithNoMatchingFactory() throws Exception {
+ Reference ref = new Reference("dummy.class.name");
+
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+
+ assertSame("The naming manager should have returned the reference object", ref, obj);
+ }
+
+ @Test
+ public void testFactoriesThatDoUnsafeCastsAreIgnored() throws Exception {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("aries.object.factory.requires.reference", Boolean.TRUE);
+ bc.registerService(ObjectFactory.class.getName(), new ObjectFactory() {
+
+ public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3)
+ throws Exception {
+ return (Reference) arg0;
+ }
+ }, props);
+
+ NamingManager.getObjectInstance("Some dummy data", null, null, env);
+ }
+
+ @Test
+ public void testContextDotObjectFactories() throws Exception {
+ env.put(Context.OBJECT_FACTORIES, "org.apache.aries.jndi.ObjectFactoryTest$DummyObjectFactory");
+ Reference ref = new Reference("anything");
+ Object obj = NamingManager.getObjectInstance(ref, null, null, env);
+ assertTrue(obj instanceof String);
+ assertEquals((String) obj, "pass");
+ env.remove(Context.OBJECT_FACTORIES);
+ }
+
+ public static class DummyObjectFactory implements ObjectFactory {
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?, ?> environment) throws Exception {
+ Hashtable<?, ?> environment) throws Exception {
// TODO Auto-generated method stub
- return new String ("pass");
+ return new String("pass");
}
- }
-
- @Test
- public void testContextDotObjectFactories() throws Exception {
- env.put(Context.OBJECT_FACTORIES, "org.apache.aries.jndi.ObjectFactoryTest$DummyObjectFactory");
- Reference ref = new Reference("anything");
- Object obj = NamingManager.getObjectInstance(ref, null, null, env);
- assertTrue (obj instanceof String);
- assertEquals ((String)obj, "pass");
- env.remove(Context.OBJECT_FACTORIES);
- }
+ }
}
\ No newline at end of file
Modified: aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java (original)
+++ aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -18,20 +18,20 @@
*/
package org.apache.aries.jndi.legacy.support;
-import javax.naming.spi.InitialContextFactoryBuilder;
-
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-public class Activator implements BundleActivator {
+import javax.naming.spi.InitialContextFactoryBuilder;
- @Override
- public void start(BundleContext context) throws Exception
- {
- context.registerService(InitialContextFactoryBuilder.class.getName(), new LegacyInitialContextFinder(), null);
- }
+public class Activator implements BundleActivator {
- @Override
- public void stop(BundleContext context) throws Exception { }
+ @Override
+ public void start(BundleContext context) throws Exception {
+ context.registerService(InitialContextFactoryBuilder.class.getName(), new LegacyInitialContextFinder(), null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ }
}
Modified: aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java (original)
+++ aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -18,14 +18,13 @@
*/
package org.apache.aries.jndi.legacy.support;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Hashtable;
-
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import javax.naming.spi.InitialContextFactoryBuilder;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Hashtable;
/**
* Some OSGi based server runtimes, such as jetty OSGi and virgo rely on the thread context classloader
@@ -39,32 +38,31 @@ import javax.naming.spi.InitialContextFa
*/
public class LegacyInitialContextFinder implements InitialContextFactoryBuilder {
- public InitialContextFactory createInitialContextFactory(
- Hashtable<?, ?> environment) throws NamingException
- {
- String icf = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
- if (icf != null) {
- ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
-
- try {
- Class<?> icfClass = Class.forName(icf, false, cl);
- if (InitialContextFactory.class.isAssignableFrom(icfClass)) {
- return (InitialContextFactory) icfClass.newInstance();
- }
- } catch (ClassNotFoundException e) {
- // If the ICF doesn't exist this is expected. Should return null so the next builder is queried.
- } catch (InstantiationException e) {
- // If the ICF couldn't be created just ignore and return null.
- } catch (IllegalAccessException e) {
- // If the default constructor is private, just ignore and return null.
- }
- }
-
- return null;
- }
+ public InitialContextFactory createInitialContextFactory(
+ Hashtable<?, ?> environment) throws NamingException {
+ String icf = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
+ if (icf != null) {
+ ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+
+ try {
+ Class<?> icfClass = Class.forName(icf, false, cl);
+ if (InitialContextFactory.class.isAssignableFrom(icfClass)) {
+ return (InitialContextFactory) icfClass.newInstance();
+ }
+ } catch (ClassNotFoundException e) {
+ // If the ICF doesn't exist this is expected. Should return null so the next builder is queried.
+ } catch (InstantiationException e) {
+ // If the ICF couldn't be created just ignore and return null.
+ } catch (IllegalAccessException e) {
+ // If the default constructor is private, just ignore and return null.
+ }
+ }
+
+ return null;
+ }
}
Modified: aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java (original)
+++ aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java Wed Feb 21 09:04:41 2018
@@ -18,11 +18,6 @@
*/
package org.apache.aries.jndi.rmi;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import javax.naming.spi.ObjectFactory;
-
import org.apache.aries.util.AriesFrameworkUtil;
import org.apache.aries.util.nls.MessageUtil;
import org.osgi.framework.BundleActivator;
@@ -32,11 +27,14 @@ import org.osgi.service.jndi.JNDIConstan
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class Activator implements BundleActivator {
+import javax.naming.spi.ObjectFactory;
+import java.util.Dictionary;
+import java.util.Hashtable;
- private ServiceRegistration reg;
+public class Activator implements BundleActivator {
private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class.getName());
+ private ServiceRegistration reg;
public void start(BundleContext context) {
@@ -44,14 +42,12 @@ public class Activator implements Bundle
try {
Hashtable<Object, Object> props = new Hashtable<Object, Object>();
- props.put(JNDIConstants.JNDI_URLSCHEME, new String[] { "rmi" });
+ props.put(JNDIConstants.JNDI_URLSCHEME, new String[]{"rmi"});
reg = context.registerService(
- ObjectFactory.class.getName(),
- ClassLoader.getSystemClassLoader().loadClass("com.sun.jndi.url.rmi.rmiURLContextFactory").newInstance(),
- (Dictionary) props);
- }
- catch (Exception e)
- {
+ ObjectFactory.class.getName(),
+ ClassLoader.getSystemClassLoader().loadClass("com.sun.jndi.url.rmi.rmiURLContextFactory").newInstance(),
+ (Dictionary) props);
+ } catch (Exception e) {
MessageUtil msg = MessageUtil.createMessageUtil(Activator.class, "org.apache.aries.jndi.nls.jndiRmiMessages");
LOGGER.info(msg.getMessage("rmi.factory.creation.failed"), e);
}
Modified: aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/JndiUrlItestServlet.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/JndiUrlItestServlet.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/JndiUrlItestServlet.java (original)
+++ aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/JndiUrlItestServlet.java Wed Feb 21 09:04:41 2018
@@ -19,44 +19,42 @@
package org.apache.aries.jndiurl.itest;
-import java.io.IOException;
-import java.util.List;
+import org.apache.aries.jndiurl.itest.beans.ConfigBean;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
-import org.apache.aries.jndiurl.itest.beans.ConfigBean;
-
-public class JndiUrlItestServlet extends HttpServlet{
+public class JndiUrlItestServlet extends HttpServlet {
- private static final long serialVersionUID = -4610850218411296469L;
+ private static final long serialVersionUID = -4610850218411296469L;
- @Override
- public void doGet (HttpServletRequest req, HttpServletResponse resp) throws IOException
- {
- StringBuilder result = new StringBuilder();
- try {
- InitialContext ctx = new InitialContext();
- ConfigBean cb = (ConfigBean) ctx.lookup("blueprint:comp/config");
- result.append(cb.getSimple().getOwner());
- result.append(".");
- result.append(cb.getVersion()); // Expected output is now "Mark.2.0"
-
- // Now lookup and use a service published from another bundle
- @SuppressWarnings("unchecked")
- List<String> listService = (List<String>) ctx.lookup("blueprint:comp/listRef");
- result.append(".");
- String thirdListEntry = listService.get(2);
- result.append(thirdListEntry);
- } catch (NamingException nx) {
- IOException ex = new IOException (nx.getMessage());
- ex.initCause(nx);
- throw ex;
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ StringBuilder result = new StringBuilder();
+ try {
+ InitialContext ctx = new InitialContext();
+ ConfigBean cb = (ConfigBean) ctx.lookup("blueprint:comp/config");
+ result.append(cb.getSimple().getOwner());
+ result.append(".");
+ result.append(cb.getVersion()); // Expected output is now "Mark.2.0"
+
+ // Now lookup and use a service published from another bundle
+ @SuppressWarnings("unchecked")
+ List<String> listService = (List<String>) ctx.lookup("blueprint:comp/listRef");
+ result.append(".");
+ String thirdListEntry = listService.get(2);
+ result.append(thirdListEntry);
+ } catch (NamingException nx) {
+ IOException ex = new IOException(nx.getMessage());
+ ex.initCause(nx);
+ throw ex;
+ }
+ resp.getWriter().print(result.toString());
+ resp.getWriter().close();
}
- resp.getWriter().print(result.toString());
- resp.getWriter().close();
- }
}
Modified: aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/ConfigBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/ConfigBean.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/ConfigBean.java (original)
+++ aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/ConfigBean.java Wed Feb 21 09:04:41 2018
@@ -20,23 +20,23 @@
package org.apache.aries.jndiurl.itest.beans;
public class ConfigBean {
-
- SimpleBean _simple;
- String _version;
-
- public SimpleBean getSimple() {
- return _simple;
- }
-
- public void setSimple (SimpleBean s) {
- _simple = s;
- }
-
- public String getVersion() {
- return _version;
- }
-
- public void setVersion(String v) {
- _version = v;
- }
+
+ SimpleBean _simple;
+ String _version;
+
+ public SimpleBean getSimple() {
+ return _simple;
+ }
+
+ public void setSimple(SimpleBean s) {
+ _simple = s;
+ }
+
+ public String getVersion() {
+ return _version;
+ }
+
+ public void setVersion(String v) {
+ _version = v;
+ }
}
Modified: aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/SimpleBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/SimpleBean.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/SimpleBean.java (original)
+++ aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/SimpleBean.java Wed Feb 21 09:04:41 2018
@@ -21,13 +21,13 @@ package org.apache.aries.jndiurl.itest.b
public class SimpleBean {
- private String _owner;
-
- public void setOwner (String s) {
- _owner = s;
- }
-
- public String getOwner() {
- return _owner;
- }
+ private String _owner;
+
+ public String getOwner() {
+ return _owner;
+ }
+
+ public void setOwner(String s) {
+ _owner = s;
+ }
}