You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by an...@apache.org on 2002/06/20 12:58:57 UTC
cvs commit: xml-axis-wsif/java/test/org/apache/wsif/util/jms JMSAsyncListener.java
antelder 2002/06/20 03:58:57
Added: java/test/org/apache/wsif/util/jms JMSAsyncListener.java
Removed: java/src/org/apache/wsif/util/jms JMSAsyncListener.java
Log:
Move JMSAsyncListener to the test packages folder
Revision Changes Path
1.1 xml-axis-wsif/java/test/org/apache/wsif/util/jms/JMSAsyncListener.java
Index: JMSAsyncListener.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 apache@apache.org.
*
* 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 java.util.ArrayList;
import java.util.Arrays;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueReceiver;
import org.apache.wsif.WSIFException;
import org.apache.wsif.logging.Tr;
import org.apache.wsif.util.jms.*;
import org.apache.wsif.util.*;
import org.apache.wsif.*;
import org.apache.wsif.util.jms.WSIFJMSCorrelationId;
import java.io.Serializable;
/**
* A simple JMS listener which can be used to test async operations
* @author ant elder <an...@apache.org>
*/
public class JMSAsyncListener extends JMS2HTTPBridgeDestination {
static final String startType = JMS2HTTPBridgeDestination.COLDSTART;
static final String initialContextFactory = "com.sun.jndi.fscontext.RefFSContextFactory";
static final String jndiUrl = "file:///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;
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 JMSAsyncListener(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) {
throw WSIFJMSConstants.ToWsifException(je);
} catch (InterruptedException ignored) {
System.out.println("JMSAsyncListener Exitting");
}
Tr.exit();
}
private void processResponse(Message msg) {
Serializable so;
try {
System.out.println( "WSIFJmsAsyncListener.processResponse called" );
WSIFCorrelationService cs =
WSIFCorrelationServiceLocator.getCorrelationService();
WSIFCorrelationId cid = new WSIFJMSCorrelationId( msg.getJMSCorrelationID() );
synchronized( cs ) {
so = cs.get( cid );
}
if ( so != null && so instanceof WSIFOperation ) {
cs.remove( cid );
((WSIFOperation) so).fireAsyncResponse( msg );
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void stop() {
listener.interrupt();
}
}