79740544

Date: 2025-08-20 01:23:38
Score: 1
Natty:
Report link

TL;DR

Don’t create the ConnectionFactory manually in code.
Instead, inject it with @Resource so WebLogic uses the credentials from the Foreign Server configuration.


I was able to find the root cause for this a few weeks ago, and now I’m taking the time to close this topic.

The issue was actually in the application source code, which I was initially trying to avoid changing.

The application was creating the ConnectionFactory like this:

public static void sendMessage(final Object msg, final String queueName) throws Exception {
    String connectionFactoryName = "ConnectionFactoryName";
    ServiceLocator sl = ServiceLocatorFactory.getServiceLocator(queues);
    
    try {
        QueueConnectionFactory connectionFactory = sl.getQueueConnectionFactory(connectionFactoryName);
        QueueConnection connection = connectionFactory.createQueueConnection();

        [...]
    }
}

When I changed the line to explicitly provide username and password:

QueueConnection connection = connectionFactory.createQueueConnection("user", "password");

the connection was authenticated successfully.


So, when you create a ConnectionFactory directly in code without passing user and password as arguments, the application will still retrieve all configuration from the Foreign Server (such as Remote JNDI and Remote ConnectionFactory), except the user/password values defined there.


Final Fix

The real fix was to avoid creating the ConnectionFactory in code at all. Instead, I injected it directly into the MDB EJB using @Resource. This way, the application receives the complete ConnectionFactory with the authentication provided inside the Foreign Server:

@Resource(lookup = "jms/app/remoteFactory")
private QueueConnectionFactory connectionFactory;
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Resource
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: vz1654056