antelder 2002/06/18 06:00:22
Added: java/test/org/apache/wsif/util/jms
NativeJMSRequestListener.java
Removed: java/src/org/apache/wsif/util/jms
NativeJMSRequestListener.java
Log:
Move the NativeJMSRequestListener to the test folder where it belongs
Revision Changes Path
1.1
xml-axis-wsif/java/test/org/apache/wsif/util/jms/NativeJMSRequestListener.java
Index: NativeJMSRequestListener.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.util.jms;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFCorrelationId;
import org.apache.wsif.WSIFCorrelationService;
import org.apache.wsif.util.WSIFCorrelationServiceLocator;
import org.apache.wsif.base.WSIFDefaultCorrelationService;
import org.apache.wsif.util.jms.*;
import org.apache.wsif.util.jms.WSIFJMSFinderForJndi;
import org.apache.wsif.logging.*;
import addressbook.wsiftypes.AddressBook;
import addressbook.wsiftypes.Address;
import addressbook.wsiftypes.Phone;
import stockquote.wsifservice.StockquotePT;
import stockquote.wsiftypes.StockQuote;
import java.io.Serializable;
import java.util.*;
import javax.jms.*;
/**
* Used to simulate the remote service for native JMS requests.
*/
public class NativeJMSRequestListener extends JMS2HTTPBridgeDestination {
static final String startType = JMS2HTTPBridgeDestination.COLDSTART;
static final String initialContextFactory =
"com.sun.jndi.fscontext.RefFSContextFactory";
static final String jndiUrl = "file://C:/JNDI-Directory";
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;
AddressBook ab = new AddressBook();
StockQuote sq = new StockQuote();
private WSIFJMSListener list = new WSIFJMSListener() {
public void onException(JMSException arg1) {
Tr.entry(this, arg1);
System.out.println("Caught an exception!");
arg1.printStackTrace();
Tr.exit();
}
public void onMessage(Message message) {
Tr.entry(this, message);
processResponse(message);
Tr.exit();
}
};
public NativeJMSRequestListener(String msgQ) throws WSIFException {
super( new WSIFJMSFinderForJndi(
null,
initialContextFactory,
jndiUrl,
WSIFJMSFinder.STYLE_QUEUE,
queueConnectionFactory,
msgQ),
null,
WSIFJMSConstants.WAIT_FOREVER,
startType);
listener = new Thread() {
public void run() {
try {
listen( list );
} catch (WSIFException ex) {
ex.printStackTrace();
}
}
};
listener.start();
}
/**
* Create a listener thread to listen for messages. This waits forever until it
gets
* an InterruptedException.
* @param listener is the JMS message and exception callback interface
implementation
* @param queue to listen on
*/
public void listen(WSIFJMSListener listener, Queue queue)
throws WSIFException {
Tr.entry(this, listener, queue);
areWeClosed();
try {
QueueReceiver qr = session.createReceiver(queue);
qr.setMessageListener(listener);
connection.setExceptionListener(listener);
connection.start();
for (int i = 1; !Thread.interrupted(); i++) {
Thread.yield();
Thread.sleep(5000);
System.out.println("JMSAsyncListener waiting... " + i);
}
} catch (JMSException je) {
je.printStackTrace();
throw new WSIFException( je.getMessage() );
} catch (InterruptedException ignored) {
System.out.println("JMSAsyncListener Exitting");
}
Tr.exit();
}
public void stop() {
listener.interrupt();
}
private void processResponse(Message msg) {
System.out.println( "NativeJMSRequestListener got msg:" + msg );
try {
HashMap hm = (HashMap) ((ObjectMessage)msg).getObject();
String name = (String)hm.get( "name" );
String symbol = (String)hm.get( "symbol" );
Address addr = (Address)hm.get( "address" );
Object reply = null;
if ( symbol != null ) {
reply = new Float( sqGetQuote( (ObjectMessage)msg ) );
sendReply( msg, reply );
} else if ( addr != null && name != null ) {
abAddEntry( (ObjectMessage) msg );
} else if ( name != null ) {
reply = abGetAddressFromName( (ObjectMessage) msg );
sendReply( msg, reply );
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void abAddEntry(ObjectMessage msg) throws JMSException {
HashMap hm = (HashMap) msg.getObject();
String name = (String)hm.get( "name" );
Address addr = (Address)hm.get( "address" );
ab.addEntry( name, addr );
}
private Address abGetAddressFromName(ObjectMessage msg) throws JMSException {
HashMap hm = (HashMap) msg.getObject();
String name = (String)hm.get( "name" );
return ab.getAddressFromName( name );
}
private float sqGetQuote(ObjectMessage msg) throws Exception {
HashMap hm = (HashMap) msg.getObject();
String name = (String)hm.get( "symbol" );
return sq.getQuote( name );
}
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() );
}
}