antelder 2003/03/27 04:25:15
Added: java/test/jms JMSURL.wsdl JMSURLTest.java Log: Initial version of support the SOAP over JMS using the soap:address location attribute to define the JMS properties Revision Changes Path 1.1 xml-axis-wsif/java/test/jms/JMSURL.wsdl Index: JMSURL.wsdl =================================================================== <?xml version="1.0" ?> <definitions targetNamespace="http://wsifservice.addressbook/" xmlns:tns="http://wsifservice.addressbook/" xmlns:typens="http://wsiftypes.addressbook/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:format="http://schemas.xmlsoap.org/wsdl/formatbinding/" xmlns:java="http://schemas.xmlsoap.org/wsdl/java/" xmlns:jms="http://schemas.xmlsoap.org/wsdl/jms/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <!-- type defs --> <types> <xsd:schema targetNamespace="http://wsiftypes.addressbook/" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <xsd:complexType name="phone"> <xsd:all> <xsd:element name="areaCode" type="xsd:int"/> <xsd:element name="exchange" type="xsd:string"/> <xsd:element name="number" type="xsd:string"/> </xsd:all> </xsd:complexType> <xsd:complexType name="address"> <xsd:all> <xsd:element name="streetNum" type="xsd:int"/> <xsd:element name="streetName" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="zip" type="xsd:int"/> <xsd:element name="phoneNumber" type="typens:phone"/> </xsd:all> </xsd:complexType> </xsd:schema> </types> <!-- message declns --> <message name="AddEntryWholeNameRequestMessage"> <part name="name" type="xsd:string"/> <part name="address" type="typens:address"/> </message> <message name="AddEntryFirstAndLastNamesRequestMessage"> <part name="firstName" type="xsd:string"/> <part name="lastName" type="xsd:string"/> <part name="address" type="typens:address"/> </message> <message name="GetAddressFromNameRequestMessage"> <part name="name" type="xsd:string"/> </message> <message name="GetAddressFromNameResponseMessage"> <part name="address" type="typens:address"/> </message> <!-- port type declns --> <portType name="AddressBook"> <operation name="addEntry"> <input name="AddEntryWholeNameRequest" message="tns:AddEntryWholeNameRequestMessage"/> </operation> <operation name="addEntry"> <input name="AddEntryFirstAndLastNamesRequest" message="tns:AddEntryFirstAndLastNamesRequestMessage"/> </operation> <operation name="getAddressFromName"> <input name="GetAddressFromNameRequest" message="tns:GetAddressFromNameRequestMessage"/> <output name="GetAddressFromNameResponse" message="tns:GetAddressFromNameResponseMessage"/> </operation> </portType> <!-- binding declns --> <binding name="SOAPHttpBinding" type="tns:AddressBook"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="addEntry"> <soap:operation soapAction=""/> <input name="AddEntryWholeNameRequest"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> <operation name="addEntry"> <soap:operation soapAction=""/> <input name="AddEntryFirstAndLastNamesRequest"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> <operation name="getAddressFromName"> <soap:operation soapAction=""/> <input name="GetAddressFromNameRequest"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output name="GetAddressFromNameResponse"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <binding name="SOAPJmsBinding" type="tns:AddressBook"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/jms"/> <operation name="addEntry"> <soap:operation soapAction=""/> <input name="AddEntryWholeNameRequest"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> <operation name="addEntry"> <soap:operation soapAction=""/> <input name="AddEntryFirstAndLastNamesRequest"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> <operation name="getAddressFromName"> <soap:operation soapAction=""/> <input name="GetAddressFromNameRequest"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output name="GetAddressFromNameResponse"> <soap:body use="encoded" namespace="http://wsifservice.addressbook/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <binding name="JavaBinding" type="tns:AddressBook"> <java:binding/> <format:typeMapping encoding="Java" style="Java"> <format:typeMap typeName="typens:address" formatType="addressbook.wsiftypes.Address" /> <format:typeMap typeName="xsd:string" formatType="java.lang.String" /> </format:typeMapping> <operation name="addEntry"> <java:operation methodName="addEntry" parameterOrder="name address" methodType="instance" /> <input name="AddEntryWholeNameRequest"/> </operation> <operation name="addEntry"> <java:operation methodName="addEntry" parameterOrder="firstName lastName address" methodType="instance" /> <input name="AddEntryFirstAndLastNamesRequest"/> </operation> <operation name="getAddressFromName"> <java:operation methodName="getAddressFromName" parameterOrder="name" methodType="instance" returnPart="address" /> <input name="GetAddressFromNameRequest"/> <output name="GetAddressFromNameResponse"/> </operation> </binding> <binding name="NativeJmsBinding" type="tns:AddressBook"> <jms:binding type="ObjectMessage"/> <format:typeMapping encoding="Java" style="Java"> <format:typeMap typeName="typens:address" formatType="addressbook.wsiftypes.Address" /> <format:typeMap typeName="xsd:string" formatType="java.lang.String" /> </format:typeMapping> <operation name="addEntry"> <input name="AddEntryWholeNameRequest"> <jms:input parts="name address"/> </input> </operation> <operation name="addEntry"> <input name="AddEntryFirstAndLastNamesRequest"/> </operation> <operation name="getAddressFromName"> <input name="GetAddressFromNameRequest"/> <output name="GetAddressFromNameResponse"/> </operation> </binding> <!-- service decln --> <service name="AddressBookService"> <port name="SOAPPort" binding="tns:SOAPHttpBinding"> <soap:address location="http://localhost:8080/soap/servlet/rpcrouter"/> </port> <port name="AXISPort" binding="tns:SOAPHttpBinding"> <soap:address location="http://localhost:8080/axis/services/AddressBook"/> </port> <port name="JavaPort" binding="tns:JavaBinding"> <java:address className="addressbook.wsiftypes.AddressBook"/> </port> <port name="SOAPJMSPort" binding="tns:SOAPJmsBinding"> <!-- <jms:address jndiDestinationName="SoapJmsAddressBookQueue" destinationStyle="queue" jndiConnectionFactoryName="WSIFSampleQCF" initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory" jndiProviderURL="file:///JNDI-Directory"> <jms:propertyValue name="SOAPAction" type="xsd:string" value=" "/> <jms:propertyValue name="SOAPAction" type="xsd:string" value=" "/> </jms:address> --> <soap:address location="jms:/queue?destination=SoapJmsAddressBookQueue|connectionFactory=WSIFSampleQCF|initialContextFactory=com.sun.jndi.fscontext.RefFSContextFactory|jndiProviderURL=file:///JNDI-Directory"/> </port> <port name="NativeJmsPort" binding="tns:NativeJmsBinding"> <jms:address jndiDestinationName="NativeJmsRequestQueue" destinationStyle="queue" jndiConnectionFactoryName="WSIFSampleQCF" initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory" jndiProviderURL="file:///JNDI-Directory"> <jms:propertyValue name="JMSReplyTo" type="xsd:string" value="NativeJmsResponseQueue"/> </jms:address> </port> </service> </definitions> 1.1 xml-axis-wsif/java/test/jms/JMSURLTest.java Index: JMSURLTest.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 [EMAIL PROTECTED] * * 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 jms; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.wsif.WSIFConstants; import org.apache.wsif.WSIFCorrelationId; import org.apache.wsif.WSIFException; import org.apache.wsif.WSIFMessage; import org.apache.wsif.WSIFOperation; import org.apache.wsif.WSIFPort; import org.apache.wsif.WSIFService; import org.apache.wsif.WSIFServiceFactory; import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis; import org.apache.wsif.util.WSIFPluggableProviders; import util.AddressUtility; import util.TestUtilities; import addressbook.wsifservice.AddressBook; import addressbook.wsiftypes.Address; import addressbook.wsiftypes.Phone; import async.AsyncResponseHandler; /** * Junit test to test using the location JMS URL * (Its just the AddressBook test so far...) * * See WSFJMSDestination#getJMSAddressFromURL(String) for details * * @author Ant Elder <[EMAIL PROTECTED]> */ public class JMSURLTest extends TestCase { String wsdlLocation = TestUtilities.getWsdlPath("java\\test\\jms") + "JMSURL.wsdl"; static String server = TestUtilities.getSoapServer().toUpperCase(); static String name1 = "Purdue Boilermaker"; static Address addr1 = new Address( 1, "University Drive", "West Lafayette", "IN", 47907, new Phone(765, "494", "4900")); static String firstName2 = "Someone"; static String lastName2 = "Else"; static Address addr2 = new Address( 0, "Somewhere Else", "No Where", "NO", 71983, new Phone(600, "391", "5682")); public JMSURLTest(String name) { super(name); } public static void main(String[] args) { TestUtilities.startListeners( TestUtilities.ADDRESSBOOK_LISTENER | TestUtilities.ASYNC_LISTENER | TestUtilities.NATIVEJMS_LISTENER); junit.textui.TestRunner.run(suite()); TestUtilities.stopListeners(); } public static Test suite() { return new TestSuite(JMSURLTest.class); } public void setUp() { TestUtilities.setUpExtensionsAndProviders(); } // public void testAxis() { // doit(server+"Port", "axis"); // } // public void testSoap() { // doit(server+"Port", "soap"); // } // public void testJava() { // doit("JavaPort", "java"); // } // public void testSoapJms() { // doit("SOAPJMSPort", "soap"); // } public void testAxisJms() { doit("SOAPJMSPort", "axis"); } // public void testNativeJms() { // doit("NativeJmsPort", "" ); // } // public void testDynamicSOAP() { // doitDyn(server+"Port", "soap", false); // } // public void testDynamicAxis() { // doitDyn(server+"Port", "axis", false); // } // public void testDynamicJava() { // doitDyn("JavaPort", "java", false); // } // public void testDynamicSoapJms() { // doitDyn("SOAPJMSPort", "soap", false); // } // public void testDynamicAxisJms() { // doitDyn("SOAPJMSPort", "axis", false); // } // public void testDynamicNativeJms() { // doitDyn("NativeJmsPort", "", false); // } // public void testDynamicAxisAuto() { // doitDyn(server+"Port", "axis", true); // } // public void testDynamicAxisJmsAuto() { // doitDyn("SOAPJMSPort", "axis", true); // } private void doit(String portName, String protocol) { if (portName.toUpperCase().indexOf("JMS") != -1 && !TestUtilities.areWeTesting("jms")) return; TestUtilities.setProviderForProtocol( protocol ); try { WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); WSIFService service = factory.getService(wsdlLocation, null, // serviceNS null, // serviceName "http://wsifservice.addressbook/", // portTypeNS "AddressBook" ); // portTypeName AddressBook abStub = (AddressBook) service.getStub(portName, AddressBook.class); abStub.addEntry(name1, addr1); abStub.addEntry(firstName2, lastName2, addr2); Address resp1 = abStub.getAddressFromName(name1); assertTrue(new AddressUtility(addr1).equals(resp1)); Address resp2 = abStub.getAddressFromName(firstName2 + " " + lastName2); assertTrue(new AddressUtility(addr2).equals(resp2)); if (TestUtilities.areWeTesting("async")) { testAsyncOPs( service, portName, name1, addr1 ); testAsyncOPs( service, portName, firstName2 + " " + lastName2, addr2 ); } } catch (Exception e) { System.err.println("AddressBookTest(" + portName + ") caught exception " + e); e.printStackTrace(); assertTrue(false); } finally { TestUtilities.resetDefaultProviders(); } } private void doitDyn(String portName, String protocol, boolean autoMapTypes) { if (portName.toUpperCase().indexOf("JMS") != -1 && !TestUtilities.areWeTesting("jms")) return; TestUtilities.setProviderForProtocol( protocol ); try { WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); if (autoMapTypes) { factory.setFeature(WSIFConstants.WSIF_FEATURE_AUTO_MAP_TYPES, new Boolean(true)); } WSIFService service = factory.getService(wsdlLocation, null, // serviceNS null, // serviceName "http://wsifservice.addressbook/", // portTypeNS "AddressBook"); // portTypeName if (!autoMapTypes) { service.mapType( new javax.xml.namespace.QName( "http://wsiftypes.addressbook/", "address"), Class.forName("addressbook.wsiftypes.Address")); service.mapType( new javax.xml.namespace.QName( "http://wsiftypes.addressbook/", "phone"), Class.forName("addressbook.wsiftypes.Phone")); } WSIFPort port = null; port = service.getPort(portName); WSIFOperation operation = port.createOperation("addEntry", "AddEntryWholeNameRequest", null); WSIFMessage inputMessage = operation.createInputMessage(); WSIFMessage outputMessage = operation.createOutputMessage(); WSIFMessage faultMessage = operation.createFaultMessage(); // Create a name and address to add to the addressbook String nameToAdd = "Chris P. Bacon"; Address addressToAdd = new Address( 1, "The Waterfront", "Some City", "NY", 47907, new Phone(765, "494", "4900")); // Add the name and address to the input message inputMessage.setObjectPart("name", nameToAdd); inputMessage.setObjectPart("address", addressToAdd); // Execute the operation, obtaining a flag to indicate its success operation.executeInputOnlyOperation(inputMessage); // Start from fresh operation = null; inputMessage = null; outputMessage = null; faultMessage = null; operation = port.createOperation("getAddressFromName"); // Create the messages inputMessage = operation.createInputMessage(); outputMessage = operation.createOutputMessage(); faultMessage = operation.createFaultMessage(); // Set the name to find in the addressbook String nameToLookup = "Chris P. Bacon"; inputMessage.setObjectPart("name", nameToLookup); // Execute the operation boolean operationSucceeded = operation.executeRequestResponseOperation( inputMessage, outputMessage, faultMessage); if (operationSucceeded) { System.out.println( "Successfull lookup of name '" + nameToLookup + "' in addressbook"); // We can obtain the address that was found by querying the output message Address addressFound = (Address) outputMessage.getObjectPart("address"); System.out.println("The address found was:"); System.out.println(addressFound); } else { System.out.println("Failed to lookup name in addressbook"); } // Check that we can't reuse an operation. boolean caughtException = false; try { operationSucceeded = operation.executeRequestResponseOperation( inputMessage, outputMessage, faultMessage); } catch (WSIFException we) { caughtException = true; } assertTrue(caughtException); } catch (Exception e) { System.err.println("AddressBookTest(" + portName + ") caught exception " + e); e.printStackTrace(); assertTrue(false); } finally { TestUtilities.resetDefaultProviders(); } } private void testAsyncOPs(WSIFService service, String portName, String name, Address addr) { try { WSIFPort port = (portName == null) ? service.getPort() : service.getPort(portName); if (!port.supportsAsync() ) { return; } WSIFOperation op = port.createOperation( "getAddressFromName" ); AsyncResponseHandler abHandler = new AsyncResponseHandler( 1 ); // 1 async call WSIFMessage inMsg = op.createInputMessage(); inMsg.setObjectPart( "name", name ); WSIFMessage outmsg = op.createOutputMessage(); WSIFMessage faultMsg = op.createFaultMessage(); WSIFMessage context = op.getContext(); context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", TestUtilities.getWsifProperty("wsif.async.replytoq") ); op.setContext( context ); WSIFCorrelationId id = op.executeRequestResponseAsync(inMsg, abHandler); assertTrue("null correlation id returned from async request!", id != null ); int i = 10; while (i-- > 0 && !abHandler.isDone()) { System.out.println( "waiting for async responses - " + i ); try { Thread.sleep(3000); } catch (InterruptedException ex) { } } assertTrue("no response from async operation!",i > 0); // no responses in time WSIFMessage[] faults = abHandler.getFaults(); WSIFMessage[] outputs = abHandler.getOutputs(); Address respAddr = (Address) outputs[0].getObjectPart("address"); assertTrue("incorrect address response!", addr.equals(respAddr)); } catch (Exception ex) { ex.printStackTrace(); assertTrue( "exception making async request!!", false ); } } }
