1 57 58 package headers; 59 60 import javax.wsdl.Definition; 61 import javax.wsdl.PortType; 62 import javax.wsdl.Service; 63 import junit.framework.Test; 64 import junit.framework.TestCase; 65 import junit.framework.TestSuite; 66 67 import org.apache.wsif.WSIFConstants; 68 import org.apache.wsif.WSIFMessage; 69 import org.apache.wsif.WSIFOperation; 70 import org.apache.wsif.WSIFPort; 71 import org.apache.wsif.WSIFService; 72 import org.apache.wsif.WSIFServiceFactory; 73 import org.apache.wsif.util.WSIFPluggableProviders; 74 import org.apache.wsif.util.WSIFUtils; 75 import util.TestUtilities; 76 77 88 public class HeadersTest extends TestCase { 89 90 String wsdlLocation = 91 TestUtilities.getWsdlPath("java\\test\\stockquote\\wsifservice") + "Stockquote.wsdl"; 92 static String server = TestUtilities.getSoapServer().toUpperCase(); 93 94 public HeadersTest(String name) { 95 super(name); 96 } 97 98 public static void main(String [] args) { 99 junit.textui.TestRunner.run(suite()); 100 } 101 102 public static Test suite() { 103 return new TestSuite(HeadersTest.class); 104 } 105 106 public void setUp() { 107 TestUtilities.setUpExtensionsAndProviders(); 108 } 109 110 public void testAxis() { 111 doit(server+"Port", "axis"); 112 } 113 public void testSoap() { 114 doit(server+"Port" ,"soap"); 115 } 116 120 private void doit(String portName, String protocol) { 121 122 try { 123 invokeMethod( 124 wsdlLocation, 125 "getQuote", 126 null, 127 null, 128 portName, 129 protocol, 130 new String [] { "" }, 131 0); 132 } catch (Exception e) { 133 System.err.println("AsyncTest(" + portName + ") caught exception " + e); 134 e.printStackTrace(); 135 assertTrue(false); 136 } finally { 137 } 138 139 } 140 141 public static void invokeMethod( 142 String wsdlLocation, 143 String operationName, 144 String inputName, 145 String outputName, 146 String portName, 147 String protocol, 148 String [] args, 149 int argShift) 150 throws Exception { 151 152 String serviceNS = null; 153 String serviceName = null; 154 String portTypeNS = null; 155 String portTypeName = null; 156 157 TestUtilities.setProviderForProtocol( protocol ); 158 159 System.out.println("Reading WSDL document from '" + wsdlLocation + "'"); 160 Definition def = WSIFUtils.readWSDL(null, wsdlLocation); 161 162 Service service = WSIFUtils.selectService(def, serviceNS, serviceName); 163 PortType portType = WSIFUtils.selectPortType(def, portTypeNS, portTypeName); 164 165 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 166 WSIFService dpf = factory.getService(def, service, portType); 167 WSIFPort port = (portName == null) ? dpf.getPort() : dpf.getPort(portName); 168 169 System.out.println("HeadersTest executing getQuote for \"\"" + operationName); 170 WSIFOperation operation = 171 port.createOperation("getQuote", inputName, outputName); 172 WSIFMessage input = operation.createInputMessage(); 173 WSIFMessage output = operation.createOutputMessage(); 174 WSIFMessage fault = operation.createFaultMessage(); 175 input.setObjectPart("symbol", ""); 176 177 WSIFMessage headers = operation.getContext(); 179 headers.setObjectPart(WSIFConstants.CONTEXT_HTTP_USER, "petra"); 180 headers.setObjectPart(WSIFConstants.CONTEXT_HTTP_PSWD, "washere"); 181 operation.setContext(headers); 182 183 boolean ok = operation.executeRequestResponseOperation(input, output, fault); 184 System.out.println("operation returned " + ok); 185 186 float q = ((Float ) output.getObjectPart("quote")).floatValue(); 187 188 if (q == -1.0F) { 189 assertTrue(true); 190 } else { 191 assertTrue(false); 192 } 193 194 System.out.println( 196 "HeadersTest no headers executing getQuote for \"\"" + operationName); 197 operation = port.createOperation("getQuote", inputName, outputName); 198 input = operation.createInputMessage(); 199 output = operation.createOutputMessage(); 200 fault = operation.createFaultMessage(); 201 input.setObjectPart("symbol", ""); 202 ok = operation.executeRequestResponseOperation(input, output, fault); 203 q = ((Float ) output.getObjectPart("quote")).floatValue(); 204 if (q == -1.0F) { 205 assertTrue(true); 206 } else { 207 assertTrue(false); 208 } 209 210 TestUtilities.resetDefaultProviders(); 211 212 } 213 214 } | Popular Tags |