package org.jboss.test.webservice.samples;
import junit.framework.Test;
import org.jboss.axis.client.Call;
import org.jboss.axis.configuration.FileProvider;
import org.jboss.axis.encoding.XMLType;
import org.jboss.axis.transport.jms.JMSConstants;
import org.jboss.axis.transport.jms.JMSTransport;
import org.jboss.test.JBossTestCase;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
public class ServerSideJMSTestCase extends JBossTestCase
{
private static final String ENDPOINT_QUEUE = "queue/MessageDrivenEndpointQueue";
private static final String TARGET_NAMESPACE = "http://org.jboss.test.webservice/samples";
public ServerSideJMSTestCase(String name)
{
super(name);
}
public static Test suite() throws Exception
{
return getDeploySetup(ServerSideJMSTestCase.class, "ws4ee-samples-server-jms.jar");
}
public void testSOAPMessageToEndpointQueue() throws Exception
{
InitialContext ctx = new InitialContext();
HashMap ctxEnv = new HashMap(ctx.getEnvironment());
ctxEnv.put("transport.jms.ConnectionFactoryJNDIName", "UIL2ConnectionFactory");
JMSTransport transport = new JMSTransport(null, ctxEnv);
String clientConfig =
"<deployment name='JMS Test' xmlns='http://xml.apache.org/axis/wsdd/'" +
" xmlns:java='http://xml.apache.org/axis/wsdd/providers/java'>" +
" <handler name='JMSSender' type='java:org.jboss.axis.transport.jms.JMSSender' />" +
" <transport name='JMSTransport' pivot='JMSSender'/>" +
"</deployment>";
try
{
FileProvider config = new FileProvider(new ByteArrayInputStream(clientConfig.getBytes()));
org.jboss.axis.client.Service service = new org.jboss.axis.client.Service(config);
Call call = (Call)service.createCall();
call.setOperationName(new QName(TARGET_NAMESPACE, "getContactInfo"));
call.addParameter("organization", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setProperty(JMSConstants.DESTINATION, ENDPOINT_QUEUE);
call.setTimeout(new Integer(1000));
call.setTransport(transport);
String info = (String)call.invoke(new String[]{"mafia"});
assertEquals("The 'mafia' boss is currently out of office, please call again.", info);
}
finally
{
transport.shutdown();
}
}
}