public Object doInContext(Context ctx) throws NamingException { ctx.rebind(name, object); return null; } });
@Override protected void doOperation(String name, Object object) throws NamingException { localContext.rebind(name, object); } }
@Override public void rebind(String name, Object obj) throws NamingException { context.rebind(name, obj); }
@Override public void rebind(Name name, Object obj) throws NamingException { context.rebind(name, obj); }
/** * Rebind the given object to the current JNDI context, using the given name. * Overwrites any existing binding. * @param name the JNDI name of the object * @param object the object to rebind * @throws NamingException thrown by JNDI */ public void rebind(final String name, final Object object) throws NamingException { if (logger.isDebugEnabled()) { logger.debug("Rebinding JNDI object with name [" + name + "]"); } execute(ctx -> { ctx.rebind(name, object); return null; }); }
/** * Rebind the given object to the current JNDI context, using the given name. * Overwrites any existing binding. * @param name the JNDI name of the object * @param object the object to rebind * @throws NamingException thrown by JNDI */ public void rebind(final String name, final Object object) throws NamingException { if (logger.isDebugEnabled()) { logger.debug("Rebinding JNDI object with name [" + name + "]"); } execute(ctx -> { ctx.rebind(name, object); return null; }); }
@Override public void rebind(final String name, final Object obj) throws NamingException { CNCtxFactory.INSTANCE.getInitialContext(environment).rebind(name, obj); }
@Override public void rebind(final Name name, final Object obj) throws NamingException { CNCtxFactory.INSTANCE.getInitialContext(environment).rebind(name, obj); }
private static void validateAndBindDataSource(Context context, String jndiName, DataSource dataSource) throws NamingException, DataSourceCreateException { try (Connection connection = dataSource.getConnection()) { } catch (SQLException sqlEx) { closeDataSource(dataSource); throw new DataSourceCreateException( "Failed to connect to \"" + jndiName + "\". See log for details", sqlEx); } context.rebind("java:/" + jndiName, dataSource); dataSourceMap.put(jndiName, dataSource); if (logger.isDebugEnabled()) { logger.debug("Bound java:/" + jndiName + " to Context"); } }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
@Override public void rebind(final Name name, final Object obj) throws NamingException { Assert.checkNotNullParam("name", name); final ReparsedName reparsedName = reparse(name); ContextResult result = getProviderContext(reparsedName.getUrlScheme()); if(result.oldStyle) { result.context.rebind(name, obj); } else { result.context.rebind(reparsedName.getName(), obj); } }
@Override public void rebind(final String name, final Object obj) throws NamingException { Assert.checkNotNullParam("name", name); final ReparsedName reparsedName = reparse(getNameParser().parse(name)); ContextResult result = getProviderContext(reparsedName.getUrlScheme()); if(result.oldStyle) { result.context.rebind(name, obj); } else { result.context.rebind(reparsedName.getName(), obj); } }
/** * Rebind val to name in ctx, and make sure that all intermediate contexts exist * * @param ctx the parent JNDI Context under which value will be bound * @param name the name relative to ctx where value will be bound * @param value the value to bind. * @throws NamingException for any error */ public static void rebind(final Context ctx, final Name name, final Object value) throws NamingException { final int size = name.size(); final String atom = name.get(size - 1); final Context parentCtx = createSubcontext(ctx, name.getPrefix(size - 1)); parentCtx.rebind(atom, value); }
@Test public void testRebind() 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.rebind(name, o); verify(context).rebind(name, o); verify(context).close(); }
@Test public void mapDataSourceWithGetConnectionSuccessClosesConnectionAndRebinds() throws Exception { Map<String, String> inputs = new HashMap<>(); Context context = mock(Context.class); DataSource dataSource = mock(DataSource.class); Connection connection = mock(Connection.class); when(dataSource.getConnection()).thenReturn(connection); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); when(dataSourceFactory.getSimpleDataSource(any())).thenReturn(dataSource); inputs.put("type", "SimpleDataSource"); String jndiName = "myJndiBinding"; inputs.put("jndi-name", jndiName); JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context); verify(connection).close(); verify(context).rebind((String) any(), same(dataSource)); } }
@Test public void mapDataSourceWithGetConnectionExceptionThrowsDataSourceCreateException() throws Exception { Map<String, String> inputs = new HashMap<>(); Context context = mock(Context.class); DataSource dataSource = mock(DataSource.class); SQLException exception = mock(SQLException.class); doThrow(exception).when(dataSource).getConnection(); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); when(dataSourceFactory.getSimpleDataSource(any())).thenReturn(dataSource); inputs.put("type", "SimpleDataSource"); String jndiName = "myJndiBinding"; inputs.put("jndi-name", jndiName); Throwable thrown = catchThrowable(() -> JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context)); assertThat(thrown).isInstanceOf(DataSourceCreateException.class) .hasMessage("Failed to connect to \"" + jndiName + "\". See log for details"); verify(context, never()).rebind((String) any(), any()); }
public void rebind(Name name, Object object) throws NamingException { final ParsedName parsedName = parse(name); final Context namespaceContext = findContext(name, parsedName); if (namespaceContext == null) super.rebind(parsedName.remaining(), object); else namespaceContext.rebind(parsedName.remaining(), object); }
context1.rebind("myinteger", i); String s = ""; context2.bind("mystring", s);
/** * Converts the "Name" name into a NameComponent[] object and * performs the rebind operation. Uses callBindOrRebind. Throws an * invalid name exception if the name is empty. We must have a name * to rebind the object to even if we are working within the current * context. * * @param name string * @param obj Object to be bound. * @throws NamingException See callBindOrRebind */ public void rebind(Name name, java.lang.Object obj) throws NamingException { if (name.size() == 0) { throw IIOPLogger.ROOT_LOGGER.invalidEmptyName(); } NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name); try { callBindOrRebind(path, name, obj, true); } catch (CannotProceedException e) { javax.naming.Context cctx = getContinuationContext(e); cctx.rebind(e.getRemainingName(), obj); } }
public void rebind(final Name name, final Object obj) throws NamingException { Assert.checkNotNullParam("name", name); if (name.isEmpty()) { throw log.invalidEmptyName(); } if (name instanceof CompositeName) { final String first = name.get(0); final Name firstName = getNativeNameParser().parse(first); if (name.size() == 1) { rebindNative(firstName, obj); return; } final Object next = lookup(firstName); if (next instanceof Context) { final Context context = (Context) next; try { context.rebind(name.getSuffix(1), obj); } finally { NamingUtils.safeClose(context); } } else { throw log.notContextInCompositeName(first); } } else { rebindNative(name, obj); } }