Debian Codegraph @

test/MSGDispatch/TestService.java

raw
1 /*
2 * Copyright 2002-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.MSGDispatch;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.message.SOAPBodyElement;
21 import org.apache.axis.message.SOAPEnvelope;
22 import org.apache.axis.message.SOAPHeaderElement;
23 import org.apache.axis.utils.XMLUtils;
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.InputStream;
29
30 /**
31 * This class is a message-based service with three methods. It tests:
32 *
33 * 1) Our ability to dispatch to multiple methods for a message service
34 * 2) That each of the valid signatures works as expected
35 *
36 * @author Glen Daniels ([email protected])
37 */
38 public class TestService {
39 // Adding these dummy methods to make sure that when we deploy this
40 // service using "allowedMethods="*" that we don't barf on them.
41 // This will ensure that people can take classes that have public
42 // methods (some available thru Axis and some not) and still be able
43 // to deploy them. (We used to throw exceptions about it)
44 public void testBody(int t) {}
45 public void testElement(int t) {}
46 public void testEnvelope(int t) {}
47
48 public SOAPBodyElement [] testBody(SOAPBodyElement [] bodies)
49 throws Exception {
50
51 String xml = "<m:bodyResult xmlns:m=\"http://db.com\"/>" ;
52 InputStream is = new ByteArrayInputStream(xml.getBytes());
53 SOAPBodyElement result = new SOAPBodyElement(is);
54 return new SOAPBodyElement [] { result };
55 }
56
57 public Element [] testElement(Element [] bodyElems)
58 throws Exception {
59 if (bodyElems == null || bodyElems.length != 1) {
60 throw new AxisFault("Wrong number of Elements in array!");
61 }
62 Element el = bodyElems[0];
63 if (el == null) {
64 throw new AxisFault("Null Element in array!");
65 }
66 if (!"http://db.com".equals(el.getNamespaceURI())) {
67 throw new AxisFault("Wrong namespace for Element (was \"" +
68 el.getNamespaceURI() + "\" should be " +
69 "\"http://db.com\"!");
70 }
71 String xml = "<m:elementResult xmlns:m=\"http://db.com\"/>" ;
72 Document doc = XMLUtils.newDocument(
73 new ByteArrayInputStream(xml.getBytes()));
74 Element result = doc.getDocumentElement();
75 return new Element [] { result };
76 }
77
78 public Element [] testElementEcho(Element [] bodyElems)
79 throws Exception {
80 return bodyElems;
81 }
82
83 public void testEnvelope(SOAPEnvelope req, SOAPEnvelope resp)
84 throws Exception {
85 // Throw a header in and echo back.
86 SOAPBodyElement body = req.getFirstBody();
87 resp.addBodyElement(body);
88 resp.addHeader(new SOAPHeaderElement("http://db.com", "local", "value"));
89 }
90 }