List of usage examples for javax.naming Context getEnvironment
public Hashtable<?, ?> getEnvironment() throws NamingException;
From source file:org.wso2.carbon.deployment.notifier.internal.JMSUtils.java
/** * Return the JMS destination with the given destination name looked up from the context * Borrowed generiously from axis2 jms transport implementation * * @param context the Context to lookup//from ww w . j a va2 s .c om * @param destinationName name of the destination to be looked up * @param destinationType type of the destination to be looked up * @return the JMS destination, or null if it does not exist */ public static Destination lookupDestination(Context context, String destinationName, String destinationType) throws NamingException { try { return lookup(context, Destination.class, destinationName); } catch (NameNotFoundException e) { Properties initialContextProperties = new Properties(); if (context.getEnvironment() != null) { if (context.getEnvironment().get(Context.INITIAL_CONTEXT_FACTORY) != null) { initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY, context.getEnvironment().get(Context.INITIAL_CONTEXT_FACTORY)); } if (context.getEnvironment().get(Context.PROVIDER_URL) != null) { initialContextProperties.put(Context.PROVIDER_URL, context.getEnvironment().get(Context.PROVIDER_URL)); } } if (Constants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(Constants.TOPIC_PREFIX + destinationName, destinationName); } else { initialContextProperties.put(Constants.QUEUE_PREFIX + destinationName, destinationName); } InitialContext initialContext = new InitialContext(initialContextProperties); try { return lookup(initialContext, Destination.class, destinationName); } catch (NamingException e1) { return lookup(context, Destination.class, (Constants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType) ? "dynamicTopics/" : "dynamicQueues/") + destinationName); } } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSUtils.java
/** * Return the JMS destination with the given destination name looked up from the context * * @param context the Context to lookup * @param destinationName name of the destination to be looked up * @param destinationType type of the destination to be looked up * @return the JMS destination, or null if it does not exist *//*w w w. ja v a 2 s . c om*/ public static Destination lookupDestination(Context context, String destinationName, String destinationType) throws NamingException { if (destinationName == null) { return null; } try { return JMSUtils.lookup(context, Destination.class, destinationName); } catch (NameNotFoundException e) { try { Properties initialContextProperties = new Properties(); if (context.getEnvironment() != null) { if (context.getEnvironment().get(JMSConstants.NAMING_FACTORY_INITIAL) != null) { initialContextProperties.put(JMSConstants.NAMING_FACTORY_INITIAL, context.getEnvironment().get(JMSConstants.NAMING_FACTORY_INITIAL)); } if (context.getEnvironment().get(JMSConstants.CONNECTION_STRING) != null) { initialContextProperties.put(JMSConstants.CONNECTION_STRING, context.getEnvironment().get(JMSConstants.CONNECTION_STRING)); } if (context.getEnvironment().get(JMSConstants.PROVIDER_URL) != null) { initialContextProperties.put(JMSConstants.PROVIDER_URL, context.getEnvironment().get(JMSConstants.PROVIDER_URL)); } } if (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(JMSConstants.TOPIC_PREFIX + destinationName, destinationName); } else if (JMSConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(destinationType) || JMSConstants.DESTINATION_TYPE_GENERIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(JMSConstants.QUEUE_PREFIX + destinationName, destinationName); } InitialContext initialContext = new InitialContext(initialContextProperties); try { return JMSUtils.lookup(initialContext, Destination.class, destinationName); } catch (NamingException e1) { return JMSUtils.lookup(context, Destination.class, (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType) ? "dynamicTopics/" : "dynamicQueues/") + destinationName); } } catch (NamingException x) { log.warn("Cannot locate destination : " + destinationName); throw x; } } catch (NamingException e) { log.warn("Cannot locate destination : " + destinationName, e); throw e; } }
From source file:org.wso2.intcloud.tierapi.util.DataSourceJDBC.java
public static Connection getConnection() { Connection conn = null;/*from ww w. j a v a2s . c om*/ try { Context initCtx = new InitialContext(); SelectorContext selectorContext = new SelectorContext( (Hashtable<String, Object>) initCtx.getEnvironment(), false); Context envCtx = (Context) selectorContext.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/WSO2IntCloud"); conn = ds.getConnection(); } catch (NamingException e) { String msg = "Error while connecting to Data Source "; log.error(msg, e); } catch (SQLException e) { String msg = "Error while getting connection to Data Base "; log.error(msg, e); } return conn; }