KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > jbws464 > SAAJTestHandler


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.webservice.jbws464;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import javax.xml.rpc.handler.GenericHandler JavaDoc;
26 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
27 import javax.xml.rpc.handler.MessageContext JavaDoc;
28 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
29 import javax.xml.soap.SOAPEnvelope JavaDoc;
30 import javax.xml.soap.SOAPPart JavaDoc;
31 import javax.xml.soap.SOAPException JavaDoc;
32
33 import org.jboss.logging.Logger;
34 import org.w3c.dom.Document JavaDoc;
35
36 public class SAAJTestHandler extends GenericHandler JavaDoc
37 {
38    // provide logging
39
private static Logger log = Logger.getLogger(SAAJTestHandler.class);
40
41    protected QName JavaDoc[] headers;
42
43    public QName JavaDoc[] getHeaders()
44    {
45       return headers;
46    }
47
48    public void init(HandlerInfo JavaDoc config)
49    {
50       headers = config.getHeaders();
51    }
52
53    public void destroy()
54    {
55    }
56
57    public boolean handleRequest(MessageContext JavaDoc msgContext)
58    {
59       try
60       {
61          log.info("handleRequest");
62          SOAPMessageContext JavaDoc context = (SOAPMessageContext JavaDoc) msgContext;
63          SOAPPart JavaDoc part = context.getMessage().getSOAPPart();
64          SOAPEnvelope JavaDoc env = (SOAPEnvelope JavaDoc) part.getDocumentElement();
65          Document JavaDoc doc = env.getOwnerDocument();
66          if (doc == null)
67             throw new IllegalStateException JavaDoc("Document from SOAPPart is null");
68          if (part != doc)
69             throw new IllegalStateException JavaDoc("Document != SOAPPart");
70          if (env.getBody().getOwnerDocument() != doc)
71             throw new IllegalStateException JavaDoc("SOAPBody does not have SOAPPart as its parent!");
72       }
73       catch (SOAPException JavaDoc e)
74       {
75          throw new RuntimeException JavaDoc(e);
76       }
77
78       return true;
79    }
80
81    public boolean handleResponse(MessageContext JavaDoc msgContext)
82    {
83       log.info("handleResponse");
84       SOAPMessageContext JavaDoc context = (SOAPMessageContext JavaDoc) msgContext;
85       SOAPPart JavaDoc part = context.getMessage().getSOAPPart();
86       SOAPEnvelope JavaDoc env = (SOAPEnvelope JavaDoc) part.getDocumentElement();
87       Document JavaDoc doc = env.getOwnerDocument();
88       if (doc == null)
89          throw new IllegalStateException JavaDoc("Document from SOAPPart is null");
90
91       return true;
92    }
93
94    public boolean handleFault(MessageContext JavaDoc msgContext)
95    {
96       log.info("handleFault");
97       log.info("IGNORE THE EXCEPTION:This is a test only");
98       SOAPMessageContext JavaDoc context = (SOAPMessageContext JavaDoc) msgContext;
99       SOAPPart JavaDoc part = context.getMessage().getSOAPPart();
100       SOAPEnvelope JavaDoc env = (SOAPEnvelope JavaDoc) part.getDocumentElement();
101       Document JavaDoc doc = env.getOwnerDocument();
102       if (doc == null)
103          throw new IllegalStateException JavaDoc("Document from SOAPPart is null");
104
105       return true;
106    }
107 }
108
Popular Tags