Skip to content

Commit ac831cd

Browse files
committed
Stubbed out support for parsing service responses in the WSDL parser
1 parent fc821a9 commit ac831cd

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

src/javaxt/webservices/Method.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Method {
2121
private String ResultsNode;
2222

2323
private NodeList Parameters = null;
24+
private NodeList Outputs = null;
2425

2526

2627
//**************************************************************************
@@ -48,6 +49,9 @@ protected Method(Node MethodNode){
4849
if (NodeName.toLowerCase().equals("parameters")){
4950
Parameters = ChildNodes.item(j).getChildNodes();
5051
}
52+
if (NodeName.toLowerCase().equals("outputs")){
53+
Outputs = ChildNodes.item(j).getChildNodes();
54+
}
5155
}
5256
}
5357

@@ -64,30 +68,44 @@ protected Method(Node MethodNode){
6468
//**************************************************************************
6569
//** getParameters
6670
//**************************************************************************
67-
/** Returns a list of parameters associated with this method. */
68-
71+
/** Returns a list of input parameters associated with this method.
72+
*/
6973
public Parameters getParameters(){
7074

7175
//Note that we don't store parameters as a class variable. Instead, we
7276
//extract parameters from the SSD. This is important. Otherwise, the
7377
//param values get cached
74-
Parameter[] parameters = getParameters(Parameters);
78+
Parameter[] parameters = getParameters(Parameters, "parameter");
7579
if (parameters==null) return null;
7680
else return new Parameters(parameters);
7781
}
7882

7983

8084
//**************************************************************************
81-
//** getParameters
85+
//** getOutputs
8286
//**************************************************************************
83-
/** Used to retrieve an array of parameters from an SSD NodeList */
87+
/** Returns a list of outputs returned by this method. There should be only
88+
* one result. Use the getResultsNodeName() method to find the correct
89+
* output.
90+
*/
91+
public Outputs getOutputs(){
92+
Parameter[] parameters = getParameters(Outputs, "output");
93+
if (parameters==null) return null;
94+
return new Outputs(parameters, ResultsNode);
95+
}
8496

85-
private Parameter[] getParameters(NodeList parameterNodes){
8697

87-
java.util.ArrayList<Parameter> parameters = new java.util.ArrayList<Parameter>();
98+
//**************************************************************************
99+
//** getParameters
100+
//**************************************************************************
101+
/** Used to retrieve an array of parameters from an SSD NodeList
102+
*/
103+
private Parameter[] getParameters(NodeList parameterNodes, String tagName){
104+
105+
java.util.ArrayList<Parameter> parameters = new java.util.ArrayList<>();
88106

89107
for (Node parameterNode : DOM.getNodes(parameterNodes)){
90-
if (parameterNode.getNodeName().equalsIgnoreCase("parameter")){
108+
if (parameterNode.getNodeName().equalsIgnoreCase(tagName)){
91109
try{
92110
parameters.add(new Parameter(parameterNode));
93111
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package javaxt.webservices;
2+
3+
4+
public class Outputs extends Parameters {
5+
6+
public Outputs(Parameter[] Parameters, String ResultsNode){
7+
super(Parameters);
8+
}
9+
10+
}

src/javaxt/webservices/Parameter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class Parameter {
3333
*/
3434
protected Parameter(Node ParameterNode) throws InstantiationException {
3535

36-
if (!ParameterNode.getNodeName().equalsIgnoreCase("parameter")){
36+
String nodeName = ParameterNode.getNodeName();
37+
if (!nodeName.equalsIgnoreCase("parameter") && !nodeName.equalsIgnoreCase("output")){
3738
throw new InstantiationException(DOM.getText(ParameterNode));
3839
}
3940

@@ -76,7 +77,7 @@ else if(maxOccurs.equals("")){
7677

7778

7879
//Get children
79-
java.util.ArrayList<Parameter> params = new java.util.ArrayList<Parameter>();
80+
java.util.ArrayList<Parameter> params = new java.util.ArrayList<>();
8081
for (Node node : DOM.getNodes(ParameterNode.getChildNodes())){
8182

8283
if (node.getNodeName().equalsIgnoreCase("parameter")){
@@ -96,7 +97,7 @@ else if(maxOccurs.equals("")){
9697

9798

9899
//Get list of possible values (i.e. options)
99-
java.util.ArrayList<Option> options = new java.util.ArrayList<Option>();
100+
java.util.ArrayList<Option> options = new java.util.ArrayList<>();
100101
for (Node node : DOM.getNodes(ParameterNode.getChildNodes())){
101102
if (node.getNodeName().equalsIgnoreCase("options")){
102103
for (Node optionNode : DOM.getNodes(node.getChildNodes())){

src/javaxt/webservices/WSDL.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private class Element{
6767
public String minOccurs = "0";
6868
public String maxOccurs = "1";
6969
public boolean IsAttribute = false;
70+
public String tagName = "parameter";
7071

7172
private java.util.ArrayList<Object> children = new java.util.ArrayList<>();
7273

@@ -150,7 +151,7 @@ public void addOptions(Options options){
150151

151152
public String toString(){
152153
StringBuffer xml = new StringBuffer();
153-
xml.append(" <parameter " +
154+
xml.append(" <" + tagName + " " +
154155
"name=\"" + Name + "\" " +
155156
"type=\"" + Type + "\" " +
156157
"minOccurs=\"" + minOccurs + "\" " +
@@ -164,7 +165,7 @@ public String toString(){
164165
xml.append(it.next().toString());
165166
}
166167

167-
xml.append(" </parameter>" + vbCrLf);
168+
xml.append(" </" + tagName + ">" + vbCrLf);
168169
return xml.toString();
169170
}
170171
}
@@ -501,6 +502,19 @@ private void parseWSDL(){
501502
}
502503
SSD += " </parameters>" + vbCrLf;
503504

505+
SSD += " <outputs>" + vbCrLf;
506+
arrElements = getElements(Message.Output);
507+
try{
508+
for (int k=0; k<arrElements.size(); k++ ) {
509+
Element = arrElements.get(k);
510+
Element.tagName = "output";
511+
SSD += Element.toString();
512+
}
513+
}
514+
catch(Exception e){
515+
//System.out.println(e.toString());
516+
}
517+
SSD += " </outputs>" + vbCrLf;
504518

505519
SSD +=" </method>" + vbCrLf;
506520
}
@@ -513,6 +527,7 @@ private void parseWSDL(){
513527
}
514528

515529
SSD += vbCrLf + "</ssd>";
530+
System.out.println(SSD);
516531
ssd = DOM.createDocument(SSD);
517532

518533
knownTypes.clear();
@@ -532,18 +547,23 @@ private Port getPort(NodeList Ports){
532547
for (int j=0; j<Ports.getLength(); j++ ) {
533548
if (contains(Ports.item(j).getNodeName(), "port")) {
534549

535-
//Get Service Binding
550+
//Get Service Binding
536551
NamedNodeMap attr = Ports.item(j).getAttributes();
537552
PortName = DOM.getAttributeValue(attr, "name");
538553
PortBinding = stripNameSpace(DOM.getAttributeValue(attr, "binding"));
539554

540555

541-
//Get Service Endpoint (url)
556+
//Get Service Endpoint (url)
542557
PortAddress = "";
543558
NodeList Addresses = Ports.item(j).getChildNodes();
544559
for (int k=0; k<Addresses.getLength(); k++ ) {
545560
String Address = Addresses.item(k).getNodeName();
546-
if (contains(Address, "address") && !contains(Address,"http:") ) { //soap:address
561+
System.out.println(Address);
562+
if (contains(Address, "address") && //soap:address
563+
!contains(Address,"http:") &&
564+
!contains(Address,"https:") && //untested prefix
565+
!contains(Address,"soap12:") //untested prefix (suggested by user)
566+
){
547567
attr = Addresses.item(k).getAttributes();
548568
PortAddress = DOM.getAttributeValue(attr, "location");
549569
foundSoapPort = true;

0 commit comments

Comments
 (0)