-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWSDL.java
More file actions
1589 lines (1222 loc) · 56.2 KB
/
WSDL.java
File metadata and controls
1589 lines (1222 loc) · 56.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package javaxt.webservices;
import org.w3c.dom.*;
import javaxt.xml.DOM;
/******************************************************************************
/** WSDL Parser
/*****************************************************************************/
/** Used to parse a WSDL return information about the web services documented
* in the WSDL including service name and description, web methods, and input
* parameters.
*
<pre>
javaxt.webservices.WSDL wsdl = new javaxt.webservices.WSDL(url);
for (javaxt.webservices.Service service : wsdl.getServices()){
System.out.println(service.getName());
for (javaxt.webservices.Method method : service.getMethods()){
System.out.println(" - " + method.getName());
javaxt.webservices.Parameters parameters = method.getParameters();
if (parameters!=null){
for (javaxt.webservices.Parameter parameter : parameters.getArray()){
System.out.println(" * " + parameter.getName());
}
}
}
}
</pre>
*
*****************************************************************************/
public class WSDL {
private Document wsdl;
private Document ssd; //Simple Service Definition
private String vbCrLf = "\r\n";
private String ElementNameSpace = "";
private java.util.HashMap<String, String> NameSpaces;
private NodeList Schema;
private String HttpProxyServer;
private class Port{
public String Name;
public String Binding;
public String Address;
}
private class Binding{
public String Operation;
public String SoapAction;
public String Style;
public String Name;
public String Type;
}
private class Message{ //PortType
public String Input;
public String Output;
public String Documentation = null;
}
private class Element{
private int id;
public String Name;
public String Type;
public boolean IsNillable = false;
public boolean IsComplex = false;
public String minOccurs = "0";
public String maxOccurs = "1";
public boolean IsAttribute = false;
public String tagName = "parameter";
private java.util.ArrayList<Object> children = new java.util.ArrayList<>();
public int hashCode(){
return id;
}
public boolean equals(Object obj){
if (obj instanceof Element){
return id==((Element) obj).id;
}
else if (obj instanceof Node){
return id==new Element((Node) obj).id;
}
return false;
}
public Element(String Name, String Type){
id = (Name + "\t" + Type).hashCode();
this.Name = Name;
this.Type = stripNameSpace(Type);
IsComplex = isElementComplex(Type);
}
public Element(Node node){
String nodeName = stripNameSpace(node.getNodeName());
NamedNodeMap attr = node.getAttributes();
Name = DOM.getAttributeValue(attr, "name");
Type = DOM.getAttributeValue(attr, "type");
id = (Name + "\t" + Type).hashCode();
IsNillable = isElementNillable(DOM.getAttributeValue(attr, "nillable"));
IsComplex = isElementComplex(Type);
minOccurs = DOM.getAttributeValue(attr, "minOccurs");
maxOccurs = DOM.getAttributeValue(attr, "maxOccurs");
if (minOccurs.length()==0) minOccurs = "0";
if (maxOccurs.length()==0) maxOccurs = "1";
Type = stripNameSpace(Type);
String elementRef = DOM.getAttributeValue(attr, "ref");
if (elementRef.length()>0){
Name = elementRef;
}
if (nodeName.equalsIgnoreCase("attribute")){
IsAttribute = true;
IsNillable = DOM.getAttributeValue(attr, "use").equalsIgnoreCase("optional");
}
}
public void addElement(Element element){
//Child elements should be unique.
boolean addElement = true;
java.util.Iterator it = children.iterator();
while (it.hasNext()){
Object child = it.next();
if (child instanceof Element){
Element e = (Element) child;
if (e.Name.equals(element.Name) && e.Type.equals(element.Type)){
addElement = false;
}
}
}
if (addElement) children.add(element);
}
public void addChoices(Choices choices){
children.add(choices);
}
public void addOptions(Options options){
children.add(options);
}
public String toString(){
StringBuffer xml = new StringBuffer();
xml.append(" <" + tagName + " " +
"name=\"" + Name + "\" " +
"type=\"" + Type + "\" " +
"minOccurs=\"" + minOccurs + "\" " +
"maxOccurs=\"" + maxOccurs + "\" " +
"isattribute=\"" + IsAttribute + "\" " +
"iscomplex=\"" + IsComplex + "\" " +
"isnillable=\"" + IsNillable + "\">" + vbCrLf);
java.util.Iterator it = children.iterator();
while (it.hasNext()){
xml.append(it.next().toString());
}
xml.append(" </" + tagName + ">" + vbCrLf);
return xml.toString();
}
}
private class Options{
private java.util.ArrayList<String> options = new java.util.ArrayList<>();
public Options(){}
public void addOption(String option){
options.add(option);
}
public String toString(){
StringBuffer xml = new StringBuffer();
if (!options.isEmpty()){
xml.append(" <options>");
xml.append(vbCrLf);
java.util.Iterator<String> it = options.iterator();
while (it.hasNext()){
String option = it.next();
xml.append(" <option value=\"" + option + "\">" + option + "</option>" + vbCrLf);
}
xml.append(" </options>");
xml.append(vbCrLf);
}
return xml.toString();
}
}
private class Choices{
private java.util.ArrayList<Element> choices = new java.util.ArrayList<>();
public Choices(){}
public void addChoice(Element choice){
choices.add(choice);
}
public String toString(){
StringBuffer xml = new StringBuffer();
if (!choices.isEmpty()){
xml.append(" <options>");
xml.append(vbCrLf);
java.util.Iterator<Element> it = choices.iterator();
while (it.hasNext()){
xml.append(" ");
xml.append("<option>");
xml.append(it.next().toString());
xml.append("</option>");
xml.append(vbCrLf);
}
xml.append(" </options>");
xml.append(vbCrLf);
}
return xml.toString();
}
}
//**************************************************************************
//** Constructor
//**************************************************************************
/** Instantiate wsdl parser using a url to a wsdl (java.net.url)
*/
public WSDL(java.net.URL url){
this(downloadXML(url, null), null, true, null);
}
public WSDL(String url){
this(downloadXML(url, null), null, true, null);
}
public WSDL(java.net.URL url, String HttpProxyServer){
this(downloadXML(url, HttpProxyServer), null, true, HttpProxyServer);
}
public WSDL(Document wsdl) {
this(wsdl, null, true, null);
}
public WSDL(Document wsdl, String HttpProxyServer) {
this(wsdl, null, true, HttpProxyServer);
}
public WSDL(Document wsdl, Document[] xsd) {
this(wsdl, xsd, false, null);
}
private WSDL(Document wsdl, Document[] xsd, boolean followImports, String HttpProxyServer) {
this.wsdl = wsdl;
NameSpaces = DOM.getNameSpaces(wsdl);
ElementNameSpace = getElementNameSpace();
if (xsd==null){
xsd = new Document[1];
xsd[0] = wsdl;
}
else{
Document[] arr = new Document[xsd.length+1];
arr[0] = wsdl;
for (int i=1; i<arr.length; i++){
arr[i] = xsd[i-1];
}
xsd = arr;
}
this.HttpProxyServer = HttpProxyServer;
addSchema(xsd, followImports, false);
parseWSDL();
}
//**************************************************************************
//** getSSD
//**************************************************************************
/** Returns a Simple Service Description (SSD) - an xml document which
* outlines all the web methods and input parameters defined in
* the WSDL. This document is significantly easier to parse and understand
* than the original WSDL.
*/
public Document getSSD(){
return ssd;
}
//**************************************************************************
//** toString
//**************************************************************************
/** Returns a string representing an XML document containing a Simple
* Service Description (SSD). Please see the getSSD() for more information.
*/
public String toString(){
return DOM.getText(ssd);
}
// <editor-fold defaultstate="collapsed" desc="Core WSDL Parser. Click on the + sign on the left to edit the code.">
private NamedNodeMap getDefinitionAttributes(){
NodeList Definitions = wsdl.getChildNodes();
for (int i=0; i<Definitions.getLength(); i++ ) {
if (Definitions.item(i).getNodeType() == 1){
if (contains(Definitions.item(i).getNodeName(), "definitions")) {
return Definitions.item(i).getAttributes();
}
}
}
return null;
}
//**************************************************************************
//** getTargetNameSpace
//**************************************************************************
private String getTargetNameSpace(){
NamedNodeMap attr = getDefinitionAttributes();
return DOM.getAttributeValue(attr, "targetNamespace");
}
//**************************************************************************
//** getElementNameSpace
//**************************************************************************
private String getElementNameSpace(){
String elementNameSpace = "http://www.w3.org/2001/XMLSchema";
NamedNodeMap attr = getDefinitionAttributes();
if (attr!=null){
Node node;
String nodeName;
String nodeValue;
for (int i=0; i < attr.getLength(); i++ ) {
node = attr.item(i);
nodeName = node.getNodeName().toLowerCase();
nodeValue = node.getNodeValue();
if (nodeValue.toLowerCase().equals(elementNameSpace.toLowerCase())) {
return stripNameSpace(nodeName);
}
}
}
return "";
}
//**************************************************************************
//** isElementComplex
//**************************************************************************
private boolean isElementComplex(String elementType){
String elementNameSpace = "";
if (elementType.contains(":")){
elementNameSpace = elementType.substring(0, elementType.indexOf(":"));
}
return !elementNameSpace.equalsIgnoreCase(ElementNameSpace);
}
//**************************************************************************
//** isElementNillable
//**************************************************************************
private boolean isElementNillable(String isnillable){
if (isnillable.toLowerCase().equals("true")){
return true;
}
else{
return false;
}
}
//**************************************************************************
//** parseWSDL
//**************************************************************************
/** Used to parse the WSDL and generate the SSD.
* Note that this parser works for most xml web services in production. That
* said, there are a couple limitations. Here's a short list of outstanding
* tasks:
* <ul>
* <ul>
* <li>Implement support for Abstract Types</li>
* <li>Finish the Parameters.setValue() method to support arrays</li>
* <li>Verify that the namespace is identified and used properly (currently
* assume one targetNamespace per wsdl)</li>
* <li>Test whether parameters are identified properly</li>
* <li>Need to test against wsdls w/multiple services</li>
* </ul>
* </ul>
*/
private void parseWSDL(){
String SSD = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + vbCrLf +
"<ssd>" + vbCrLf;
String ServiceName = "";
String ServiceDescription = "";
NodeList Definitions, ChildNodes;
NamedNodeMap attr;
Port Port = null;
Binding Binding = null;
java.util.ArrayList<Binding> arrBindings = null;
Element Element = null;
java.util.ArrayList<Element> arrElements = null;
//Loop Through Definitions and Get Services
//definitions->service (name attribute)
Definitions = getDefinitions();
for (int i=0; i<Definitions.getLength(); i++ ) {
if (contains(Definitions.item(i).getNodeName(), "service")) {
//Get Service Name
attr = Definitions.item(i).getAttributes();
ServiceName = DOM.getAttributeValue(attr, "name");
//Get Service Description
ChildNodes = Definitions.item(i).getChildNodes();
for (int j=0; j<ChildNodes.getLength(); j++ ) {
if (contains(ChildNodes.item(j).getNodeName(), "documentation")) {
ServiceDescription = ChildNodes.item(j).getTextContent();
}
}
//Get Service Port
Port = getPort(ChildNodes);
if (Port!=null){
SSD += " <service name=\"" + ServiceName + "\" url=\"" + Port.Address + "\" namespace=\"" + getTargetNameSpace() + "\">" + vbCrLf;
if (ServiceDescription!=null){
SSD += " <description>" + ServiceDescription + "</description>" + vbCrLf;}
SSD += " <methods>" + vbCrLf;
//Get Bindings
arrBindings = getBindings(Port.Binding);
for (int j=0; j<arrBindings.size(); j++ ) {
Binding = arrBindings.get(j);
//Get Soap Action
String SoapAction = Binding.SoapAction;
if (SoapAction!=null) SoapAction = " soapAction=\"" + SoapAction + "\"";
//Get Messages (need to valid logic here!)
//Message Message = getMessages(Port.Name,Binding.Operation);
//if (Message==null) Message = getMessages(Port.Binding,Binding.Operation);
Message Message = getMessages(Binding.Type,Binding.Operation);
//Get Response Element
String ResultsNode = "";
try{
arrElements = getElements(Message.Output);
for (int k=0; k<arrBindings.size(); k++ ) {
Element = arrElements.get(k);
ResultsNode = Element.Name;
}
}
catch(Exception e){
//System.out.println(e.toString());
}
SSD +=" <method name=\"" + Binding.Operation + "\"" + SoapAction + " resultsNode=\"" + ResultsNode + "\">" + vbCrLf;
if (Message.Documentation!=null){
SSD += " <description>" + Message.Documentation + "</description>" + vbCrLf;
}
SSD += " <parameters>" + vbCrLf;
arrElements = getElements(Message.Input);
try{
for (int k=0; k<arrElements.size(); k++ ) {
Element = arrElements.get(k);
SSD += Element.toString();
}
}
catch(Exception e){
//System.out.println(e.toString());
}
SSD += " </parameters>" + vbCrLf;
SSD += " <outputs>" + vbCrLf;
arrElements = getElements(Message.Output);
try{
for (int k=0; k<arrElements.size(); k++ ) {
Element = arrElements.get(k);
Element.tagName = "output";
SSD += Element.toString();
}
}
catch(Exception e){
//System.out.println(e.toString());
}
SSD += " </outputs>" + vbCrLf;
SSD +=" </method>" + vbCrLf;
}
//Update SSD
SSD += " </methods>" + vbCrLf;
SSD += " </service>" + vbCrLf;
}
}
}
SSD += vbCrLf + "</ssd>";
//System.out.println(SSD);
ssd = DOM.createDocument(SSD);
knownTypes.clear();
}
//**************************************************************************
//** getPort
//**************************************************************************
private Port getPort(NodeList Ports){
Port Port = null;
String PortName, PortBinding, PortAddress;
boolean foundSoapPort = false;
for (int j=0; j<Ports.getLength(); j++ ) {
if (contains(Ports.item(j).getNodeName(), "port")) {
//Get Service Binding
NamedNodeMap attr = Ports.item(j).getAttributes();
PortName = DOM.getAttributeValue(attr, "name");
PortBinding = stripNameSpace(DOM.getAttributeValue(attr, "binding"));
//Get Service Endpoint (url)
PortAddress = "";
NodeList Addresses = Ports.item(j).getChildNodes();
for (int k=0; k<Addresses.getLength(); k++ ) {
String Address = Addresses.item(k).getNodeName();
//System.out.println(Address);
if (contains(Address, "address") && //soap:address
!contains(Address,"http:") &&
!contains(Address,"https:") && //untested prefix
!contains(Address,"soap12:") //untested prefix (suggested by user)
){
attr = Addresses.item(k).getAttributes();
PortAddress = DOM.getAttributeValue(attr, "location");
foundSoapPort = true;
}
}
if (foundSoapPort){
Port = new Port();
Port.Name = PortName;
Port.Binding = PortBinding;
Port.Address = PortAddress;
return Port;
}
}
}
return Port;
}
//**************************************************************************
//** getBindings
//**************************************************************************
private java.util.ArrayList<Binding> getBindings(String PortBinding){
NodeList Definitions, ChildNodes;
NamedNodeMap attr;
String BindingName, BindingType, BindingStyle, BindingTransport;
Binding Binding = null;
java.util.ArrayList<Binding> arrBindings = null;
int BindingCount = -1;
//Loop through definitions
Definitions = getDefinitions();
//Definitions = Definitions.item(0).getChildNodes();
for (int i=0; i<Definitions.getLength(); i++ ) {
if (contains(Definitions.item(i).getNodeName(), "binding")) {
//Get Binding Name
attr = Definitions.item(i).getAttributes();
BindingName = DOM.getAttributeValue(attr, "name");
BindingType = DOM.getAttributeValue(attr, "type");
if (BindingName.equals(PortBinding)){
arrBindings = new java.util.ArrayList<>();
//Get Binding Transport/Style
BindingStyle = BindingTransport = "";
ChildNodes = Definitions.item(i).getChildNodes();
for (int j=0; j<ChildNodes.getLength(); j++ ) {
if (contains(ChildNodes.item(j).getNodeName(), "binding")) {
attr = ChildNodes.item(j).getAttributes();
BindingStyle = DOM.getAttributeValue(attr, "style");
BindingTransport = DOM.getAttributeValue(attr, "transport");
}
}
//Get Operation Names/Soap Action
for (int j=0; j<ChildNodes.getLength(); j++ ) {
if (contains(ChildNodes.item(j).getNodeName(), "operation")) {
Binding = new Binding();
BindingCount +=1;
attr = ChildNodes.item(j).getAttributes();
Binding.Operation = DOM.getAttributeValue(attr, "name");
NodeList Operations = ChildNodes.item(j).getChildNodes();
for (int k=0; k<Operations.getLength(); k++ ) {
if (contains(Operations.item(k).getNodeName(), "operation")) {
attr = Operations.item(k).getAttributes();
Binding.SoapAction = DOM.getAttributeValue(attr, "soapaction");
Binding.Style = BindingStyle; //DOM.getAttributeValue(attr, "style");
Binding.Name = BindingName;
Binding.Type = stripNameSpace(BindingType);
}
}
arrBindings.add(Binding);
}
}
return arrBindings;
}
}
}
return null;
}
//**************************************************************************
//** getMessages
//**************************************************************************
private Message getMessages(String PortTypeName, String OperationName){
//System.out.println();
//System.out.println(PortTypeName);
NodeList Definitions, PortTypes, Messages;
NamedNodeMap attr;
String portTypeName, operationName, messageName;
Message Message = null;
//Loop through definitions
Definitions = getDefinitions();
//Definitions = Definitions.item(0).getChildNodes();
for (int i=0; i<Definitions.getLength(); i++ ) {
if (contains(Definitions.item(i).getNodeName(), "porttype")) {
attr = Definitions.item(i).getAttributes();
portTypeName = DOM.getAttributeValue(attr, "name");
//System.out.println(" vs " + DOM.getAttributeValue(attr, "name"));
if (portTypeName.equals(PortTypeName)){
String Documentation = "";
//Loop through PortTypes
PortTypes = Definitions.item(i).getChildNodes();
for (int j=0; j<PortTypes.getLength(); j++ ) {
String NodeName = PortTypes.item(j).getNodeName();
if (NodeName.endsWith("documentation")) {
Documentation = DOM.getNodeValue(PortTypes.item(j));
}
if (NodeName.endsWith("operation")) {
attr = PortTypes.item(j).getAttributes();
operationName = DOM.getAttributeValue(attr, "name");
if (operationName.equals(OperationName)){
//Instantiate Message Object
Message = new Message();
Message.Documentation = Documentation;
//Loop through the Messages
Messages = PortTypes.item(j).getChildNodes();
for (int k=0; k<Messages.getLength(); k++ ) {
if (Messages.item(k).getNodeType()==1){
attr = Messages.item(k).getAttributes();
messageName = stripNameSpace(DOM.getAttributeValue(attr, "message"));
if (contains(Messages.item(k).getNodeName(), "input")) {
Message.Input = messageName;
}
if (contains(Messages.item(k).getNodeName(), "output")) {
Message.Output = messageName;
}
if (contains(Messages.item(k).getNodeName(), "documentation")) {
Documentation = DOM.getNodeValue(Messages.item(k));
if (Documentation.length()>0){
Message.Documentation = Documentation;
}
}
}
}
return Message;
}
}
}
}
}
}
return Message;
}
//**************************************************************************
//** getElements
//**************************************************************************
/** Returns a list of elements (parameters) associated with a given message.
* definitions->message->part (element name attribute)
*/
private java.util.ArrayList<Element> getElements(String MessageName){
NodeList Definitions, Messages;
NamedNodeMap attr;
String messageName, name, type, min, max;
java.util.ArrayList<Element> elements = new java.util.ArrayList<>();
//Loop through Definitions and Find Messages
Definitions = getDefinitions();
for (int i=0; i<Definitions.getLength(); i++ ) {
if (contains(Definitions.item(i).getNodeName(), "message")) {
attr = Definitions.item(i).getAttributes();
messageName = DOM.getAttributeValue(attr, "name");
if (messageName.equals(MessageName)){
//Loop through Messages and Find Message Parts
Messages = Definitions.item(i).getChildNodes();
for (int j=0; j<Messages.getLength(); j++ ) {
if (contains(Messages.item(j).getNodeName(), "part")) {
attr = Messages.item(j).getAttributes();
type = DOM.getAttributeValue(attr, "type");
String element = stripNameSpace(DOM.getAttributeValue(attr, "element"));
elements = getElement(element);
}
}
return elements;
}
}
}
return null;
}
//**************************************************************************
//** getDefinitions
//**************************************************************************
private NodeList getDefinitions(){
NodeList Definitions = wsdl.getChildNodes();
if (Definitions!=null){
for (int i=0; i<Definitions.getLength(); i++){
Node node = Definitions.item(i);
if (node.getNodeType() == 1){
if (node.getNodeName().endsWith("definitions")) {
return Definitions.item(i).getChildNodes();
}
}
}
}
return null;
}
//**************************************************************************
//** getTypes
//**************************************************************************
private NodeList getTypes(){
NodeList Definitions = getDefinitions();
if (Definitions!=null){
for (int i=0; i<Definitions.getLength(); i++ ) {
Node node = Definitions.item(i);
if (node.getNodeType()==1){
if (node.getNodeName().endsWith("types")){
return node.getChildNodes();
}
}
}
}
return null;
}
//**************************************************************************
//** getShema
//**************************************************************************
private NodeList getSchema(){
return Schema;
}
//**************************************************************************
//** addSchema
//**************************************************************************
/** Used to add an external XSD.
* @param followImports Flag used to indicate whether to download/parse XSD
* files referenced by the schema/import nodes.
*/
public void addSchema(Document xsd, boolean followImports){
addSchema(new Document[]{xsd}, followImports);
}
//**************************************************************************
//** addSchemas
//**************************************************************************
/** Used to add multiple external XSDs.
* @param followImports Flag used to indicate whether to download/parse XSD
* files referenced by the schema/import nodes.
*/
public void addSchema(Document[] xsd, boolean followImports){
this.addSchema(xsd, followImports, true);
}
private void addSchema(Document[] XSDs, boolean followImports, boolean parseWSDL){
if (XSDs==null) return;
if (XSDs.length==0) return;
//Create xml document to store all the schema
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\"?>");
xml.append("<schemas");
java.util.Iterator<String> it = NameSpaces.keySet().iterator();
while (it.hasNext()){
String ns = it.next();
String url = (String) NameSpaces.get(ns);
xml.append(" xmlns:");
xml.append(ns);
xml.append("=\"");
xml.append(url);
xml.append("\"");
}
xml.append(">");
//Add existing schema
if (this.Schema!=null) xml.append(DOM.getText(this.Schema));
//Loop through the new schemas
for (Document xsd : XSDs){
if (xsd!=null){
Node outerNode = DOM.getOuterNode(xsd);
String outerNodeName = stripNameSpace(outerNode.getNodeName());
java.util.ArrayList<Node> schemaNodes = new java.util.ArrayList<Node>();
if (outerNodeName.equalsIgnoreCase("definitions")){
NodeList childNodes = outerNode.getChildNodes();
for (int i=0; i<childNodes.getLength(); i++){
Node node = childNodes.item(i);
if (stripNameSpace(node.getNodeName()).equalsIgnoreCase("types")){
NodeList types = node.getChildNodes();
for (int j=0; j<types.getLength(); j++){
Node typeNode = types.item(j);
if (stripNameSpace(typeNode.getNodeName()).equalsIgnoreCase("schema")){
NodeList nodes = typeNode.getChildNodes();
for (int k=0; k<nodes.getLength(); k++ ) {
schemaNodes.add(nodes.item(k));
}
}
}
}
}
}
else if (outerNodeName.equalsIgnoreCase("schema")){
//schemaNodes = outerNode.getChildNodes();
NodeList nodes = outerNode.getChildNodes();
for (int k=0; k<nodes.getLength(); k++ ) {
schemaNodes.add(nodes.item(k));
}
}
else{
return;
}
NameSpaces.putAll(DOM.getNameSpaces(xsd));
StringBuffer auxSchemas = new StringBuffer();
//Loop through Schemas and Get Imports
for (int i=0; i<schemaNodes.size(); i++ ) {
Node schemaNode = schemaNodes.get(i);
Node importNode = getNode(schemaNode, "import");
if (importNode!=null){
if (followImports){
NamedNodeMap attr = importNode.getAttributes();
String schemaLocation = DOM.getAttributeValue(attr, "schemaLocation");
if (schemaLocation.length()>0){
importSchemas(schemaLocation, auxSchemas, HttpProxyServer);
}
}
Node iSchema = importNode.getParentNode();
iSchema.removeChild(importNode);
}
}
//Insert new schemas
for (int i=0; i<schemaNodes.size(); i++ ) {
Node schemaNode = schemaNodes.get(i);
xml.append(DOM.getText(schemaNode));
}
//xml.append(DOM.getText(schemaNodes));
xml.append(auxSchemas);
}
}
//Finish writing the xml document, serialize it to a DOM object, and reparse the WSDL
xml.append("</schemas>");
//boolean parseWSDL = this.Schema!=null;
this.Schema = DOM.getOuterNode(DOM.createDocument(xml.toString())).getChildNodes();
if (parseWSDL) parseWSDL();
}
//**************************************************************************
//** importSchemas
//**************************************************************************
/** Used to download and parse an XSD document. Used in conjunction with the
* addSchema method. Note that this is a recursive function.
*