whitlock 2002/06/21 06:17:07
Modified: java/test/org/apache/wsif/util/jms
NativeJMSRequestListener.java
java/test/async AsyncTests.java
java/src/org/apache/wsif/util/jms WSIFJMSFinderForJndi.java
Log:
Look JMS objects up in default JNDI as well as JNDI from the WSDL
Revision Changes Path
1.4 +5 -15
xml-axis-wsif/java/test/org/apache/wsif/util/jms/NativeJMSRequestListener.java
Index: NativeJMSRequestListener.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/test/org/apache/wsif/util/jms/NativeJMSRequestListener.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NativeJMSRequestListener.java 20 Jun 2002 11:14:05 -0000 1.3
+++ NativeJMSRequestListener.java 21 Jun 2002 13:17:06 -0000 1.4
@@ -90,7 +90,6 @@
static final String sampleName = null;
static final String queueConnectionFactory = "WSIFSampleQCF";
static final String readQueue = null;
- static final String httpUrlString =
"http://localhost:8080/soap/servlet/rpcrouter";
private Thread listener;
@@ -306,21 +305,12 @@
return new Integer( inout.addNumbers( nums ) );
}
- private void sendReply(Message msg, Object response) throws Exception {
- Message replyMsg = session.createObjectMessage();
- ((ObjectMessage)replyMsg).setObject((Serializable) response );
+ private void sendReply(Message msg, Object response) throws Exception {
+ Message replyMsg = session.createObjectMessage();
+ ((ObjectMessage) replyMsg).setObject((Serializable) response);
- String replyq = ((Queue)msg.getJMSReplyTo()).getQueueName().substring( 9 );
-
- WSIFJMSDestination dest = new WSIFJMSDestination(
- new WSIFJMSFinderForJndi(null,
- initialContextFactory,
- jndiUrl,
- WSIFJMSFinder.STYLE_QUEUE,
- queueConnectionFactory,
- replyq )
- );
- dest.send( replyMsg, msg.getJMSMessageID() );
+ setReplyToQueue((Queue)(msg.getJMSReplyTo()));
+ send(replyMsg, msg.getJMSMessageID());
}
/**
1.3 +56 -31 xml-axis-wsif/java/test/async/AsyncTests.java
Index: AsyncTests.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/async/AsyncTests.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AsyncTests.java 21 Jun 2002 11:12:10 -0000 1.2
+++ AsyncTests.java 21 Jun 2002 13:17:06 -0000 1.3
@@ -57,31 +57,40 @@
package async;
-import junit.framework.*;
-
-import addressbook.wsiftypes.AddressBook;
-import addressbook.wsiftypes.Address;
-import addressbook.wsiftypes.Phone;
-import stockquote.wsifservice.StockquotePT;
-import stockquote.wsiftypes.StockQuote;
-
-import org.apache.wsif.*;
-import org.apache.wsif.util.*;
-import org.apache.wsif.base.*;
-import org.apache.wsif.util.jms.*;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.wsif.WSIFConstants;
+import org.apache.wsif.WSIFCorrelationId;
+import org.apache.wsif.WSIFCorrelationService;
+import org.apache.wsif.WSIFException;
+import org.apache.wsif.WSIFMessage;
+import org.apache.wsif.WSIFOperation;
+import org.apache.wsif.WSIFPort;
+import org.apache.wsif.WSIFService;
+import org.apache.wsif.WSIFServiceFactory;
+import org.apache.wsif.base.WSIFDefaultMessage;
+import org.apache.wsif.base.WSIFServiceImpl;
import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
-
-import javax.jms.*;
-import javax.mail.MessagingException;
-
-import org.apache.wsif.providers.jms.*;
-
+import org.apache.wsif.util.WSIFCorrelationServiceLocator;
+import org.apache.wsif.util.WSIFProperties;
+import org.apache.wsif.util.jms.WSIFJMSFinderForJndi;
+import org.apache.wsif.util.jms.WSIFJMSFinder;
import util.TestUtilities;
+import addressbook.wsiftypes.Address;
+import addressbook.wsiftypes.Phone;
import com.ibm.mq.jms.MQQueueConnectionFactory;
-import java.util.HashMap;
-
/**
* Junit test to test the NativeJMSProvider
*
@@ -462,15 +471,31 @@
return output;
}
- private Message getJMSResponse(String id) throws JMSException {
- QueueConnectionFactory factory = new MQQueueConnectionFactory();
- MQQueueConnectionFactory mqfactory = (MQQueueConnectionFactory) factory;
- QueueConnection connection = factory.createQueueConnection();
- connection.start();
- QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
- Queue readQ = session.createQueue(
TestUtilities.getWsifProperty("wsif.async.replytoq2") );
- QueueReceiver receiver = session.createReceiver( readQ,
"JMSCorrelationID='"+id+"'" );
- return receiver.receive( WSIFProperties.getAsyncTimeout() );
- }
-
+ private Message getJMSResponse(String id) throws WSIFException, JMSException {
+ String initialContextFactory = "com.sun.jndi.fscontext.RefFSContextFactory";
+ String jndiUrl = "file:///JNDI-Directory";
+ String queueConnectionFactory = "WSIFSampleQCF";
+
+ WSIFJMSFinder finder =
+ new WSIFJMSFinderForJndi(
+ null,
+ initialContextFactory,
+ jndiUrl,
+ WSIFJMSFinder.STYLE_QUEUE,
+ queueConnectionFactory,
+ null);
+
+ QueueConnectionFactory factory = finder.getFactory();
+ QueueConnection connection = factory.createQueueConnection();
+ connection.start();
+ QueueSession session =
+ connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue readQ =
+ session.createQueue(
+ TestUtilities.getWsifProperty("wsif.async.replytoq2"));
+ QueueReceiver receiver =
+ session.createReceiver(readQ, "JMSCorrelationID='" + id + "'");
+ return receiver.receive(WSIFProperties.getAsyncTimeout());
+ }
+
}
1.2 +80 -38
xml-axis-wsif/java/src/org/apache/wsif/util/jms/WSIFJMSFinderForJndi.java
Index: WSIFJMSFinderForJndi.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/jms/WSIFJMSFinderForJndi.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WSIFJMSFinderForJndi.java 6 Jun 2002 08:28:52 -0000 1.1
+++ WSIFJMSFinderForJndi.java 21 Jun 2002 13:17:06 -0000 1.2
@@ -72,9 +72,10 @@
* Finds JMS objects by looking them up in JNDI.
* @author Mark Whitlock <[EMAIL PROTECTED]>
*/
-class WSIFJMSFinderForJndi extends WSIFJMSFinder {
+public class WSIFJMSFinderForJndi extends WSIFJMSFinder {
- private InitialDirContext jndiContext;
+ private InitialDirContext namedJndiContext = null;
+ private InitialDirContext containersJndiContext = null;
private QueueConnectionFactory factory;
private Destination initialDestination = null;
private String style;
@@ -89,7 +90,7 @@
* @param jndiDestinationName is the JNDI name of the initial queue.
* @param jmsproviderDestinationName is the JMS implementation's name of the
initial queue.
*/
- WSIFJMSFinderForJndi(
+ public WSIFJMSFinderForJndi(
String jmsVendorURL,
String initialContextFactory,
String jndiProviderURL,
@@ -110,38 +111,40 @@
throw new WSIFException("Style must either be queue or topic");
this.style = style;
+ if (((initialContextFactory == null) && (jndiProviderURL != null))
+ || ((initialContextFactory != null) && (jndiProviderURL == null)))
+ throw new WSIFException(
+ "Either both initialContextFactory and jndiProviderURL "
+ + "must be specified or neither of them must be specified");
+
if (initialContextFactory != null && jndiProviderURL != null) {
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
environment.put(Context.PROVIDER_URL, jndiProviderURL);
try {
- jndiContext = new InitialDirContext(environment);
+ namedJndiContext = new InitialDirContext(environment);
} catch (NamingException ne) {
throw new WSIFException(
"WSIFJMSFinderForJndi caught '"
+ ne
- + "'. "
- + "InitialContextFactory was '"
+ + "'. InitialContextFactory was '"
+ initialContextFactory
- + "' "
- + "ProviderUrl was '"
+ + "' ProviderUrl was '"
+ jndiProviderURL
+ "'");
}
- } else if (initialContextFactory == null && jndiProviderURL == null)
- try {
- jndiContext = new InitialDirContext();
- } catch (NamingException ne) {
+ }
+
+ try {
+ containersJndiContext = new InitialDirContext();
+ } catch (NamingException ne) {
+ if (initialContextFactory == null && jndiProviderURL == null)
throw new WSIFException(
"WSIFJMSFinderForJndi caught '"
+ ne
- + "' "
- + "using the default JNDI repository.");
- } else
- throw new WSIFException(
- "Either both initialContextFactory and jndiProviderURL "
- + "must be specified or neither of them must be specified");
+ + "' using the default JNDI repository.");
+ }
if (STYLE_TOPIC.equals(style))
throw new WSIFException("Topics not implemented");
@@ -154,36 +157,40 @@
if (jndiConnectionFactory == null)
throw new WSIFException("jndiConnectionFactory must be specified");
try {
- factory = (QueueConnectionFactory)
jndiContext.lookup(jndiConnectionFactory);
+ factory = (QueueConnectionFactory) lookup(jndiConnectionFactory);
+ if (factory == null)
+ throw new WSIFException(
+ "WSIFJMSFinderForJndi was not able to lookup the
ConnectionFactory "
+ + jndiConnectionFactory
+ + " in JNDI.");
} catch (ClassCastException cce) {
throw new WSIFException(
- "WSIFJMSFinderForJndi caught ClassCastException. "
- + "The ConnectionFactory "
+ "WSIFJMSFinderForJndi caught ClassCastException. The
ConnectionFactory "
+ jndiConnectionFactory
- + " in JNDI was not "
- + "defined to be a connection factory.");
+ + " in JNDI was not defined to be a connection factory.");
} catch (NamingException ne) {
throw new WSIFException(
- "WSIFJMSFinderForJndi caught NamingException. "
- + "The ConnectionFactory "
+ "WSIFJMSFinderForJndi caught NamingException. The ConnectionFactory
"
+ jndiConnectionFactory
- + " in JNDI was not "
- + "defined to be a connection factory.");
+ + " in JNDI was not defined to be a connection factory.");
}
if (jndiDestinationName != null)
try {
- initialDestination = (Destination)
jndiContext.lookup(jndiDestinationName);
+ initialDestination = (Destination) lookup(jndiDestinationName);
+ if (initialDestination == null)
+ throw new WSIFException(
+ "WSIFJMSFinderForJndi was not able to lookup the
Destination "
+ + jndiDestinationName
+ + " in JNDI.");
} catch (ClassCastException cce) {
throw new WSIFException(
- "WSIFJMSFinderForJndi caught ClassCastException. "
- + "The Destination "
+ "WSIFJMSFinderForJndi caught ClassCastException. The
Destination "
+ jndiDestinationName
+ " in JNDI was not defined to be a destination.");
} catch (NamingException cce) {
throw new WSIFException(
- "WSIFJMSFinderForJndi caught NamingException. "
- + "The Destination "
+ "WSIFJMSFinderForJndi caught NamingException. The Destination "
+ jndiDestinationName
+ " in JNDI was not defined to be a destination.");
}
@@ -213,17 +220,20 @@
Tr.entry(this, name);
Queue q = null;
try {
- q = (Queue) jndiContext.lookup(name);
+ q = (Queue) lookup(name);
+ if (q == null)
+ throw new WSIFException(
+ "WSIFJMSFinderForJndi was not able to lookup the Destination "
+ + name
+ + " in JNDI.");
} catch (ClassCastException cce) {
throw new WSIFException(
- "WSIFJMSFinderForJndi caught ClassCastException. "
- + "The Queue "
+ "WSIFJMSFinderForJndi caught ClassCastException. The Queue "
+ name
+ " in JNDI was not defined to be a queue.");
} catch (NamingException cce) {
throw new WSIFException(
- "WSIFJMSFinderForJndi caught NamingException. "
- + "The Queue "
+ "WSIFJMSFinderForJndi caught NamingException. The Queue "
+ name
+ " in JNDI was not defined to be a queue.");
}
@@ -231,11 +241,43 @@
return q;
}
+ /**
+ * There is at least one and at most two JNDI databases to look
+ * objects up in :- the container's default JNDI database and the
+ * one specified in the WSDL. This code looks objects up in the
+ * container's JNDI first (if running in a container), and then
+ * looks the object up in the JNDI pointed at by the WSDL (assuming
+ * there is a JNDI mentioned in the WSDL). This allows a client
+ * administrator to override the JNDI specified in the WSDL. If
+ * both fail, then the first error is returned.
+ */
+ private Object lookup(String name) throws NamingException {
+ Tr.entry(name);
+ Object result = null;
+ if (containersJndiContext != null) {
+ try {
+ result = containersJndiContext.lookup(name);
+ } catch (NamingException ne) {
+ if (namedJndiContext != null) {
+ try {
+ result = namedJndiContext.lookup(name);
+ } catch (NamingException ignored) {
+ throw ne;
+ }
+ }
+ }
+ } else
+ result = namedJndiContext.lookup(name);
+ Tr.exit(result);
+ return result;
+ }
+
public String deep() {
String buff = "";
try {
buff = new String(this.toString() + "\n");
- buff += "jndiContext: " + jndiContext;
+ buff += "containersJndiContext: " + containersJndiContext;
+ buff += " namedJndiContext: " + namedJndiContext;
buff += " factory: " + factory;
buff += " initialDestination: " + initialDestination;
buff += " style: " + style;