InitialContext context = new InitialContext(); //initialize a new JNDI context context.addToEnvironment("logback/configuration-resource","logback.xml)"; //add a new named entry
public JmsClient( final InitialContext context, final String defaultConnectionFactoryName, final String brokerURI ) throws NamingException { this.context = new InitialContext(context.getEnvironment()); this.defaultConnectionFactoryName = defaultConnectionFactoryName; this.brokerURI = brokerURI; if (this.brokerURI != null) { this.context.addToEnvironment(Context.PROVIDER_URL, this.brokerURI); } }
/** * (non-Javadoc). * * @see javax.naming.InitialContext#addToEnvironment(java.lang.String, * java.lang.Object) * @param propName * the name * @param propVal * the value * @throws NamingException * impossible to add to environment * @return the associated object */ @Override public Object addToEnvironment(final String propName, final Object propVal) throws NamingException { Object out; if (this.initialContext == null) { myProps.put(propName, propVal); out = this.defaultInitCtx.addToEnvironment(propName, propVal); } else { out = this.initialContext.addToEnvironment(propName, propVal); } return out; }
/** * (non-Javadoc). * * @see javax.naming.InitialContext#addToEnvironment(java.lang.String, * java.lang.Object) * @param propName * the name * @param propVal * the value * @throws NamingException * impossible to add to environment * @return the associated object */ @Override public Object addToEnvironment(final String propName, final Object propVal) throws NamingException { Object out; if (this.initialContext == null) { myProps.put(propName, propVal); out = this.defaultInitCtx.addToEnvironment(propName, propVal); } else { out = this.initialContext.addToEnvironment(propName, propVal); } return out; }
/** * {@inheritDoc} */ public Object addToEnvironment(String propName, Object propVal) throws NamingException { if (isInitialContextInitializerCall()) { return super.addToEnvironment(propName, propVal); } return getContext().addToEnvironment(propName, propVal); }
/** * @param subject the subject to set */ public void setSubject(Subject subject) { auth = new Authorization(subject); /* * for server side checks (e.g. sessioncontext.getCallerPrincipal()), we have to add * the SECURITY_PRINCIPAL to the initial context additionally, the server has to know, * which security domain to use - in jboss we do that in login-conf.xml. the application should * define a jboss.xml inside it's META-INF - perhaps using the 'client-login'. */ try { final Set<UserPrincipal> userPrincipals = subject != null ? subject.getPrincipals(UserPrincipal.class) : null; final UserPrincipal userPrincipal = userPrincipals != null && userPrincipals.size() > 0 ? userPrincipals.iterator() .next() : null; if (userPrincipal == null) { LOG.warn("No user principal defined --> services are not able to retrieve sessioncontext.getCallerPrincipal"); if (getServiceLocator().getInitialContext() != null) getServiceLocator().getInitialContext().removeFromEnvironment(Context.SECURITY_PRINCIPAL); } else { if (getServiceLocator().getInitialContext() != null) getServiceLocator().getInitialContext().addToEnvironment(Context.SECURITY_PRINCIPAL, userPrincipal); } } catch (final Exception e) { ManagedException.forward(e); } }