use of javax.jms.JMSContext in project wildfly by wildfly.
the class DeserializationMessagingBean method send.
public void send(Serializable serializable) throws NamingException {
assertNotNull(queue);
Context namingContext = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) namingContext.lookup(BLACK_LIST_CF_LOOKUP);
assertNotNull(cf);
try (JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE)) {
context.createProducer().send(queue, serializable);
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class DeserializationMessagingBean method receive.
public void receive(Serializable serializable, String cfLookup, boolean consumeMustFail) throws NamingException {
assertNotNull(queue);
Context namingContext = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) namingContext.lookup(cfLookup);
try (JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE)) {
JMSConsumer consumer = context.createConsumer(queue);
try {
Message response = consumer.receive(1000);
assertNotNull(response);
assertTrue(response instanceof ObjectMessage);
Serializable o = ((ObjectMessage) response).getObject();
if (consumeMustFail) {
fail(o + " must not be deserialized when message is consumed");
} else {
assertEquals(serializable, o);
}
} catch (JMSException e) {
if (consumeMustFail) {
log.trace("Expected JMSException", e);
} else {
log.error("Unexpected exception", e);
fail(serializable + " is allowed to be deserialized when message is consumed");
}
}
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class AbstractSaslTestBase method sendAndReceiveMsg.
protected void sendAndReceiveMsg(int remotingPort, boolean expectedSaslFail, String username, String password) {
Context namingContext = null;
try {
// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
env.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
env.put(Context.PROVIDER_URL, "remote://" + HOST_FMT + ":" + remotingPort);
namingContext = new InitialContext(env);
// Perform the JNDI lookups
ConnectionFactory connectionFactory = null;
try {
connectionFactory = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
assertFalse("JNDI lookup should have failed.", expectedSaslFail);
} catch (NamingException e) {
if (expectedSaslFail) {
// only SASL failures are expected
assertTrue("Unexpected cause of lookup failure", e.getCause() instanceof SaslException);
return;
}
throw e;
}
Destination destination = (Destination) namingContext.lookup(NAME);
try (JMSContext context = (username != null ? connectionFactory.createContext(username, password) : connectionFactory.createContext())) {
// Send a message
context.createProducer().send(destination, MESSAGE);
// Create the JMS consumer
JMSConsumer consumer = context.createConsumer(destination);
// Then receive the same message that was sent
String text = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
Assert.assertEquals(MESSAGE, text);
}
} catch (NamingException e) {
LOGGER.error("Naming problem occured.", e);
throw new RuntimeException(e);
} finally {
if (namingContext != null) {
try {
namingContext.close();
} catch (NamingException e) {
LOGGER.error("Naming problem occured during closing context.", e);
}
}
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class ClusteredMessagingTestCase method testClusteredTopic.
@Test
public void testClusteredTopic() throws Exception {
InitialContext contextFromServer1 = createJNDIContext(NODE_1);
InitialContext contextFromServer2 = createJNDIContext(NODE_2);
try (JMSContext jmsContext1 = createJMSContext(createJNDIContext(NODE_1));
JMSConsumer consumer1 = jmsContext1.createConsumer((Destination) contextFromServer1.lookup(jmsTopicLookup));
JMSContext jmsContext2 = createJMSContext(createJNDIContext(NODE_2));
JMSConsumer consumer2 = jmsContext2.createConsumer((Destination) contextFromServer2.lookup(jmsTopicLookup))) {
String text = UUID.randomUUID().toString();
Destination destination1 = (Destination) contextFromServer1.lookup(jmsTopicLookup);
Destination destination2 = (Destination) contextFromServer2.lookup(jmsTopicLookup);
// send a message to the topic on server 1
sendMessage(contextFromServer1, destination1, text);
// consumers receive it on both servers
receiveMessage(consumer1, text);
receiveMessage(consumer2, text);
String anotherText = UUID.randomUUID().toString();
// send another message to topic on server 2
sendMessage(contextFromServer2, destination2, anotherText);
// consumers receive it on both servers
receiveMessage(consumer1, anotherText);
receiveMessage(consumer2, anotherText);
} finally {
contextFromServer1.close();
contextFromServer2.close();
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class ClusteredMessagingTestCase method sendMessage.
protected static void sendMessage(Context ctx, Destination destination, String text) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
assertNotNull(destination);
try (JMSContext context = cf.createContext(JMS_USERNAME, JMS_PASSWORD)) {
context.createProducer().send(destination, text);
}
}
Aggregations