Debian Codegraph @

test/soap/TestOnFaultHeaders.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
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 /**
34 * Confirm OnFault() header processing + additions work right.
35 *
36 * @author Glen Daniels ([email protected])
37 */
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 /**
70 * Add a header which will trigger a fault in the TestHandler, and
71 * therefore trigger the onFault() in the TestFaultHandler. That should
72 * put a header in the outgoing message, which we check for when we get
73 * the fault.
74 *
75 * @throws Exception
76 */
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 }