KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > soap > TestHandler


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. If a particular header appears in
27  * the message, we mark the MessageContext so the TestService knows to
28  * double its results (which is a detectable way of confirming header
29  * processing on the client side).
30  */

31 public class TestHandler extends BasicHandler {
32     public void invoke(MessageContext msgContext) throws AxisFault {
33         SOAPEnvelope env = msgContext.getRequestMessage().getSOAPEnvelope();
34         if (env.getHeaderByName(TestHeaderAttrs.GOOD_HEADER_NS,
35                                 TestHeaderAttrs.GOOD_HEADER_NAME) != null) {
36             // Just the header's presence is enough - mark the property
37
// so it can be picked up by the service (see below)
38
msgContext.setProperty(TestHeaderAttrs.PROP_DOUBLEIT, Boolean.TRUE);
39         }
40         
41         if (env.getHeaderByName(TestOnFaultHeaders.TRIGGER_NS,
42                                 TestOnFaultHeaders.TRIGGER_NAME) != null) {
43             // Fault trigger header is there, so throw an Exception
44
throw new AxisFault("triggered exception");
45         }
46     }
47
48     public void onFault(MessageContext msgContext) {
49         try {
50             SOAPEnvelope env = msgContext.getResponseMessage().getSOAPEnvelope();
51             SOAPHeaderElement header = new SOAPHeaderElement("ns", "local", "val");
52             env.addHeader(header);
53         } catch (Exception JavaDoc e) {
54             throw new RuntimeException JavaDoc("Exception during onFault processing");
55         }
56     }
57 }
58
Popular Tags