/** * Configure a {@code JndiLocatorDelegate} with its "resourceRef" property set to * {@code true}, meaning that all names will be prefixed with "java:comp/env/". * @see #setResourceRef */ public static JndiLocatorDelegate createDefaultResourceRefLocator() { JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); return jndiLocator; }
/** * Configure a {@code JndiLocatorDelegate} with its "resourceRef" property set to * {@code true}, meaning that all names will be prefixed with "java:comp/env/". * @see #setResourceRef */ public static JndiLocatorDelegate createDefaultResourceRefLocator() { JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); return jndiLocator; }
@Override public MBeanServer getMBeanServer() { try { return new JndiLocatorDelegate().lookup("java:comp/env/jmx/runtime", MBeanServer.class); } catch (NamingException ex) { throw new MBeanServerNotFoundException("Failed to retrieve WebLogic MBeanServer from JNDI", ex); } } },
@Override public MBeanServer getMBeanServer() { try { return new JndiLocatorDelegate().lookup("java:comp/env/jmx/runtime", MBeanServer.class); } catch (NamingException ex) { throw new MBeanServerNotFoundException("Failed to retrieve WebLogic MBeanServer from JNDI", ex); } } },
public <T> T lookup(String jndiName, Class<T> requiredType) throws Exception { JndiLocatorDelegate locator = new JndiLocatorDelegate(); if (jndiEnvironment instanceof JndiTemplate) { locator.setJndiTemplate((JndiTemplate) jndiEnvironment); } else if (jndiEnvironment instanceof Properties) { locator.setJndiEnvironment((Properties) jndiEnvironment); } else if (jndiEnvironment != null) { throw new IllegalStateException("Illegal 'jndiEnvironment' type: " + jndiEnvironment.getClass()); } locator.setResourceRef(resourceRef); return locator.lookup(jndiName, requiredType); } }
public <T> T lookup(String jndiName, Class<T> requiredType) throws Exception { JndiLocatorDelegate locator = new JndiLocatorDelegate(); if (jndiEnvironment instanceof JndiTemplate) { locator.setJndiTemplate((JndiTemplate) jndiEnvironment); } else if (jndiEnvironment instanceof Properties) { locator.setJndiEnvironment((Properties) jndiEnvironment); } else if (jndiEnvironment != null) { throw new IllegalStateException("Illegal 'jndiEnvironment' type: " + jndiEnvironment.getClass()); } locator.setResourceRef(resourceRef); return locator.lookup(jndiName, requiredType); } }
@Test public void nameBoundWithPrefix() { final SimpleNamingContext context = new SimpleNamingContext(); context.bind("java:comp/env/p1", "v1"); JndiTemplate jndiTemplate = new JndiTemplate() { @Override protected Context createInitialContext() throws NamingException { return context; } }; JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); jndiLocator.setJndiTemplate(jndiTemplate); JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); assertThat(ps.getProperty("p1"), equalTo("v1")); }
@Test public void nameBoundWithoutPrefix() { final SimpleNamingContext context = new SimpleNamingContext(); context.bind("p1", "v1"); JndiTemplate jndiTemplate = new JndiTemplate() { @Override protected Context createInitialContext() throws NamingException { return context; } }; JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); jndiLocator.setJndiTemplate(jndiTemplate); JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator); assertThat(ps.getProperty("p1"), equalTo("v1")); }
/** * Configure a {@code JndiLocatorDelegate} with its "resourceRef" property set to * {@code true}, meaning that all names will be prefixed with "java:comp/env/". * @see #setResourceRef */ public static JndiLocatorDelegate createDefaultResourceRefLocator() { JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); jndiLocator.setResourceRef(true); return jndiLocator; }
@Override public MBeanServer getMBeanServer() { try { return new JndiLocatorDelegate().lookup("java:comp/env/jmx/runtime", MBeanServer.class); } catch (NamingException ex) { throw new MBeanServerNotFoundException("Failed to retrieve WebLogic MBeanServer from JNDI", ex); } } },
public <T> T lookup(String jndiName, Class<T> requiredType) throws Exception { JndiLocatorDelegate locator = new JndiLocatorDelegate(); if (jndiEnvironment instanceof JndiTemplate) { locator.setJndiTemplate((JndiTemplate) jndiEnvironment); } else if (jndiEnvironment instanceof Properties) { locator.setJndiEnvironment((Properties) jndiEnvironment); } else if (jndiEnvironment != null) { throw new IllegalStateException("Illegal 'jndiEnvironment' type: " + jndiEnvironment.getClass()); } locator.setResourceRef(resourceRef); return locator.lookup(jndiName, requiredType); } }