KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > qualify2 > AttributeQualify_BindingImpl


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  * AttributeQualify_BindingImpl.java
20  *
21  * Service implementation for Qualified/Nonqualified attributes in a complex
22  * type. The service validates the request XML and the test client validates
23  * the response XML to verify the attributes that should be namesapce qualified
24  * are, and those that are not supposed to be aren't.
25  */

26
27 package test.wsdl.qualify2;
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.Attr JavaDoc;
34 import org.w3c.dom.Element JavaDoc;
35
36 public class AttributeQualify_BindingImpl implements test.wsdl.qualify2.AttributeQualify_PortType {
37
38     public static final String JavaDoc NAMESPACE = "urn:attributeQualify";
39
40     public test.wsdl.qualify2.Phone echoPhone(test.wsdl.qualify2.Phone in) throws java.rmi.RemoteException JavaDoc {
41
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 JavaDoc requestString = request.getSOAPPartAsString();
48
49         Element JavaDoc body;
50         try {
51             body = env.getFirstBody().getAsDOM();
52         } catch (Exception JavaDoc e) {
53             throw new AxisFault("Unable to get request body as DOM Element on server");
54         }
55         
56         // Now we have a DOM Element, verfy namespace attributes
57
// Here is what we think it looks like
58
// <phone age="35"
59
// ns1:color="red"
60
// ns1:hair="brown"
61
// xmlns:ns1="urn:attributeQualify">
62
// <areaCode>505</areaCode>
63
// <exchange>555</exchange>
64
// <number>1212</number>
65
//</phone>
66

67         String JavaDoc bodyNS = body.getNamespaceURI();
68         if (! NAMESPACE.equals(bodyNS))
69         throw new AxisFault("On Server: Namespace of body element incorrect: " +
70                                 bodyNS + " should be: " + NAMESPACE);
71
72         // Verify age does NOT have a namespace (unqualified)
73
Attr JavaDoc ageAttr = body.getAttributeNode("age");
74         if (ageAttr.getNamespaceURI() != null) {
75             throw new AxisFault("On Server: Namespace of age attribute incorrect: "
76                              + ageAttr.getNamespaceURI() + " should be: NULL");
77         }
78         
79         // Verify hair and color have the right namespace (are qualified).
80
Attr JavaDoc hairAttr = body.getAttributeNodeNS(NAMESPACE, "hair");
81         if (hairAttr == null) {
82             throw new AxisFault("On Server: Missing namespace for attribute 'hair' should be: " + NAMESPACE);
83         }
84         
85         Attr JavaDoc colorAttr = body.getAttributeNodeNS(NAMESPACE, "color");
86         if (hairAttr == null) {
87             throw new AxisFault("On Server: Missing namespace for attribute 'color' should be: " + NAMESPACE);
88         }
89
90         // Echo input
91
return in;
92     }
93
94 }
95
Popular Tags