KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > arrays2 > TestArrays2TestCase


1 package test.wsdl.arrays2;
2
3 import org.apache.axis.Constants;
4 import org.apache.axis.Message;
5 import org.apache.axis.MessageContext;
6 import org.apache.axis.encoding.TypeMapping;
7 import org.apache.axis.encoding.TypeMappingRegistry;
8 import org.apache.axis.message.RPCElement;
9 import org.apache.axis.message.RPCParam;
10 import org.apache.axis.message.SOAPEnvelope;
11 import org.apache.axis.server.AxisServer;
12
13 import test.wsdl.arrays2.data.*;
14 import test.wsdl.arrays2.data.inner.*;
15
16 import java.util.Vector JavaDoc;
17
18 public class TestArrays2TestCase extends junit.framework.TestCase {
19     public TestArrays2TestCase(String JavaDoc name) {
20         super(name);
21     }
22
23     private static AxisServer server = new AxisServer();
24
25     private static String JavaDoc xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
26             "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
27             " <env:Header/>\n" +
28             " <env:Body env:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
29             " <m:getDataOperationResponse xmlns:m=\"http://www.xyz.net/webservices/arraytest/1.0\">\n" +
30             " <dataResponse xmlns:n1=\"http://www.xyz.net/schemas/arraytest/data/1.0\" xsi:type=\"n1:dataType\">\n" +
31             " <innerData soapenc:arrayType=\"n2:innerDataType[10]\" xmlns:n2=\"http://www.xyz.net/schemas/arraytest/innerdata/1.0\">\n" +
32             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
33             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
34             "desc#0 HELLO! </trDescr>\n" +
35             " </innerDataType>\n" +
36             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
37             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
38             "desc#1 HELLO! </trDescr>\n" +
39             " </innerDataType>\n" +
40             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
41             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
42             "desc#2 HELLO! </trDescr>\n" +
43             " </innerDataType>\n" +
44             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
45             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
46             "desc#3 HELLO! </trDescr>\n" +
47             " </innerDataType>\n" +
48             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
49             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
50             "desc#4 HELLO! </trDescr>\n" +
51             " </innerDataType>\n" +
52             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
53             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
54             "desc#5 HELLO! </trDescr>\n" +
55             " </innerDataType>\n" +
56             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
57             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
58             "desc#6 HELLO! </trDescr>\n" +
59             " </innerDataType>\n" +
60             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
61             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
62             "desc#7 HELLO! </trDescr>\n" +
63             " </innerDataType>\n" +
64             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
65             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
66             "desc#8 HELLO! </trDescr>\n" +
67             " </innerDataType>\n" +
68             " <innerDataType xsi:type=\"n2:innerDataType\">\n" +
69             " <trDescr xsi:type=\"n2:trDescrType\">\n" +
70             "desc#9 HELLO! </trDescr>\n" +
71             " </innerDataType>\n" +
72             " </innerData>\n" +
73             " </dataResponse>\n" +
74             " </m:getDataOperationResponse>\n" +
75             " </env:Body>\n" +
76             "</env:Envelope>";
77
78     public void testBug22213() throws Exception JavaDoc {
79         TypeMappingRegistry tmr = server.getTypeMappingRegistry();
80         TypeMapping tm = (TypeMapping) tmr.createTypeMapping();
81         tm.setSupportedEncodings(new String JavaDoc[]{Constants.URI_DEFAULT_SOAP_ENC});
82         tmr.register(Constants.URI_DEFAULT_SOAP_ENC, tm);
83         tm.register(test.wsdl.arrays2.data.DataType.class,
84                 new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/data/1.0", "dataType"),
85                 new org.apache.axis.encoding.ser.BeanSerializerFactory(
86                         test.wsdl.arrays2.data.DataType.class,
87                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/data/1.0", "dataType")),
88                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(
89                         test.wsdl.arrays2.data.DataType.class,
90                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/data/1.0", "dataType")));
91         tm.register(InnerDataType.class,
92                 new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "innerDataType"),
93                 new org.apache.axis.encoding.ser.BeanSerializerFactory(
94                         InnerDataType.class,
95                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "innerDataType")),
96                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(
97                         InnerDataType.class,
98                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "innerDataType")));
99         tm.register(String JavaDoc.class,
100                 new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "trDescrType"),
101                 new org.apache.axis.encoding.ser.SimpleSerializerFactory(
102                         String JavaDoc.class,
103                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "trDescrType")),
104                 new org.apache.axis.encoding.ser.SimpleDeserializerFactory(
105                         String JavaDoc.class,
106                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "trDescrType")));
107
108         tm.register(DataRequestType.class,
109                 new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "dataRequestType"),
110                 new org.apache.axis.encoding.ser.BeanSerializerFactory(
111                         DataRequestType.class,
112                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "dataRequestType")),
113                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(
114                         DataRequestType.class,
115                         new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "dataRequestType")));
116
117         tm.register(InnerDataType[].class,
118                 new javax.xml.namespace.QName JavaDoc("http://www.xyz.net/schemas/arraytest/innerdata/1.0", "innerDataArrType"),
119                 new org.apache.axis.encoding.ser.ArraySerializerFactory(),
120                 new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
121
122         Message message = new Message(xml);
123         message.setMessageContext(new MessageContext(server));
124
125         SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPEnvelope();
126         RPCElement body = (RPCElement) envelope.getFirstBody();
127         Vector JavaDoc arglist = body.getParams();
128         RPCParam param = (RPCParam) arglist.get(0);
129         DataType result = (DataType) param.getObjectValue();
130         System.out.println(result);
131         assertTrue(result != null);
132         InnerDataType inner[] = result.getInnerData();
133         assertTrue(inner != null);
134         assertEquals(inner.length, 10);
135         assertEquals(inner[9].getTrDescr().trim(),"desc#9 HELLO!");
136     }
137 }
138
Popular Tags