001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package headers;
059:
060: import javax.wsdl.Definition;
061: import javax.wsdl.PortType;
062: import javax.wsdl.Service;
063: import junit.framework.Test;
064: import junit.framework.TestCase;
065: import junit.framework.TestSuite;
066:
067: import org.apache.wsif.WSIFConstants;
068: import org.apache.wsif.WSIFMessage;
069: import org.apache.wsif.WSIFOperation;
070: import org.apache.wsif.WSIFPort;
071: import org.apache.wsif.WSIFService;
072: import org.apache.wsif.WSIFServiceFactory;
073: import org.apache.wsif.util.WSIFPluggableProviders;
074: import org.apache.wsif.util.WSIFUtils;
075: import util.TestUtilities;
076:
077: /**
078: * Junit test to test out the Asynchronous requests.
079: *
080: * Tests the get/setContext methods using the stockquote sample
081: * the context allows seting HTTP and SOAP headers, HTTP headers
082: * are currently only uid/pswd for basic authentication.
083: * Currently all this does is set them so you can see thme in
084: * the packets using TCPMON.
085: * You should see this at the top of the out going packet:
086: * Authorization: Basic cGV0cmE6d2FzaGVyZQ==
087: */
088: public class HeadersTest extends TestCase {
089:
090: String wsdlLocation = TestUtilities
091: .getWsdlPath("java\\test\\stockquote\\wsifservice")
092: + "Stockquote.wsdl";
093: static String server = TestUtilities.getSoapServer().toUpperCase();
094:
095: public HeadersTest(String name) {
096: super (name);
097: }
098:
099: public static void main(String[] args) {
100: junit.textui.TestRunner.run(suite());
101: }
102:
103: public static Test suite() {
104: return new TestSuite(HeadersTest.class);
105: }
106:
107: public void setUp() {
108: TestUtilities.setUpExtensionsAndProviders();
109: }
110:
111: public void testAxis() {
112: doit(server + "Port", "axis");
113: }
114:
115: public void testSoap() {
116: doit(server + "Port", "soap");
117: }
118:
119: //public void testJava () { doit("JavaPort" ,"java"); }
120: //public void testSoapJms () { if (TestUtilities.areWeTesting("jms")) doit("SOAPJMSPort","soap"); }
121: //public void testAxisJms () { if (TestUtilities.areWeTesting("jms")) doit("SOAPJMSPort","axis"); }
122:
123: private void doit(String portName, String protocol) {
124:
125: try {
126: invokeMethod(wsdlLocation, "getQuote", null, null,
127: portName, protocol, new String[] { "" }, 0);
128: } catch (Exception e) {
129: System.err.println("AsyncTest(" + portName
130: + ") caught exception " + e);
131: e.printStackTrace();
132: assertTrue(false);
133: } finally {
134: }
135:
136: }
137:
138: public static void invokeMethod(String wsdlLocation,
139: String operationName, String inputName, String outputName,
140: String portName, String protocol, String[] args,
141: int argShift) throws Exception {
142:
143: String serviceNS = null;
144: String serviceName = null;
145: String portTypeNS = null;
146: String portTypeName = null;
147:
148: TestUtilities.setProviderForProtocol(protocol);
149:
150: System.out.println("Reading WSDL document from '"
151: + wsdlLocation + "'");
152: Definition def = WSIFUtils.readWSDL(null, wsdlLocation);
153:
154: Service service = WSIFUtils.selectService(def, serviceNS,
155: serviceName);
156: PortType portType = WSIFUtils.selectPortType(def, portTypeNS,
157: portTypeName);
158:
159: WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
160: WSIFService dpf = factory.getService(def, service, portType);
161: WSIFPort port = (portName == null) ? dpf.getPort() : dpf
162: .getPort(portName);
163:
164: System.out.println("HeadersTest executing getQuote for \"\""
165: + operationName);
166: WSIFOperation operation = port.createOperation("getQuote",
167: inputName, outputName);
168: WSIFMessage input = operation.createInputMessage();
169: WSIFMessage output = operation.createOutputMessage();
170: WSIFMessage fault = operation.createFaultMessage();
171: input.setObjectPart("symbol", "");
172:
173: // set a basic authentication header
174: WSIFMessage headers = operation.getContext();
175: headers.setObjectPart(WSIFConstants.CONTEXT_HTTP_USER, "petra");
176: headers.setObjectPart(WSIFConstants.CONTEXT_HTTP_PSWD,
177: "washere");
178: operation.setContext(headers);
179:
180: boolean ok = operation.executeRequestResponseOperation(input,
181: output, fault);
182: System.out.println("operation returned " + ok);
183:
184: float q = ((Float) output.getObjectPart("quote")).floatValue();
185:
186: if (q == -1.0F) {
187: assertTrue(true);
188: } else {
189: assertTrue(false);
190: }
191:
192: // do it agian without context so you can see the difference
193: System.out
194: .println("HeadersTest no headers executing getQuote for \"\""
195: + operationName);
196: operation = port.createOperation("getQuote", inputName,
197: outputName);
198: input = operation.createInputMessage();
199: output = operation.createOutputMessage();
200: fault = operation.createFaultMessage();
201: input.setObjectPart("symbol", "");
202: ok = operation.executeRequestResponseOperation(input, output,
203: fault);
204: q = ((Float) output.getObjectPart("quote")).floatValue();
205: if (q == -1.0F) {
206: assertTrue(true);
207: } else {
208: assertTrue(false);
209: }
210:
211: TestUtilities.resetDefaultProviders();
212:
213: }
214:
215: }
|