Java Code Examples for org.springframework.jndi.JndiLookupFailureException

Following code examples demonstrate how to use org.springframework.jndi.JndiLookupFailureExceptionfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.jndi.JndiLookupFailureExceptionand various code implementation of this class.

        synchronized (this) {
            if (context == null) {
                try {
                    context = new InitialContext();
                } catch (NamingException ex) {
                    throw new JndiLookupFailureException("Couldn't create InitialContext - oh bugger", ex);
                }
            }
        } 


    protected Object getContextVariable(String varName) throws JndiLookupFailureException {
        try {
            if (!varName.startsWith(COMP_ENV_JNDI_PREFIX)) {
                varName = COMP_ENV_JNDI_PREFIX + varName;
            }
            return getContext().lookup(varName);
        } catch (NamingException ex) {
            throw new JndiLookupFailureException(varName, ex);
        }
    } 

	public void sendMessage(String destName, MessageCreator messageCreator) {
		try {
			Destination des = (Destination) jndiTemplate.lookup(destName);
			this.getJmsTemplate().send(des, messageCreator);
		} catch (NamingException ex) {
			logger.error(ex);
			throw new JndiLookupFailureException(destName + " Ѱ�Ҵ���", ex);
		}
	} 

	public Message receiverMessage(String destName, String selector) {
		Message mes = null;
		try {
			Destination des = (Destination) jndiTemplate.lookup(destName);
			if (selector == null) {
				mes = this.getJmsTemplate().receive(des);
			} else {
				mes = this.getJmsTemplate().receiveSelected(des, selector);
			}
			return mes;
		} catch (NamingException ex) {
			logger.error(ex);
			throw new JndiLookupFailureException(destName + " Ѱ�Ҵ���", ex);
		}
	} 

				public Object doInJms(Session session) throws JMSException {
					QueueBrowser browser = null;
					List messages = new ArrayList();
					if (selector != null) {
						browser = session.createBrowser((Queue) des, selector);
					} else {
						browser = session.createBrowser((Queue) des);
					}
					Enumeration enu = browser.getEnumeration();
					while (enu.hasMoreElements()) {
						messages.add(enu.nextElement());
					}
					browser.close();
					return messages;
				} 

	protected boolean retrieveTransactionType() {
		try {
			Boolean txType = (Boolean) getContextVariable("containerTransactions");
			if (txType == null) {
				log.warn("Value of variable 'containerTransactions' in Bean JNDI context is null, assuming bean-managed transactions");
				return false;
			} else {
				return txType.booleanValue();
			}
		} catch (JndiLookupFailureException e) {
			log.error("Cannot look up variable 'containerTransactions' in Bean JNDI context; assuming bean-managed transactions", e);
			return false;
		}
	} 

	public FactoryBean<Object> dataSource() {
		val jndiObjectFactoryBean = new JndiObjectFactoryBean();
		jndiObjectFactoryBean.setJndiName(env.getProperty("datasource.name"));
		jndiObjectFactoryBean.setResourceRef(true);
		jndiObjectFactoryBean.setProxyInterface(DataSource.class);
		try {
			jndiObjectFactoryBean.afterPropertiesSet();
		} catch (NamingException e) {
			throw new JndiLookupFailureException("DataSource is not found", e);
		}
		return jndiObjectFactoryBean;
	} 

Advertisement
Javadoc
RuntimeException to be thrown in case of JNDI lookup failures, in particular from code that does not

declare JNDI's checked javax.naming.NamingException: for example, from Spring's JndiObjectTargetSource. @author Juergen Hoeller @since 2.0.3

Read More
Advertisement