Skip to content
This repository

Not sure if anyone is listening, fixed a bug. #112

Merged
merged 18 commits into from about 1 year ago

6 participants

alanbly Tim de Koning milewise Adrian Filipe Constantinov Menezes Kyle Stetz
alanbly

Noticed that multiple SOAP listeners didn't work, fixed it.

alanbly

When multiple Servers were created serially, this method always returned the original listener, not the previous call's listener as would be expected.

Tim de Koning

Too bad this pull request isn't merged... It fixes all my issues!

milewise milewise merged commit 0f0382a into from April 10, 2013
milewise milewise closed this April 10, 2013
Tim de Koning

@milewise and @alanbly thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
0  .gitignore 100644 → 100755
File mode changed
0  Readme.md 100644 → 100755
Source Rendered
File mode changed
0  client.js b/lib/client.js 100644 → 100755
File mode changed
0  http.js b/lib/http.js 100644 → 100755
File mode changed
0  index.js 100644 → 100755
File mode changed
76  lib/server.js 100644 → 100755
@@ -13,14 +13,16 @@ var url = require('url'),
13 13
 try { compress = require("compress"); } catch(e) {}
14 14
 
15 15
 var Server = function(server, path, services, wsdl) {
16  
-    var self = this,
17  
-        listeners = server.listeners('request');
18  
-                
  16
+    var self = this;
  17
+
  18
+    this.path = path;     
19 19
     this.services = services;
20 20
     this.wsdl = wsdl;
21 21
 
22 22
     if (path[path.length-1] != '/') path += '/';
23 23
     wsdl.onReady(function(err) {
  24
+        var listeners = server.listeners('request').slice();
  25
+
24 26
         server.removeAllListeners('request');
25 27
         server.addListener('request', function(req, res) {
26 28
             if (typeof self.authorizeConnection === 'function') {
@@ -45,9 +47,15 @@ var Server = function(server, path, services, wsdl) {
45 47
 
46 48
 Server.prototype._requestListener = function(req, res) {
47 49
     var self = this;
  50
+    var reqParse = url.parse(req.url);
  51
+    var reqPath = reqParse.pathname;
  52
+    var reqQuery = reqParse.search;
  53
+
  54
+    self.log("info", "Handling "+req.method+" on "+req.url);
  55
+
48 56
     if (req.method === 'GET') {
49  
-        var search = url.parse(req.url).search;
50  
-        if (search && search.toLowerCase() === '?wsdl') {
  57
+        if (reqQuery && reqQuery.toLowerCase() === '?wsdl') {
  58
+            self.log("info", "Wants the WSDL");
51 59
             res.setHeader("Content-Type", "application/xml");
52 60
             res.write(self.wsdl.toXML());
53 61
         }
@@ -112,46 +120,60 @@ Server.prototype._process = function(input, URL, callback) {
112 120
         throw new Error('Invalid username or password');
113 121
       }
114 122
     }
  123
+    
  124
+    self.log("info", "Attempting to bind to "+pathname);
115 125
 
116 126
     // use port.location and current url to find the right binding
117 127
     binding = (function(self){
118 128
         var services = self.wsdl.definitions.services;
  129
+        var firstPort = undefined;
119 130
         for(serviceName in services ) {
120 131
             var service = services[serviceName];
121 132
             var ports = service.ports;
122 133
             for(portName in ports) {
123 134
                 var port = ports[portName];
124 135
                 var portPathname = url.parse(port.location).pathname.replace(/\/$/,'');
  136
+                self.log("info", "Trying "+portName+" from path "+portPathname);
125 137
                 if(portPathname===pathname) 
126 138
                     return port.binding;
  139
+                    
  140
+                // The port path is almost always wrong for genrated WSDLs
  141
+                if(firstPort == undefined) {
  142
+                  firstPort = port;
  143
+                }
127 144
             }
128 145
         }
  146
+        return firstPort == undefined ? undefined : firstPort.binding;
129 147
     })(this);
130 148
 
  149
+    if (!binding) {
  150
+      throw new Error('Failed to bind to WSDL');
  151
+    }
  152
+
131 153
     methods = binding.methods;
132 154
 
133  
-        if(binding.style === 'rpc') {
134  
-            methodName = Object.keys(body)[0];
135  
-            self._executeMethod({
136  
-                serviceName: serviceName,
137  
-                portName: portName,
138  
-                methodName: methodName,
139  
-                outputName: methodName + 'Response',
140  
-                args: body[methodName],
141  
-                style: 'rpc'
142  
-            }, callback);
143  
-        } else {
144  
-            var messageElemName = Object.keys(body)[0];
145  
-            var pair = binding.topElements[messageElemName];
146  
-            self._executeMethod({
147  
-                serviceName: serviceName,
148  
-                portName: portName,
149  
-                methodName: pair.methodName,
150  
-                outputName: pair.outputName,
151  
-                args: body[messageElemName],
152  
-                style: 'document'
153  
-            }, callback);
154  
-        }
  155
+    if(binding.style === 'rpc') {
  156
+        methodName = Object.keys(body)[0];
  157
+        self._executeMethod({
  158
+	    serviceName: serviceName,
  159
+	    portName: portName,
  160
+	    methodName: methodName,
  161
+	    outputName: methodName + 'Response',
  162
+	    args: body[methodName],
  163
+	    style: 'rpc'
  164
+        }, callback);
  165
+    } else {
  166
+        var messageElemName = Object.keys(body)[0];
  167
+        var pair = binding.topElements[messageElemName];
  168
+        self._executeMethod({
  169
+	    serviceName: serviceName,
  170
+	    portName: portName,
  171
+	    methodName: pair.methodName,
  172
+	    outputName: pair.outputName,
  173
+	    args: body[messageElemName],
  174
+	    style: 'document'
  175
+        }, callback);
  176
+    }
155 177
 }
156 178
 
157 179
 Server.prototype._executeMethod = function(options, callback) {
7  lib/wsdl.js 100644 → 100755
@@ -483,7 +483,8 @@ ElementElement.prototype.description = function(definitions) {
483 483
     var element = {},
484 484
         name = this.$name,
485 485
         schema;
486  
-    if (this.$minOccurs !== this.$maxOccurs) {
  486
+    var isMany = !this.$maxOccurs ? false : (isNaN(this.$maxOccurs) ? (this.$maxOccurs == 'unbounded') : (this.$maxOccurs > 1));
  487
+    if (this.$minOccurs !== this.$maxOccurs && isMany) {
487 488
         name += '[]';
488 489
     }
489 490
     
@@ -856,14 +857,14 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) {
856 857
                 parts.push(['</',ns,name,'>'].join(''));
857 858
                 parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
858 859
             }
859  
-            parts.push(self.objectToXML(item, name));
  860
+            parts.push(self.objectToXML(item, name, namespace, xmlns));
860 861
         }
861 862
     }
862 863
     else if (typeof obj === 'object') {
863 864
         for (var name in obj) {
864 865
             var child = obj[name];
865 866
             parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
866  
-            parts.push(self.objectToXML(child, name));
  867
+            parts.push(self.objectToXML(child, name, namespace, xmlns));
867 868
             parts.push(['</',ns,name,'>'].join(''));
868 869
         }
869 870
     }
0  package.json 100644 → 100755
File mode changed
0  soap.js b/lib/soap.js 100644 → 100755
File mode changed
0  test/ip2tele/cfg.js 100644 → 100755
File mode changed
0  test/ip2tele/fake_server.js 100644 → 100755
File mode changed
0  test/ip2tele/ip2tele.js 100644 → 100755
File mode changed
0  test/ip2tele/ip2tele.wsdl 100644 → 100755
File mode changed
0  test/ip2tele/logs/dummy 100644 → 100755
File mode changed
0  test/ip2tele/readme.md 100644 → 100755
Source Rendered
File mode changed
0  test/server-test.js 100644 → 100755
File mode changed
0  test/vac/logs/vac_trace.xml 100644 → 100755
File mode changed
0  test/vac/vac.js 100644 → 100755
File mode changed
0  test/wsdl/strict/CyberSourceTransaction_1.26.wsdl 100644 → 100755
File mode changed
0  test/wsdl/strict/CyberSourceTransaction_1.26.xsd 100644 → 100755
File mode changed
0  test/wsdl/strict/CyberSourceTransaction_1.26_2.wsdl 100644 → 100755
File mode changed
0  test/wsdl/strict/CyberSourceTransaction_1.26_3.wsdl 100644 → 100755
File mode changed
0  test/wsdl/strict/DE.wsdl 100644 → 100755
File mode changed
0  test/wsdl/strict/ip2tele.wsdl 100644 → 100755
File mode changed
0  test/wsdl/strict/logincms.wsdl 100644 → 100755
File mode changed
0  test/wsdl/strict/stockquote.wsdl 100644 → 100755
File mode changed
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.