@Test public void testBind() throws Exception { Object o = new Object(); String name = "foo"; final Context context = mock(Context.class); JndiTemplate jt = new JndiTemplate() { @Override protected Context createInitialContext() { return context; } }; jt.bind(name, o); verify(context).bind(name, o); verify(context).close(); }
public class JndiExporter implements InitializingBean { private final JndiTemplate template = new JndiTemplate(); private Map<String, Object> jndiMapping = null; @Override public void afterPropertiesSet() throws Exception { for(Entry<String, Object> addToJndi: jndiMapping.entrySet()){ template.bind(addToJndi.getKey(), addToJndi.getValue()); } } public void setJndiMapping(Map<String, Object> jndiMapping) { this.jndiMapping = jndiMapping; } }
public void afterPropertiesSet() throws NamingException { logger.info("Binding " + BONITA_NON_MANAGED_DS_JNDI_NAME + " @ " + datasource.toString()); jndiTemplate.bind(BONITA_NON_MANAGED_DS_JNDI_NAME, datasource); }
public void afterPropertiesSet() throws NamingException { logger.info("Binding " + BONITA_NON_MANAGED_DS_JNDI_NAME + " @ " + datasource.toString()); jndiTemplate.bind(BONITA_NON_MANAGED_DS_JNDI_NAME, datasource); }
public void init() throws NamingException { for (final Map.Entry<String, Object> addToJndi : jndiMapping.entrySet()) { logger.info("Binding " + addToJndi.getKey() + " @ " + addToJndi.getValue()); try { jndiTemplate.bind(addToJndi.getKey(), addToJndi.getValue()); } catch (NameAlreadyBoundException ignored) { logger.info(addToJndi.getKey() + " @ " + addToJndi.getValue() + " was already bound"); } } }
public JNDIExporter export (String key, Object value) { log.info("export: method begins; key: " + key + ", value '" + value); try { jndiTemplate.bind(key, value); } catch (NamingException namingException) { throw new BindFailedException(key, value, namingException); } log.info("export: method ends."); return this; } }