001: /*
002: * Timer: The timer class
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * RPCClientTestImpl.java
020: */
021:
022: package test.client;
023:
024: import com.rift.coad.daemon.messageservice.Message;
025: import com.rift.coad.daemon.messageservice.MessageProducer;
026: import com.rift.coad.daemon.messageservice.MessageServiceException;
027: import com.rift.coad.daemon.messageservice.Producer;
028: import com.rift.coad.daemon.messageservice.TextMessage;
029: import java.rmi.Remote;
030: import java.rmi.RemoteException;
031: import java.util.Date;
032: import java.util.HashSet;
033: import java.util.Set;
034: import com.rift.coad.daemon.messageservice.rpc.RPCMessageClient;
035: import javax.naming.Context;
036: import javax.naming.InitialContext;
037: import javax.naming.NamingException;
038: import javax.rmi.PortableRemoteObject;
039: import test.server.RPCServerTest;
040:
041: public class RPCClientTestImpl implements RPCClientTest {
042:
043: public String testID = "";
044:
045: public RPCClientTestImpl() {
046: }
047:
048: public void runBasicTest(String testString) throws RemoteException,
049: MessageTestException {
050: try {
051: System.out.println("The runtime class");
052: RPCServerTestAsync async = (RPCServerTestAsync) RPCMessageClient
053: .create("RPCClientTest", RPCServerTest.class,
054: RPCServerTestAsync.class, "RPCServerTest");
055:
056: testID = async.testMethod(testString);
057: System.out.println("End of method : " + testID);
058: } catch (Throwable ex) {
059: System.out.println("The test run failed : "
060: + ex.getMessage());
061: ex.printStackTrace(System.out);
062: throw new MessageTestException("The test run failed : "
063: + ex.getMessage(), ex);
064: }
065: }
066:
067: public synchronized void onSuccess(String messageId,
068: String correllationId, Object result)
069: throws RemoteException {
070:
071: if (messageId == testID) {
072: System.out.println("ID: " + result.toString());
073: }
074:
075: }
076:
077: public synchronized void onFailure(String messageId,
078: String correllationId, Throwable caught)
079: throws RemoteException {
080:
081: System.out.println("The exception is not a message test "
082: + "exception : " + caught.getClass().getName());
083:
084: }
085:
086: public void runBasicMessageTest(String testString)
087: throws RemoteException, MessageTestException {
088: System.out.println("The beginning of the start test method");
089: Context context;
090: try {
091: context = new InitialContext();
092: MessageProducer messageProducer = (MessageProducer) PortableRemoteObject
093: .narrow(context.lookup(MessageProducer.JNDI_URL),
094: MessageProducer.class);
095: Producer producer = messageProducer
096: .createProducer("RPCClientTest");
097: TextMessage textMessage = producer
098: .createTextMessage(Message.POINT_TO_POINT);
099: textMessage.setTarget("TextServerTest");
100: textMessage.setReply(true);
101: textMessage.setTextBody(testString);
102: producer.submit(textMessage);
103: } catch (Exception ex) {
104: throw new MessageTestException("Text message failure:", ex);
105: }
106: }
107:
108: public Message processMessage(Message message)
109: throws RemoteException, MessageServiceException {
110: TextMessage textMessage = (TextMessage) message;
111: System.out.println("Message is : " + textMessage.getTextBody());
112: textMessage.acknowledge();
113: return textMessage;
114: }
115: }
|