List of usage examples for javax.jms QueueConnectionFactory createQueueConnection
QueueConnection createQueueConnection(String userName, String password) throws JMSException;
From source file:org.wso2.carbon.apimgt.jms.listener.utils.JMSUtils.java
/** * This is a JMS spec independent method to create a Connection. Please be cautious when * making any changes/*from w w w . j a v a 2 s .c o m*/ * * @param conFac the ConnectionFactory to use * @param user optional user name * @param pass optional password * @param jmsSpec11 should we use JMS 1.1 API ? * @param isQueue is this to deal with a Queue? * @param isDurable whether the messaging provider is durable * @param clientID durable subscriber client id * @return a JMS Connection as requested * @throws JMSException on errors, to be handled and logged by the caller */ public static Connection createConnection(ConnectionFactory conFac, String user, String pass, boolean jmsSpec11, Boolean isQueue, boolean isDurable, String clientID) throws JMSException { Connection connection = null; if (log.isDebugEnabled()) { log.debug("Creating a " + (isQueue ? "Queue" : "Topic") + "Connection using credentials : (" + user + "/" + pass + ")"); } if (jmsSpec11 || isQueue == null) { if (user != null && pass != null) { connection = conFac.createConnection(user, pass); } else { connection = conFac.createConnection(); } if (isDurable) { connection.setClientID(clientID); } } else { QueueConnectionFactory qConFac = null; TopicConnectionFactory tConFac = null; if (isQueue) { qConFac = (QueueConnectionFactory) conFac; } else { tConFac = (TopicConnectionFactory) conFac; } if (user != null && pass != null) { if (qConFac != null) { connection = qConFac.createQueueConnection(user, pass); } else if (tConFac != null) { connection = tConFac.createTopicConnection(user, pass); } } else { if (qConFac != null) { connection = qConFac.createQueueConnection(); } else if (tConFac != null) { connection = tConFac.createTopicConnection(); } } if (isDurable) { connection.setClientID(clientID); } } return connection; }
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * This is a JMS spec independent method to create a Connection. Please be cautious when * making any changes//from www .ja v a 2 s. c om * * @param conFac the ConnectionFactory to use * @param user optional user name * @param pass optional password * @param jmsSpec11 should we use JMS 1.1 API ? * @param isQueue is this to deal with a Queue? * @return a JMS Connection as requested * @throws JMSException on errors, to be handled and logged by the caller */ public static Connection createConnection(ConnectionFactory conFac, String user, String pass, boolean jmsSpec11, Boolean isQueue) throws JMSException { Connection connection = null; if (log.isDebugEnabled()) { log.debug("Creating a " + (isQueue == null ? "Generic" : isQueue ? "Queue" : "Topic") + "Connection using credentials : (" + user + "/" + pass + ")"); } if (jmsSpec11 || isQueue == null) { if (user != null && pass != null) { connection = conFac.createConnection(user, pass); } else { connection = conFac.createConnection(); } } else { QueueConnectionFactory qConFac = null; TopicConnectionFactory tConFac = null; if (isQueue) { qConFac = (QueueConnectionFactory) conFac; } else { tConFac = (TopicConnectionFactory) conFac; } if (user != null && pass != null) { if (qConFac != null) { connection = qConFac.createQueueConnection(user, pass); } else if (tConFac != null) { connection = tConFac.createTopicConnection(user, pass); } } else { if (qConFac != null) { connection = qConFac.createQueueConnection(); } else if (tConFac != null) { connection = tConFac.createTopicConnection(); } } } return connection; }
From source file:org.smartfrog.avalanche.shared.jms.MessageListener.java
public void init() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.mom4j.jndi.InitialCtxFactory"); p.put(Context.PROVIDER_URL, "xcp://" + serverName + ":" + port); Context ctx = null;/*from w ww . j av a 2 s.c om*/ try { ctx = new InitialContext(p); QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory"); queue = (Queue) ctx.lookup(queueName); qc = qcf.createQueueConnection(userName, password); } finally { if (ctx != null) { ctx.close(); } } }
From source file:Requestor.java
/** Create JMS client for sending messages. */ private void start(String broker, String username, String password, String sQueue) { // Create a connection. try {//from w w w . j a v a2s . c om javax.jms.QueueConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createQueueConnection(username, password); session = connect.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create the Queue and QueueRequestor for sending requests. javax.jms.Queue queue = null; try { queue = session.createQueue(sQueue); requestor = new javax.jms.QueueRequestor(session, queue); // Now that all setup is complete, start the Connection. connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); exit(); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.println("\nRequestor application:\n" + "============================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application uses a QueueRequestor to on the " + DEFAULT_QUEUE + " queue." + "The Replier application gets the message, and transforms it." + "The Requestor application displays the result.\n\n" + "Type some mixed case text, and then press Enter to make a request.\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0) { javax.jms.TextMessage msg = session.createTextMessage(); msg.setText(username + ": " + s); // Instead of sending, we will use the QueueRequestor. javax.jms.Message response = requestor.request(msg); // The message should be a TextMessage. Just report it. javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response; System.out.println("[Reply] " + textMessage.getText()); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } }
From source file:com.zotoh.maedr.device.JmsIO.java
private void inizQueue(Context ctx, Object obj) throws Exception { QueueConnectionFactory f = (QueueConnectionFactory) obj; final JmsIO me = this; QueueConnection conn;/*from ww w . j a v a 2s .c o m*/ Queue q = (Queue) ctx.lookup(_dest); if (!isEmpty(_jmsUser)) { conn = f.createQueueConnection(_jmsUser, _jmsPwd); } else { conn = f.createQueueConnection(); } _conn = conn; QueueSession s = conn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); QueueReceiver r; r = s.createReceiver(q); r.setMessageListener(new MessageListener() { public void onMessage(Message msg) { me.onMessage(msg); } }); }
From source file:org.apache.synapse.message.store.impl.jms.JmsStore.java
/** * Creates a new JMS Connection./*from ww w . j a va2 s . c o m*/ * * @return A connection to the JMS Queue used as the store of this message store. * @throws JMSException */ public Connection newConnection() throws JMSException { Connection connection; if (connectionFactory == null) { logger.error(nameString() + ". Could not create a new connection to the broker." + " Initial Context Factory:[" + parameters.get(NAMING_FACTORY_INITIAL) + "]; Provider URL:[" + parameters.get(PROVIDER_URL) + "]; Connection Factory:[null]."); return null; } if (isVersion11) { if (userName != null && password != null) { connection = connectionFactory.createConnection(userName, password); } else { connection = connectionFactory.createConnection(); } } else { QueueConnectionFactory connectionFactory; connectionFactory = (QueueConnectionFactory) this.connectionFactory; if (userName != null && password != null) { connection = connectionFactory.createQueueConnection(userName, password); } else { connection = connectionFactory.createQueueConnection(); } } connection.start(); if (logger.isDebugEnabled()) { logger.debug(nameString() + ". Created JMS Connection."); } return connection; }
From source file:com.legstar.mq.client.AbstractCicsMQ.java
/** * Create a JMS queue connection.//from w w w. jav a 2s. co m * <p/> * Starts the connection's delivery of incoming messages. (Messages will not * be received without this call). * * @param userId for authentication * @param password for authentication * @return the new JMS queue connection * @throws CicsMQConnectionException if JMS queue connection cannot be * created */ protected QueueConnection createQueueConnection(final String userId, final String password) throws CicsMQConnectionException { if (_log.isDebugEnabled()) { _log.debug("enter createQueueConnection()"); } try { QueueConnectionFactory factory = (QueueConnectionFactory) getJndiContext() .lookup(getCicsMQEndpoint().getJndiConnectionFactoryName()); if (factory == null) { throw new CicsMQConnectionException( "JNDI lookup for " + getCicsMQEndpoint().getJndiConnectionFactoryName() + " failed"); } QueueConnection connection = factory.createQueueConnection(userId, password); connection.start(); return connection; } catch (NamingException e) { throw new CicsMQConnectionException(e); } catch (JMSException e) { throw new CicsMQConnectionException(e); } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.factory.JMSConnectionFactory.java
public Connection createConnection(String userName, String password) { Connection connection = null; try {/*from w w w . ja v a 2 s .c om*/ if (JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) { if (this.destinationType.equals(JMSConstants.JMSDestinationType.QUEUE)) { connection = ((QueueConnectionFactory) (this.connectionFactory)).createQueueConnection(userName, password); } else if (this.destinationType.equals(JMSConstants.JMSDestinationType.TOPIC)) { connection = ((TopicConnectionFactory) (this.connectionFactory)).createTopicConnection(userName, password); } if (isDurable) { connection.setClientID(clientId); } return connection; } else { QueueConnectionFactory qConFac = null; TopicConnectionFactory tConFac = null; if (this.destinationType.equals(JMSConstants.JMSDestinationType.QUEUE)) { qConFac = (QueueConnectionFactory) this.connectionFactory; } else { tConFac = (TopicConnectionFactory) this.connectionFactory; } if (qConFac != null) { connection = qConFac.createQueueConnection(userName, password); } else if (tConFac != null) { connection = tConFac.createTopicConnection(userName, password); } if (isDurable && !isSharedSubscription) { connection.setClientID(clientId); } return connection; } } catch (JMSException e) { logger.error("JMS Exception while creating connection through factory '" + this.connectionFactoryString + "' " + e.getMessage()); // Need to close the connection in the case if durable subscriptions if (connection != null) { try { connection.close(); } catch (Exception ex) { } } } return null; }
From source file:org.miloss.fgsms.bueller.Bueller.java
private String doJmsURL(boolean pooled, String endpoint) { try {/*from w w w. ja va2s . c o m*/ boolean ok = false; String server = endpoint.split("#")[0]; server = server.replace("jms:", "jnp://"); String name = endpoint.split("#")[1]; String msg = ""; String[] info = DBSettingsLoader.GetCredentials(pooled, endpoint); String username = null; String password = null; if (info != null) { username = info[0]; password = info[1]; } else { info = DBSettingsLoader.GetDefaultBuellerCredentials(pooled); if (info != null) { username = info[0]; password = info[1]; } } if (name.startsWith("topic")) { try { Properties properties1 = new Properties(); properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); //properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); properties1.put(Context.PROVIDER_URL, server); InitialContext iniCtx = new InitialContext(properties1); TopicConnectionFactory tcf = (TopicConnectionFactory) iniCtx.lookup("TopicConnectionFactory"); TopicConnection createTopicConnection = null; if (info != null) { createTopicConnection = tcf.createTopicConnection(username, Utility.DE(password)); //Topic topic = (Topic) iniCtx.lookup("/topic/quickstart_jmstopic_topic"); } else { createTopicConnection = tcf.createTopicConnection(); //Topic topic = (Topic) iniCtx.lookup("/topic/quickstart_jmstopic_topic"); } createTopicConnection.start(); createTopicConnection.stop(); createTopicConnection.close(); //Topic topic = (Topic) iniCtx.lookup("//" + name); ok = true; //topic = null; iniCtx.close(); } catch (Exception ex) { System.out.println(ex); msg = ex.getLocalizedMessage(); //return ex.getLocalizedMessage(); } } else if (name.startsWith("queue")) { try { Properties properties1 = new Properties(); properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); properties1.put(Context.PROVIDER_URL, server); InitialContext iniCtx = new InitialContext(properties1); QueueConnection conn; QueueSession session; Queue que; Object tmp = iniCtx.lookup("ConnectionFactory"); QueueConnectionFactory qcf = (QueueConnectionFactory) tmp; if (info != null) { conn = qcf.createQueueConnection(username, Utility.DE(password)); } else { conn = qcf.createQueueConnection(); } que = (Queue) iniCtx.lookup(name); session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); conn.start(); //System.out.println("Connection Started"); ok = true; conn.stop(); session.close(); iniCtx.close(); } catch (Exception ex) { log.log(Level.WARN, "Could not bind to jms queue", ex); msg = ex.getLocalizedMessage(); } if (ok) { return "OK"; } return "Unable to bind to JMS queue: " + msg; } else { return "Unsupported Protocol"; } } catch (Exception ex) { log.log(Level.WARN, "service " + endpoint + " is offline or an error occured", ex); return "Offline " + ex.getLocalizedMessage(); } return "undeterminable"; }
From source file:org.apache.axis2.transport.jms.JMSOutTransportInfo.java
/** * Create a one time MessageProducer for this JMS OutTransport information. * For simplicity and best compatibility, this method uses only JMS 1.0.2b API. * Please be cautious when making any changes * * @return a JMSSender based on one-time use resources * @throws JMSException on errors, to be handled and logged by the caller */// w w w . ja v a2 s . c o m public JMSMessageSender createJMSSender() throws JMSException { // digest the targetAddress and locate CF from the EPR loadConnectionFactoryFromProperies(); // create a one time connection and session to be used String user = properties != null ? properties.get(JMSConstants.PARAM_JMS_USERNAME) : null; String pass = properties != null ? properties.get(JMSConstants.PARAM_JMS_PASSWORD) : null; QueueConnectionFactory qConFac = null; TopicConnectionFactory tConFac = null; int destType = -1; // TODO: there is something missing here for destination type generic if (JMSConstants.DESTINATION_TYPE_QUEUE.equals(destinationType)) { destType = JMSConstants.QUEUE; qConFac = (QueueConnectionFactory) connectionFactory; } else if (JMSConstants.DESTINATION_TYPE_TOPIC.equals(destinationType)) { destType = JMSConstants.TOPIC; tConFac = (TopicConnectionFactory) connectionFactory; } else { //treat jmsdestination type=queue(default is queue) destType = JMSConstants.QUEUE; qConFac = (QueueConnectionFactory) connectionFactory; } Connection connection = null; if (user != null && pass != null) { if (qConFac != null) { connection = qConFac.createQueueConnection(user, pass); } else if (tConFac != null) { connection = tConFac.createTopicConnection(user, pass); } } else { if (qConFac != null) { connection = qConFac.createQueueConnection(); } else if (tConFac != null) { connection = tConFac.createTopicConnection(); } } if (connection == null) { connection = jmsConnectionFactory != null ? jmsConnectionFactory.getConnection() : null; } Session session = null; MessageProducer producer = null; if (connection != null) { if (destType == JMSConstants.QUEUE) { session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE); producer = ((QueueSession) session).createSender((Queue) destination); } else { session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE); producer = ((TopicSession) session).createPublisher((Topic) destination); } } return new JMSMessageSender(connection, session, producer, destination, jmsConnectionFactory == null ? JMSConstants.CACHE_NONE : jmsConnectionFactory.getCacheLevel(), false, destType == -1 ? null : destType == JMSConstants.QUEUE ? Boolean.TRUE : Boolean.FALSE); }