Debian Codegraph @

test/wsdl/qualify/Qualify_BindingImpl.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
18 /**
19 * Qualify_BindingImpl.java
20 *
21 * Service implementation for Qualified/Nonqualified elements in a complex
22 * type. The service validates the request XML and the test client validates
23 * the response XML to verify the elements that should be namesapce qualified
24 * are, and those that are not supposed to be aren't.
25 */
26
27 package test.wsdl.qualify;
28
29 import org.apache.axis.AxisFault;
30 import org.apache.axis.Message;
31 import org.apache.axis.MessageContext;
32 import org.apache.axis.message.SOAPEnvelope;
33 import org.w3c.dom.Element;
34 import org.w3c.dom.Node;
35 import org.w3c.dom.NodeList;
36
37 public class Qualify_BindingImpl implements test.wsdl.qualify.Qualify_PortType {
38
39 public static final String namespace = "urn:qualifyTest";
40
41 public java.lang.String simple(java.lang.String name) throws java.rmi.RemoteException {
42 // Validate XML request to make sure elements are properly qualified
43 // or not per the WSDL
44 MessageContext mc = MessageContext.getCurrentContext();
45 Message request = mc.getRequestMessage();
46 SOAPEnvelope env = request.getSOAPEnvelope();
47 String requestString = request.getSOAPPartAsString();
48
49 Element body;
50 try {
51 body = env.getFirstBody().getAsDOM();
52 } catch (Exception e) {
53 throw new AxisFault("Unable to get request body as DOM Element on server");
54 }
55
56 // debug
57 //System.err.println("Request:\n---------\n" + requestString + "\n------");
58
59 /*
60 * Here is what we expect the Body to look like:
61 * <Simple xmlns="urn:qualifyTest">
62 * <name>Tommy</name>
63 * </Simple>
64 */
65
66 // Now we have a DOM Element, verfy namespace attributes
67 String simpleNS = body.getNamespaceURI();
68 if (!simpleNS.equals(namespace) ) {
69 throw new AxisFault("Namespace of Simple element incorrect: " +
70 simpleNS + " should be: " + namespace);
71 }
72
73 NodeList list = body.getChildNodes();
74 for(int i=0;i<list.getLength();i++) {
75 Node node = list.item(i);
76 if(node.getNodeType() == Node.TEXT_NODE)
77 continue;
78 String nameNS = node.getNamespaceURI();
79 if (!nameNS.equals("urn:qualifyTest")) {
80 throw new AxisFault("Namespace of name element incorrect: " +
81 nameNS + " should be: urn:qualifyTest");
82 }
83 }
84
85 // Return a response (which the client will validate)
86 return "Hello there: " + name;
87 }
88
89 public test.wsdl.qualify.FormOverrideResponseResponse formOverride(test.wsdl.qualify.FormOverrideComplex complex) throws java.rmi.RemoteException {
90 // Validate XML request to make sure elements are properly qualified
91 // or not per the WSDL
92 MessageContext mc = MessageContext.getCurrentContext();
93 Message request = mc.getRequestMessage();
94 SOAPEnvelope env = request.getSOAPEnvelope();
95 String requestString = request.getSOAPPartAsString();
96
97 Element body;
98 try {
99 body = env.getFirstBody().getAsDOM();
100 } catch (Exception e) {
101 throw new AxisFault("Unable to get request body as DOM Element on server");
102 }
103 // debug
104 //System.err.println("Request:\n---------\n" + requestString + "\n------");
105
106 /*
107 * Here is what we expect the Body to look like:
108 * <FormOverride xmlns="urn:qualifyTest">
109 * <complex xmlns="">
110 * <ns1:name xmlns:ns1="urn:qualifyTest">Timmah</ns1:name>
111 * </complex>
112 * </FormOverride>
113 */
114
115 // Now we have a DOM Element, verfy namespace attributes
116 String FormOverrideNS = body.getNamespaceURI();
117 if (!FormOverrideNS.equals(namespace) ) {
118 throw new AxisFault("Namespace of FormOverrideNS element incorrect: " +
119 FormOverrideNS + " should be: " + namespace);
120 }
121
122 Node complexNode = body.getFirstChild();
123 String complexNS = complexNode.getNamespaceURI();
124 if (complexNS != null ) {
125 throw new AxisFault("Namespace of <complex> element incorrect: " +
126 complexNS + " should be: NULL");
127 }
128
129 // FIXME: for some reason I can't get at the <name> node which is
130 // under the <complex> node. Are we not converting the request to
131 // DOM correctly?
132 if (complexNode.hasChildNodes()) {
133 Node nameNode = complexNode.getFirstChild();
134 String nameNS = nameNode.getNamespaceURI();
135 if (!nameNS.equals(namespace)) {
136 throw new AxisFault("Namespace of <name> element incorrect: " +
137 nameNS + " should be: " + namespace);
138 }
139 }
140
141 // Return a response (which the client will validate)
142 test.wsdl.qualify.FormOverrideResponseResponse r = new FormOverrideResponseResponse();
143 r.setName("Tommy");
144 return r;
145 }
146
147 }