Java Code Examples for javax.jms.Connection#getMetaData()

The following examples show how to use javax.jms.Connection#getMetaData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmqpManagementTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private boolean isSupportedClient() throws NamingException, JMSException
{
    if (getProtocol() == Protocol.AMQP_1_0)
    {
        return true;
    }
    else
    {
        Connection con = getConnection();
        try
        {
            final ConnectionMetaData metaData = con.getMetaData();
            // Older Qpid JMS Client 0-x (<=6.1.x) didn't support management addresses.
            return !(metaData.getProviderMajorVersion() < 6 || (metaData.getProviderMajorVersion() == 6
                                                                    && metaData.getProviderMinorVersion() <= 1));
        }
        finally
        {
            con.close();
        }
    }

}
 
Example 2
Source File: ConnectionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMetadata() throws Exception {
   Connection connection = createConnection();

   ConnectionMetaData metaData = connection.getMetaData();

   // TODO - need to check whether these are same as current version
   metaData.getJMSMajorVersion();
   metaData.getJMSMinorVersion();
   metaData.getJMSProviderName();
   metaData.getJMSVersion();
   metaData.getJMSXPropertyNames();
   metaData.getProviderMajorVersion();
   metaData.getProviderMinorVersion();
   metaData.getProviderVersion();

   connection.close();
}
 
Example 3
Source File: SingleConnectionFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithConnectionFactoryAndLocalExceptionListenerWithReconnect() throws JMSException {
	ConnectionFactory cf = mock(ConnectionFactory.class);
	TestConnection con = new TestConnection();
	given(cf.createConnection()).willReturn(con);

	TestExceptionListener listener0 = new TestExceptionListener();
	TestExceptionListener listener1 = new TestExceptionListener();
	TestExceptionListener listener2 = new TestExceptionListener();

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	scf.setReconnectOnException(true);
	scf.setExceptionListener(listener0);
	Connection con1 = scf.createConnection();
	con1.setExceptionListener(listener1);
	assertSame(listener1, con1.getExceptionListener());
	con1.start();
	Connection con2 = scf.createConnection();
	con2.setExceptionListener(listener2);
	assertSame(listener2, con2.getExceptionListener());
	con.getExceptionListener().onException(new JMSException(""));
	con2.close();
	con1.getMetaData();
	con.getExceptionListener().onException(new JMSException(""));
	con1.close();
	scf.destroy();  // should trigger actual close

	assertEquals(2, con.getStartCount());
	assertEquals(2, con.getCloseCount());
	assertEquals(2, listener0.getCount());
	assertEquals(2, listener1.getCount());
	assertEquals(1, listener2.getCount());
}
 
Example 4
Source File: SingleConnectionFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testWithConnectionFactoryAndLocalExceptionListenerWithReconnect() throws JMSException {
	ConnectionFactory cf = mock(ConnectionFactory.class);
	TestConnection con = new TestConnection();
	given(cf.createConnection()).willReturn(con);

	TestExceptionListener listener0 = new TestExceptionListener();
	TestExceptionListener listener1 = new TestExceptionListener();
	TestExceptionListener listener2 = new TestExceptionListener();

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	scf.setReconnectOnException(true);
	scf.setExceptionListener(listener0);
	Connection con1 = scf.createConnection();
	con1.setExceptionListener(listener1);
	assertSame(listener1, con1.getExceptionListener());
	con1.start();
	Connection con2 = scf.createConnection();
	con2.setExceptionListener(listener2);
	assertSame(listener2, con2.getExceptionListener());
	con.getExceptionListener().onException(new JMSException(""));
	con2.close();
	con1.getMetaData();
	con.getExceptionListener().onException(new JMSException(""));
	con1.close();
	scf.destroy();  // should trigger actual close

	assertEquals(2, con.getStartCount());
	assertEquals(2, con.getCloseCount());
	assertEquals(2, listener0.getCount());
	assertEquals(2, listener1.getCount());
	assertEquals(1, listener2.getCount());
}
 
Example 5
Source File: QpidRestAPIQueueCreator.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public String getProtocolVersion(final Connection connection)
{
    if (connection != null)
    {
        try
        {
            final Method method = connection.getClass().getMethod("getProtocolVersion"); // Qpid 0-8..0-10 method only
            Object version =  method.invoke(connection);
            return String.valueOf(version);
        }
        catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e)
        {
            try
            {
                ConnectionMetaData metaData = connection.getMetaData();
                if (metaData != null && ("QpidJMS".equals(metaData.getJMSProviderName()) ||
                                         "AMQP.ORG".equals(metaData.getJMSProviderName())))
                {
                    return "1.0";
                }
            }
            catch (JMSException e1)
            {
                return null;
            }
            return null;
        }
    }
    return null;
}
 
Example 6
Source File: SingleConnectionFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithConnectionFactoryAndLocalExceptionListenerWithReconnect() throws JMSException {
	ConnectionFactory cf = mock(ConnectionFactory.class);
	TestConnection con = new TestConnection();
	given(cf.createConnection()).willReturn(con);

	TestExceptionListener listener0 = new TestExceptionListener();
	TestExceptionListener listener1 = new TestExceptionListener();
	TestExceptionListener listener2 = new TestExceptionListener();

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	scf.setReconnectOnException(true);
	scf.setExceptionListener(listener0);
	Connection con1 = scf.createConnection();
	con1.setExceptionListener(listener1);
	assertSame(listener1, con1.getExceptionListener());
	con1.start();
	Connection con2 = scf.createConnection();
	con2.setExceptionListener(listener2);
	assertSame(listener2, con2.getExceptionListener());
	con.getExceptionListener().onException(new JMSException(""));
	con2.close();
	con1.getMetaData();
	con.getExceptionListener().onException(new JMSException(""));
	con1.close();
	scf.destroy();  // should trigger actual close

	assertEquals(2, con.getStartCount());
	assertEquals(2, con.getCloseCount());
	assertEquals(2, listener0.getCount());
	assertEquals(2, listener1.getCount());
	assertEquals(1, listener2.getCount());
}
 
Example 7
Source File: ConnectionClosedTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMetadataOnClosedConnection() throws Exception {
   Connection connection = createConnection();

   connection.close();

   try {
      connection.getMetaData();
      ProxyAssertSupport.fail("should throw exception");
   } catch (javax.jms.IllegalStateException e) {
      // OK
   }
}
 
Example 8
Source File: JmsMessagingSourceFactory.java    From iaf with Apache License 2.0 5 votes vote down vote up
public String getConnectionFactoryInfo(ConnectionFactory connectionFactory) {
	if (IbisContext.getApplicationServerType().equals("TIBCOAMX")) {
		// Workaround to prevent the following exception:
		// [org.apache.geronimo.connector.outbound.MCFConnectionInterceptor] - Error occurred creating ManagedConnection for org.apache.geronimo.connector.outbound.ConnectionInfo@#######
		// javax.resource.ResourceException: JMSJCA-E084: Failed to create session: The JNDI name is null
		return null;
	}
	String info=null;
	Connection connection = null;
	try {
		connection = connectionFactory.createConnection();
		ConnectionMetaData metaData = connection.getMetaData();
		info = "jms provider name [" + metaData.getJMSProviderName()
				+ "] jms provider version [" + metaData.getProviderVersion()
				+ "] jms version [" + metaData.getJMSVersion()
				+ "]";
	} catch (JMSException e) {
		log.warn("Exception determining connection factory info",e);
	} finally {
		if (connection != null) {
			try {
				connection.close();
			} catch (JMSException e1) {
				log.warn("Exception closing connection for metadata", e1);
			}
		}
	}
	return info;
}