Does anyone know what my problem may be here? When I attempt to
retrieve my QueueConnectionFactory via InitialContext.lookup, I get
the follwing error message:
Error in setting up Context Factory:
javax.naming.NoInitialContextException: Cannot instantiate class:
com.sonicsw.jndi.mfcontext.MFContextFactory [Root exception is
java.lang.ClassNotFoundException:
com.sonicsw.jndi.mfcontext.MFContextFactory
The code is pasted below with the offending line marked between
"---->" & "<----"
package JMSEx;
import javax.naming.InitialContext;
//import javax.jms.*;
import progress.message.jclient.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.Queue;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.TextMessage;
import javax.jms.JMSException;
import java.util.Properties;
import java.io.FileInputStream;
import java.util.Date;
import java.util.Hashtable;
/**
* @author dwhitlock
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class JMS2Sonic {
protected InitialContext context;
public QueueConnectionFactory queFact;
public QueueConnection queConn;
public QueueSession queSess;
public Queue que;
public TextMessage txt;
public QueueSender sender;
public QueueReceiver rcvr;
protected Properties props;
public JMS2Sonic (String propertiesFile, boolean send)
{
System.out.println("Ready");
try
{
props = new Properties();
props.load(new FileInputStream(propertiesFile));
System.setProperties(props);
}
catch (java.io.IOException ioe)
{
System.out.println("Error in reading " +
propertiesFile +" \nError message: " + ioe.toString());
System.exit(3);
}
try
{
context = new InitialContext();
Hashtable hashtable = context.getEnvironment();
----> queFact = (QueueConnectionFactory)context.lookup
(props.getProperty("java.naming.factory.initial"));<----
//queFact = (QueueConnectionFactory)context.lookup
("java.naming.factory.initial");
queConn = queFact.createQueueConnection
(props.getProperty("java.naming.security.principal"),
props.getProperty("java.naming.security.credentials"));
queSess = queConn.createQueueSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);
que = queSess.createQueue(props.getProperty
("java.jms.queue"));
if (send)
sender = queSess.createSender(que);
else
rcvr = queSess.createReceiver(que);
txt = queSess.createTextMessage();
}
catch(javax.naming.NamingException jne)
{
System.out.println("Error in setting up Context
Factory: " + jne.toString());
System.exit(2);
}
catch(JMSException jne)
{
System.out.println("Error in creating connection
queue: " + jne.toString());
System.exit(2);
}
}
private void cleanHouse(JMS2Sonic j2s, boolean sender)
{
try
{
if (sender)
j2s.sender.close();
else
j2s.rcvr.close();
j2s.queSess.close();
}
catch(JMSException jne)
{
System.out.println("Error in closing queue
sessions: " + jne.toString());
System.exit(6);
}
}
public void sendMessage(JMS2Sonic j2s, String msg)
{
try
{
j2s.txt.setText(msg);
j2s.sender.send(j2s.txt);
}
catch(JMSException jne)
{
System.out.println("Error in sending message: " +
jne.toString());
System.exit(4);
}
}
public String getMessage(JMS2Sonic j2s)
{
String retval = "";
try
{
TextMessage msg = (TextMessage)j2s.rcvr.receive();
retval = msg.getText();
}
catch(JMSException jne)
{
System.out.println("Error in receiving message: " +
jne.toString());
System.exit(5);
}
return retval;
}
public static void main(String[] args)
{
boolean sender = true;
if (args[1].compareToIgnoreCase("f")== 0)
sender = false;
JMS2Sonic sonic = new JMS2Sonic(args[0], sender);
if (sender)
{
Date date = new Date();
sonic.sendMessage(sonic, "This is a test
from JMS2Sonic" + date.toString());
}
else
{
String msg = sonic.getMessage(sonic);
}
}
}