Bootstrap FreeKB - IBM WebSphere - Map an application to a JMS connection factory during deployment
IBM WebSphere - Map an application to a JMS connection factory during deployment

Updated:   |  IBM WebSphere articles

Let's say you have an application that needs to make a JMS connection, such as connecting to an IBM MQ channel.  In WebSphere, you can create a JMS connection factory that points to the IBM MQ channel.

First you will want to create the JMS connection factory in WebSphere. In this example, the connection factory will be used to connect to IBM MQ channel001.

 

Optionally, you could also create the J2C authentication alias in WebSphere. The J2C authentication alias would contain the username and password used to connect to the IBM MQ channel. Check out my article Create J2C Alias.

 

In your Java applications class, let's say you have the following JNDI lookup.

ConnectionFactory cf = (ConnectionFactory) jndi.lookup("java:comp/env/channel001");

 

In WEB-INF/web.xml of your Java applications WAR, you would define the resource reference.

  • res-ref-name should be an exact match of the connection factory name in WebSphere and an exact match of whatever follows java:comp/env/ in your Java applications class.
  • res-type must be javax.jms.ConnectionFactory
  • res-auth will almost always be Container
<resource-ref>
  <res-ref-name>channel01</res-ref-name>
  <res-type>javax.jms.ConnectionFactory</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

 

In WEB-INF/ibm-web-bnd.xml of your Java applications WAR.

  • binding-name should be an exact match of the connection factory JNDI in WebSphere
  • name should be
    • an exact match of res-ref-name in web.xml
    • an exact match of the connection factory name in WebSphere
    • an exact match of whatever follows java:comp/env/ in your Java applications class
  • authentication-alias is optional - if used, name should be an exact match of the name of the J2C authentication alias in WebSphere
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd 
	xmlns="http://websphere.ibm.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
	version="1.0">

    <resource-ref binding-name="websphere/connectionfactory/channel01" name="channel01">
      <authentication-alias name="johndoe"/>
    </resource-ref>

</web-bnd>

 

Now, when deploying the application to WebSphere, the appliation should be automatically bound to the connection factory JNDI in WebSphere.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 83214c in the box below so that we can be sure you are a human.