0

I have a small restify api that talks to sql server and returns xml back. xml response can be quite large and is consumed by Adobe InDesign. Api call works in the browser but when called from InDesign, I get incomplete xml response.

InDesign uses a proprietary scripting language called ExtendScript which uses sockets to communicate. Not sure in Streams is an option.

Chirdeep Tomar
  • 4,281
  • 8
  • 37
  • 66
  • How are you calling your web service? I am using a modified version of the extendables library and I'm pretty sure I had to make some changes to support larger data returns. I can't remember the specifics of the changes I made but I can dig if you're using the same library. – Anna Forrest Jul 31 '14 at 21:40
  • We are using standard ExtendScript without any additional libraries and calling API using a socket. I will try with extendables thanks for pointing it out, can you please let me know what changes you had to make. – Chirdeep Tomar Aug 01 '14 at 09:45
  • The issue I was thinking of is that the extendables library wasn't handling the continue header correctly - I modified mine to simply trash that header and wait for the final response. I also think there was some problem with how the library was parsing the url - maybe to do with the port number? – Anna Forrest Aug 01 '14 at 13:01

2 Answers2

0

I have a very similar problem and after a lot of playing around I added a few seconds pause between connection write and read and this resolved the problem for now. I am not a fan of this fix. Anyone has a better idea? I suspect that as the files get bigger you will have to start increasing the timeout.

var conn = new Socket;

if (conn.open (host + ":7000","UTF-8"))

{  conn.write("GET /report/" + ReportID  +" HTTP/1.0\n" +
   "Content-Type: application/xml; charset=UTF-8\n\n");

   $.sleep(2000);

   reply = conn.read (999999);

   conn.close();
}
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
0

You really need to use callbacks and the ->net<- library.

net library doc

var net = require('net');
var client = net.connect({port: 8124},
    function() { //'connect' listener
  console.log('connected to server!');
  client.write('world!\r\n');
});
client.on('data', function(data) {
  console.log(data.toString());
  client.end();
});
client.on('end', function() {
  console.log('disconnected from server');
});

I copied that example from the oficial docs, as you can see you really need to use callbacks on the events, in this case de "data" event, when you get the complete response THEN you proceed to send your response.

Your XML is incomplete because you send the response before the Socket finish to recieve the data.

Remember javascript is non-blocking, and this things can happen, thats why you need to learn how to use events and callbacks.

PLEASE use the net library.

Hope it helps.

PD: im sorry about my poor english but im trying to be helpful.

Sebastián Espinosa
  • 2,123
  • 13
  • 23