I am trying to send a JMS Point-to-Point message from an oracle database stored procedure to a Java application. Two "dots" are sitting on different machines, which, as I have confirmed, can talk to each other via ping.
I created a java application capable of successfully sending messages from a queue to an application server. The application runs on the JBoss v4.2.3 server. I was able to successfully send a JMS message from a remote Java application, so I am sure that the code running on the server is in order.
I took the code from a working java application and successfully loaded it into the oracle stored procedure. I also managed (I believe!) To load the required jar files into the oracle using the loadjava utility. The three jar files I downloaded are the following:
* jms-1.1
* jbossmq-3.2.3
* jboss-client-4.0.2
Three banks are used in a working remote java application and seem necessary. The code loaded into the stored procedure is as follows:
package com.base.jms.client;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class StandAloneClient {
public static String send() throws Exception {
String result = "Starting -> ";
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "192.168.111.242:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
result = result + "Environment -> ";
Context ic = new InitialContext(env);
result = result + "Context -> ";
QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ic.lookup("ConnectionFactory");
result = result + "Factory -> ";
Queue queue = (Queue) ic.lookup("queue/A");
result = result + "Queue -> ";
QueueConnection connection = connectionFactory.createQueueConnection();
result = result + "Connection -> ";
QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
result = result + "Session -> ";
QueueSender sender = session.createSender(queue);
connection.start();
result = result + "Sender -> ";
TextMessage myMessage = session.createTextMessage();
myMessage.setText(result);
sender.send(myMessage);
result = result + "Sending Message -> ";
sender.close();
session.close();
connection.close();
result = result + "Close";
} catch (JMSException e) {
result = result + "JMS Exception";
} catch (Exception e) {
result = result + "Exception";
}
return result;
}
}
I added a result line to try to determine where the code that it falls into is located. To create and test this procedure, I run the following commands in sqlplus:
create or replace function send_jms return VARCHAR2 as language java name 'com.base.jms.client.StandAloneClient.send() return java.lang.String';
variable myString varchar2(20);
call send_jms() into :myString;
Call completed.
print myString;
Everything seems to load and compile correctly, but the message is not sent. The returned result string implies that it crashes when trying to get the QueueConnectionFactory class from InitialContext. The returned string of the result:
Starting -> Environment -> Context -> Exception
I do not understand why this does not work, and could not get more information from the thrown Exception. Can anyone confirm that I am doing it right, and if so, can I see what I am doing wrong?
Sorry for the long post, but let's see it in advance!