01: /*
02: * MessageTest: This is a test message service library.
03: * Copyright (C) 2007 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * NamedClient1Impl.java
20: */
21:
22: package test.client.named;
23:
24: // java imports
25: import java.util.Date;
26: import javax.naming.Context;
27: import javax.naming.InitialContext;
28: import javax.naming.NamingException;
29: import javax.rmi.PortableRemoteObject;
30:
31: // coadunation imports
32: import com.rift.coad.daemon.messageservice.MessageService;
33: import com.rift.coad.daemon.messageservice.MessageServiceException;
34: import com.rift.coad.daemon.messageservice.Message;
35: import com.rift.coad.daemon.messageservice.MessageProducer;
36: import com.rift.coad.daemon.messageservice.Producer;
37: import com.rift.coad.daemon.messageservice.TextMessage;
38:
39: /**
40: * This object is responsible for implementing named client interface.
41: *
42: * @author Brett Chaldecott
43: */
44: public class NamedClientImpl implements NamedClient {
45:
46: // private member variables
47: private Context context = null;
48: private int results = 0;
49:
50: /** Creates a new instance of NamedClient1Impl */
51: public NamedClientImpl() throws NamedTestException {
52: try {
53: context = new InitialContext();
54: } catch (Exception ex) {
55: throw new NamedTestException(
56: "Failed to instanciate the named test "
57: + "client : " + ex.getMessage(), ex);
58: }
59: }
60:
61: /**
62: * This method is called to run a basic named message test.
63: *
64: * @param numMessages The number of messages to test the queues with.
65: * @exception MessageTestException
66: */
67: public void runBasicTest(String text) throws NamedTestException {
68: System.out.println("The beginning of the start test method");
69: MessageProducer messageProducer;
70: try {
71: messageProducer = (MessageProducer) PortableRemoteObject
72: .narrow(context.lookup(MessageProducer.JNDI_URL),
73: MessageProducer.class);
74:
75: Producer producer = messageProducer
76: .createProducer(JNDI_URL);
77: TextMessage textMessage = producer
78: .createTextMessage(Message.POINT_TO_POINT);
79: textMessage.setTarget(MessageService.JNDI_URL);
80: textMessage.setTargetNamedQueue("test");
81: textMessage.setReply(false);
82: textMessage.setTextBody(text);
83: producer.submit(textMessage);
84:
85: System.out.println("After result");
86: } catch (Exception ex) {
87: throw new NamedTestException("The test failed:", ex);
88: }
89: }
90:
91: }
|