Oracle SOA, AIA BPEL ESB and OSB knowledge base

Friday, February 27, 2009

JMS is a bit different in JDeveloper 11G and WebLogic 10.3

Thanks to Edwin for good work.

JMS is a bit different in JDeveloper 11G and WebLogic 10.3 then when you use OC4J 10.1.3. This blog will show you how you can create a Queue and Connection Factory in WebLogic and use this in one of your JDeveloper 11g projects.
First you have to add two libraries to the project, The first is the AQJMS library ( even when we don't use AQ ) and the second library is the WebLogic 10.3 thin Client

Start the weblogic server. Menu Run , Start Server Instance


The url is http://localhost:7101/console. Username weblogic password weblogic.


Default the weblogic server has an empty configuration. We need to create a new jms server with a database of file persistance. We need this for the queue or topic persistence

create a new jms system module. In this module we will create a new connection factory and queue
Select the just created jms module and create a new connection factory first.



Create a new queue

Make sure that the queue uses the jms server. See the targets this can't be empty

And here is the java code to test the connection factory and the queue

The difference with oc4j is that you use other jndi properties. This are the right properties for WebLogic 10.3 in JDeveloper 11g

java.naming.factory.initial weblogic.jndi.WLInitialContextFactory
java.naming.provider.url t3://localhost:7101
java.naming.security.principal weblogic
java.naming.security.credentials weblogic



  1. package nl.ordina.jms;

  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.sql.Timestamp;
  6. import java.util.Properties;
  7. import javax.jms.JMSException;
  8. import javax.jms.Queue;
  9. import javax.jms.QueueConnection;
  10. import javax.jms.QueueConnectionFactory;
  11. import javax.jms.QueueReceiver;
  12. import javax.jms.QueueSender;
  13. import javax.jms.QueueSession;
  14. import javax.jms.Session;
  15. import javax.jms.TextMessage;
  16. import javax.naming.Context;
  17. import javax.naming.InitialContext;

  18. public class WeblogicClient {

  19. private QueueConnection connection = null;
  20. private QueueSession session = null;
  21. private QueueSender sender = null;
  22. private QueueReceiver receiver = null;
  23. private Queue queue = null;
  24. private long waitTime = 0;


  25. public WeblogicClient() {
  26. setUp();
  27. put();
  28. get();
  29. tearDown();
  30. }

  31. public static void main(String[] args) {
  32. WeblogicClient weblogicClient = new WeblogicClient();
  33. }

  34. public void tearDown() {
  35. try {
  36. sender.close();
  37. receiver.close();
  38. session.close();
  39. connection.close();

  40. } catch (JMSException je) {
  41. je.printStackTrace();
  42. } finally {
  43. }
  44. }

  45. public void get(){
  46. try {
  47. javax.jms.TextMessage textMessage = (javax.jms.TextMessage)receiver.receive();
  48. System.out.println("Receiving message [" + textMessage.getJMSMessageID() + "] enqueued at " + new Timestamp(textMessage.getJMSTimestamp()).toString());
  49. String xmlText = textMessage.getText();
  50. System.out.println(xmlText);
  51. } catch (JMSException jmse) {
  52. jmse.printStackTrace();
  53. }
  54. }

  55. public void put(){
  56. String messageId = null;
  57. String xmlData = "";
  58. FileInputStream fis;
  59. try {
  60. fis = new FileInputStream("D:\\projecten\\mhs_esb\\delfor.xml");
  61. int x= fis.available();
  62. byte b[]= new byte[x];
  63. fis.read(b);
  64. xmlData = new String(b);
  65. } catch (FileNotFoundException e) {
  66. // TODO
  67. } catch (IOException e) {
  68. // TODO
  69. }
  70. try {
  71. TextMessage message = session.createTextMessage(xmlData);
  72. sender.send(message);
  73. } catch (JMSException jmse) {
  74. jmse.printStackTrace();
  75. }
  76. }

  77. protected void setUp() {

  78. String queueName = "jms/QTest";
  79. String queueConnectionFactoryName = "jms/CFTest";
  80. Context ctx;

  81. try {
  82. Properties parm = new Properties();
  83. parm.setProperty("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory");
  84. parm.setProperty("java.naming.provider.url","t3://localhost:7101");
  85. parm.setProperty("java.naming.security.principal","weblogic");
  86. parm.setProperty("java.naming.security.credentials","weblogic");

  87. ctx = new InitialContext(parm);

  88. QueueConnectionFactory connectionFactory =
  89. (QueueConnectionFactory)ctx.lookup(queueConnectionFactoryName);

  90. connection = connectionFactory.createQueueConnection();
  91. connection.start();
  92. session = connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
  93. queue = (Queue)ctx.lookup(queueName);
  94. sender = session.createSender(queue);
  95. receiver = session.createReceiver(queue);


  96. } catch (JMSException je) {
  97. throw new RuntimeException("Fout opgetreden bij het starten ",je);
  98. } catch (Throwable t) {
  99. throw new RuntimeException("Fout opgetreden bij het starten ",t);

  100. }
  101. }

  102. }

2 comments:

Vandan said...

Thanks for the good stuff.Useful for amny of them.Can you please explain how to create JMS queue on Oracle Application Server.
Thanks in Advance...

Abhishek Gupta said...

You need to first login to enterprise manager. Then click on your instance like home link. Then click on tab administration.

Now you see JMS connection factory and JMS destination.

If you want to user existing JMS connection factory you can use them or create one.

Now create your JMS destination as queue or topic. Here you specify jndi name as anything like jms/myqueue. You have option to go for in memory , file based or database persistance. First two options are easy then the third one. If you are looking for database, please let me know i will type in for you.

Once you are done with destination, you can use this jndi name in your BPEL process.

FEEDJIT Live Traffic Map

My Blog List