public static void openJmsConnection() throws IOException {
try {
// Perform the JNDI lookup.
Hashtable env = new Hashtable();
env.put(
Context.INITIAL_CONTEXT_FACTORY,
\"com.swiftmq.jndi.InitialContextFactoryImpl\");
env.put(Context.PROVIDER_URL, \"
smqp://\" + server);
InitialContext ctx = new InitialContext(env);
QueueConnectionFactory connectionFactory =
(QueueConnectionFactory) ctx.lookup(socket); // HANGS HERE VED FEJLAGTIG JNDI SOCKET NAME.
// Sets the global queue object.
queue = (Queue) ctx.lookup(channel);
// Important to note that you should close the context thereafter, because
// the context holds an active JMS connection.
ctx.close();
// Create connection, session & sender
JMSconnection = connectionFactory.createQueueConnection(username, password);
JMSconnection.setExceptionListener(new javax.jms.ExceptionListener() {
public void onException(javax.jms.JMSException e) {
System.out.println(\"onExeption caught :\" + e);
}
});
// Sets the global session object.
session = JMSconnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createSender(queue);
} // end of try
catch (Exception e) {
System.err.println(\"Exception in getJmsSession: \" + e);
Calendar rightNowDate = Calendar.getInstance();
JmsClient.setErrorLog(
rightNowDate.getTime()
+ \" Error - Unable to connect to sender : \"
+ server
+ \", \"
+ socket
+ \", \"
+ channel
+ \" Connection could not be established\");
}
} // end of connect
/**
* Insert the method\'s description here.
* Creation date: (17-01-2002 11:16:01)
*/
public static void sendMessage(dk.mnet.jms.message.Message messageToSend) {
try {
System.out.println(\"*** SENDING MESSAGE to SERVER ***\");
messageToSend.outputMessageContent();
checkMessageDestinationIsSet(messageToSend);
if (session == null) {
System.out.println(\"Getting new Session:\");
System.out.println(\"Server : \" + server);
System.out.println(\"Socket : \" + socket);
System.out.println(\"queue : \" + channel);
System.out.println(\"user : \" + username);
System.out.println(\"passw. : \" + password);
openJmsConnection();
}
// Send the messages to the queue
ObjectMessage msg = session.createObjectMessage(messageToSend);
System.out.println(\"--- Sending Message ---\");
sender.send(msg);
System.out.println(\"--- MESSAGE SEND ---\");
} catch (Exception e) {
System.err.println(\"Exception: \" + e);
}