I am trying to call an applet method in the 'onreadystatechange' callback function of my XMLHttpRequest call. The applet method is supposed to retreive a binary data file from the server using HTTP GET and send it to a printer.

The problem is, if the data file is too big (1.5 Mb), the server sends back a response of status OK(200), but the ContentLength field shows a size of ~400Kb, much smaller than the actual file size, and the data I receive is the size indicated in the ContentLength field.
If there was a limitation on file size I would expect an error from the server, not a status 200.

Does anyone know whats going on?

I have pasted the javascript and applet code below:

Code:
//javascript code:
function renderJob(sendbutton) {
	var send_status=document.getElementById('sendStatus');
	send_status.innerHTML="<br><h3>Sending to Printer....</h3>";
	sendbutton.disabled='true';

	var token = document.PreviewApp.getUserJobToken();
	var model = document.CreateJob.getPrinterModel();
	var jobticket = document.CreateJob.getUserJobSettings();
	var req = new XMLHttpRequest();

	req.onreadystatechange = function() {
	if(req.readyState==4) {
		var mydata = eval('(' + req.responseText + ')');
		var dataurl = "http://" + window.location.hostname + mydata.result.renderurl;
		document.CreateJob.setUserJobDataUrl(dataurl);
		document.CreateJob.sendPrintJob(document.CreateJob.getUserJobDataUrl()); 
		window.location = "http://" + window.location.hostname + "/dev/printstatus.html";
	}
	}
	var data = "{\"method\":  \"RenderPrintJob\", \"params\":  [\"" + model + "\", " + jobticket +  ", \"" + token + "\"],  \"id\":  5}";
	req.open("POST", "http://" + window.location.hostname + "/jsonsvc/", true);
	req.setRequestHeader("Content-type", "text/json");
	req.setRequestHeader("Content-Length", data.length);
	req.send(data);
}


//applet code:
public static synchronized int sendPrintJob(String jobUrl){
		
		Printer currentPrinter = Printer.getCurrentPrinter();
		String printer_address = currentPrinter.ipAddress;
		printer_address = printer_address.substring(0, printer_address.indexOf("/"));
		int totalRead = 0;
		int dataRead = 0;
		if(jobUrl != null){
			String fullUrl = "http://172.30.4.10" + jobUrl;
			System.out.println("sendPrintJob: to following url: " + fullUrl);
			 try {
				 URL serverUrl = new URL(jobUrl);
				 URLConnection WASserver = serverUrl.openConnection();
				 //int bufSize = WASserver.getContentLength();
				 int bufSize = 4096;
				 byte [] dataBuffer = new byte[bufSize];
				 System.out.println("sendPrintJob: contentlength = " + WASserver.getContentLength());
				 
				 InputStream fromWASServer = WASserver.getInputStream();	
				 
				 Socket client = new Socket(printer_address, 9100);
				 System.out.println("sendPrintJob value of keep alive = " + client.getKeepAlive());
				 client.setKeepAlive(true);
				 OutputStream toPrinter = client.getOutputStream();
				 
				 dataRead = fromWASServer.read(dataBuffer, 0, bufSize);		
				 
				 while (dataRead > 0) {
					 totalRead += dataRead;
					 toPrinter.write(dataBuffer,0, dataRead);
					 dataRead = fromWASServer.read(dataBuffer, 0, bufSize);
					
				 }
				 System.out.println("sendPrintJob: total read = " + totalRead);
				 
				 fromWASServer.close();
				 client.close();
			 }
			 catch(MalformedURLException e) {
				 System.out.println("sendPrintJob: malformed server url: " + e.getMessage());
			 }
			 catch(IOException e) {
				 System.out.println("sendPrintJob: error opening/reading server url: " + e.getMessage());
			 }
		
		}
		else { //no job URL so send a default print job to printer for demo purposes.
			try{
				System.out.println("Trying to print to: " + printer_address);
				Socket client = new Socket(printer_address, 9100);
				System.out.println("Connection to my printserver made!");
				String jobData = "Simple string sent to printer: " + printer_address;
				client.getOutputStream().write(jobData.getBytes());
				client.close();
			}
			catch(IOException io){
				System.out.println("Uknown server");
			}
		}
		return 0;
	}