KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > soap > TestFaultHandler


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 package test.soap;
17
18 import org.apache.axis.AxisFault;
19 import org.apache.axis.MessageContext;
20 import org.apache.axis.handlers.BasicHandler;
21 import org.apache.axis.message.SOAPEnvelope;
22 import org.apache.axis.message.SOAPHeaderElement;
23
24 /**
25  * This is a test Handler which interacts with the TestService below in
26  * order to test header processing. This one runs before the TestHandler,
27  * so when the TestHandler throws an Exception (triggered by a particular
28  * header being sent from TestOnFaultHeaders), the onFault() method gets
29  * called. In there, we get the response message and add a header to it.
30  * This header gets picked up by the client, who checks that it looks right
31  * and has successfully propagated from here to the top of the call stack.
32  *
33  * @author Glen Daniels (gdaniels@apache.org)
34  */

35 public class TestFaultHandler extends BasicHandler {
36     public void invoke(MessageContext msgContext) throws AxisFault {
37     }
38
39     public void onFault(MessageContext msgContext) {
40         try {
41             SOAPEnvelope env = msgContext.getResponseMessage().getSOAPEnvelope();
42             SOAPHeaderElement header = new SOAPHeaderElement(
43                     TestOnFaultHeaders.TRIGGER_NS,
44                     TestOnFaultHeaders.RESP_NAME,
45                     "here's the value"
46             );
47             env.addHeader(header);
48         } catch (Exception JavaDoc e) {
49             throw new RuntimeException JavaDoc("Exception during onFault processing");
50         }
51     }
52 }
53
Popular Tags