1 16 17 package test.soap; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.SimpleChain; 21 import org.apache.axis.client.Call; 22 import org.apache.axis.client.Service; 23 import org.apache.axis.configuration.SimpleProvider; 24 import org.apache.axis.handlers.soap.SOAPService; 25 import org.apache.axis.message.SOAPEnvelope; 26 import org.apache.axis.message.SOAPHeaderElement; 27 import org.apache.axis.providers.java.RPCProvider; 28 import org.apache.axis.server.AxisServer; 29 import org.apache.axis.transport.local.LocalTransport; 30 31 import java.util.Vector ; 32 33 38 public class TestOnFaultHeaders extends TestCase { 39 public static String TRIGGER_NS = "http://trigger-fault"; 40 public static String TRIGGER_NAME = "faultPlease"; 41 public static String RESP_NAME = "okHeresYourFault"; 42 43 private SimpleProvider provider = new SimpleProvider(); 44 private AxisServer engine = new AxisServer(provider); 45 private LocalTransport localTransport = new LocalTransport(engine); 46 47 static final String localURL = "local:///testService"; 48 49 public TestOnFaultHeaders(String s) { 50 super(s); 51 } 52 53 public void setUp() throws Exception { 54 engine.init(); 55 localTransport.setUrl(localURL); 56 SimpleChain chain = new SimpleChain(); 57 chain.addHandler(new TestFaultHandler()); 58 chain.addHandler(new TestHandler()); 59 SOAPService service = new SOAPService(chain, 60 new RPCProvider(), 61 null); 62 63 service.setOption("className", TestService.class.getName()); 64 service.setOption("allowedMethods", "*"); 65 66 provider.deployService("testService", service); 67 } 68 69 77 public void testOnFaultHeaders() throws Exception { 78 Call call = new Call(new Service()); 79 call.setTransport(localTransport); 80 81 SOAPHeaderElement header = new SOAPHeaderElement(TRIGGER_NS, 82 TRIGGER_NAME, 83 "do it"); 84 85 call.addHeader(header); 86 87 try { 88 call.invoke("countChars", new Object [] { "foo" }); 89 } catch (Exception e) { 90 SOAPEnvelope env = call.getResponseMessage().getSOAPEnvelope(); 91 Vector headers = env.getHeaders(); 92 assertEquals("Wrong # of headers in fault!", 1, headers.size()); 93 SOAPHeaderElement respHeader = (SOAPHeaderElement)headers.get(0); 94 assertEquals("Wrong namespace for header", TRIGGER_NS, 95 respHeader.getNamespaceURI()); 96 assertEquals("Wrong localName for response header", RESP_NAME, 97 respHeader.getName()); 98 return; 99 } 100 101 fail("We should have gotten a fault!"); 102 } 103 } 104 | Popular Tags |