KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > samples > ServerSideJMSTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.webservice.samples;
8
9 // $Id: ServerSideJMSTestCase.java,v 1.1.2.2 2005/03/02 14:51:06 tdiesler Exp $
10

11 import junit.framework.Test;
12 import org.jboss.axis.client.Call;
13 import org.jboss.axis.configuration.FileProvider;
14 import org.jboss.axis.encoding.XMLType;
15 import org.jboss.axis.transport.jms.JMSConstants;
16 import org.jboss.axis.transport.jms.JMSTransport;
17 import org.jboss.test.JBossTestCase;
18
19 import javax.naming.InitialContext JavaDoc;
20 import javax.xml.namespace.QName JavaDoc;
21 import javax.xml.rpc.ParameterMode JavaDoc;
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.util.HashMap JavaDoc;
24
25
26 /**
27  * A web service client that connects to a MDB endpoint using
28  * the dynamic invokation interface (DII).
29  *
30  * @author Thomas.Diesler@jboss.org
31  * @since 26-Apr-2004
32  */

33 public class ServerSideJMSTestCase extends JBossTestCase
34 {
35    private static final String JavaDoc ENDPOINT_QUEUE = "queue/MessageDrivenEndpointQueue";
36    private static final String JavaDoc TARGET_NAMESPACE = "http://org.jboss.test.webservice/samples";
37
38    public ServerSideJMSTestCase(String JavaDoc name)
39    {
40       super(name);
41    }
42
43    /** Deploy the test */
44    public static Test suite() throws Exception JavaDoc
45    {
46       return getDeploySetup(ServerSideJMSTestCase.class, "ws4ee-samples-server-jms.jar");
47    }
48
49    /**
50     * Construct an Axis call and use JMSTransport to send it to the specified queue
51     */

52    public void testSOAPMessageToEndpointQueue() throws Exception JavaDoc
53    {
54       // create the transport
55
InitialContext JavaDoc ctx = new InitialContext JavaDoc();
56       HashMap JavaDoc ctxEnv = new HashMap JavaDoc(ctx.getEnvironment());
57       ctxEnv.put("transport.jms.ConnectionFactoryJNDIName", "UIL2ConnectionFactory");
58       JMSTransport transport = new JMSTransport(null, ctxEnv);
59
60       String JavaDoc clientConfig =
61               "<deployment name='JMS Test' xmlns='http://xml.apache.org/axis/wsdd/'" +
62               " xmlns:java='http://xml.apache.org/axis/wsdd/providers/java'>" +
63               " <handler name='JMSSender' type='java:org.jboss.axis.transport.jms.JMSSender' />" +
64               " <transport name='JMSTransport' pivot='JMSSender'/>" +
65               "</deployment>";
66       try
67       {
68          // create a new Call object
69
FileProvider config = new FileProvider(new ByteArrayInputStream JavaDoc(clientConfig.getBytes()));
70          org.jboss.axis.client.Service service = new org.jboss.axis.client.Service(config);
71          Call call = (Call)service.createCall();
72
73          call.setOperationName(new QName JavaDoc(TARGET_NAMESPACE, "getContactInfo"));
74          call.addParameter("organization", XMLType.XSD_STRING, ParameterMode.IN);
75          call.setReturnType(XMLType.XSD_STRING);
76          call.setProperty(JMSConstants.DESTINATION, ENDPOINT_QUEUE);
77          call.setTimeout(new Integer JavaDoc(1000));
78          call.setTransport(transport);
79
80          String JavaDoc info = (String JavaDoc)call.invoke(new String JavaDoc[]{"mafia"});
81          assertEquals("The 'mafia' boss is currently out of office, please call again.", info);
82       }
83       finally
84       {
85          transport.shutdown();
86       }
87    }
88 }
89
Popular Tags