0
votes

Currently i have a Java EE App host by Weblogic 10R3, i am interested to get 1 Message Driven Bean tested. The problem is that i don't have access to the foreign JMS server that Bean is listening to, here is MDB code:

import static com.citi.primefinance.utils.jms.ForeignJMSConstants.Queue.INCOMING_QUEUE_SWIFT_FX;
@MessageDriven(name = "IncomingSwiftFxProcessorMDB", mappedName = INCOMING_QUEUE_SWIFT_FX)
public class IncomingSwiftFxProcessorMDB extends AbstractMessageDrivenBean {
@Override
protected void processMessage(Serializable obj) throws Exception{

    debug(this.getClass().getName() + ".processMessage()");

    if (obj instanceof String) {
        info(this.getClass().getName() + ": received on Message object");
        processSwiftFxTradeMessage((String)obj);
    } else {
        error(this.getClass().getName() + ": received an object " + obj + " which is not a TextMessage");
    }
 }

My Plan is since the Bean will look-up the queue by JNDI, and i do have access to Weblogic hosting server. So i could delete the foreign JMS server, then add a local jms queue and connectionFactory holding the exact JNDI name. therefore isolate external dependence.

Do people think it is plausible? or anyone has alternative ideas? i was also thinking of using Mocking to isolate the dependency on JMS all together.

Any help is much appreciated, thanks

Here is some Weblogic log indicating Message Bean can't handle "Hot" swap?

incomingSwiftFxProcessorMDB is unable to connect to the JMS destination: IncomingSwiftFxQueue. The Error was: The Message-Driven EJB attempted to connect to the JMS connection factory with the JNDI name: SwiftConnectionFactory. However, the object with the JNDI name: SwiftConnectionFactory is not a JMS connection factory. NestedException Message is :weblogic.jms.client.JMSConnectionFactory>

1
By the way the foreign queue's vendor is websphere-mq, the queue created locally would be weblogic.jms.queue, i guess. i am new to MessageDriven Bean, i guess it can handle the difference ?Ben.Yan

1 Answers

0
votes

Ultimately you should test your business logic outside the context of the JMS interface. Otherwise, yes - this is feasible. A Foreign JMS Server in WebLogic is simply a Local JNDI representation of a remote JMS destination.

However, you don't have to delete the foreign config - simply untarget it from the server/cluster. Then, create your JMS module containing the JMS Queue (and ConnectionFactory if applicable) with the same JNDI name that is currently used to access the Foreign resource and you can test your MDB. Once you are done, you can un-target the JMS Module you used for testing and re-target the Foreign JMS Server to the appropriate resources.

It might be good to keep the 'testing' JMS module around so you can easily test again in the future :)

Try updating it to look like this, and implement the MessageListener interface:

@MessageDriven(
messageListenerInterface = javax.jms.MessageListener.class,
name = "MyListener",
mappedName = "jms/my/notification",
activationConfig = {
    @ActivationConfigProperty(
        propertyName = "connectionFactoryJndiName",
        propertyValue = "weblogic.jms.XAConnectionFactory"),
    @ActivationConfigProperty(
        propertyName = "destinationType",
        propertyValue = "javax.jms.Queue")
})