I have an issue in communication between my java server (based on sockets) and the content of a web page obtained by a java script.
The js asks to my server an xml and then the server replies using http, however the xml isn't shown. Using Firebug (mozilla plugin) I notice that the response http header is well received but there's no content.
Making the same request directly from a browser (I used mozilla and chrome) the xml is well returned and formatted.

here a bit of code...

java server code:

Java Code:
package Server;
		import java.io.DataOutputStream;
		import java.io.IOException;
		import java.io.OutputStream;
		import java.io.PrintStream;
		import java.io.PrintWriter;
		import java.net.ServerSocket;
		import java.net.Socket;
		public class ClasseMain {
			 * @param args
			 * @throws IOException 
			public static void main(String[] args) throws IOException {
				int i =0;
					try {
					} catch (Exception e) {
						System.out.println("errore iterazione n: "+i);
			static void normalSocket()
					ServerSocket s= new ServerSocket(8080);
					Socket c = s.accept();
					System.out.println("\n\n\n\nConnessione stabilita");
					PrintWriter o = new PrintWriter(c.getOutputStream(),true);
					o.println("HTTP/1.1 200 OK\n"+
							//					"Server: nginx/1.0.4\n"+
							//					"Date: Fri, 10 Jun 2011 15:49:08 GMT\n"+
							"Content-Type: text/xml; charset=utf-8\n\n" +
							//					"Transfer-Encoding: chunked\n" +
							//					"Connection: keep-alive\n" +
							//					"X-Powered-By: PHP/5.3.5-1ubuntu7.2\n" +
							//					"P3P: CP="+'"'+"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"+'"'+"\n\n\n" +
							//					"225\n" +
							"<?xml version="+'"'+"1.0"+'"'+" encoding="+'"'+"UTF-8"+'"'+" ?>\n" +
							"<refresh>\n" +
							"<item>ciao ciao</item>\n"+
					System.out.println("HTTP/1.1 200 OK\n"+
							//					"Server: nginx/1.0.4\n"+
							//					"Date: Fri, 10 Jun 2011 15:49:08 GMT\n"+
							"Content-Type: text/xml; charset=utf-8\n\n" +
							//					"Transfer-Encoding: chunked\n" +
							//					"Connection: keep-alive\n" +
							//					"X-Powered-By: PHP/5.3.5-1ubuntu7.2\n" +
							//					"P3P: CP="+'"'+"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"+'"'+"\n\n\n" +
							//					"225\n" +
							"<?xml version="+'"'+"1.0"+'"'+" encoding="+'"'+"UTF-8"+'"'+" ?>\n" +
							"<refresh>" +
							"<item>ciao ciao</item>"+
				}catch (Exception e)

I tried to use different types of stream (as you can see in the imports) to outputting the response, with no success.

Client side development isn't my responsibility, however I post the js and html code for completeness:


XML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml"><head>
			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	<title>
				CakePHP: the rapid development php framework:		Control	</title>
			<script type="text/javascript" src="control_files/jquery.js"></script><link href="" type="image/x-icon" rel="icon"><link href="" type="image/x-icon" rel="shortcut icon"><link rel="stylesheet" type="text/css" href="control_files/cake.css"><link rel="stylesheet" type="text/css" href="control_files/menu.css"></head>
			<div id="container">
				<div id="header">
							<ul id="main-menu" class="menu">
			<li class="first-item"><a title="Home" href="">Home</a></li>
			<li><a title="User" href="">User</a></li>
			<li><a title="Sponsor" href="">Sponsor</a></li>
			<li><a title="Style" href="">Style</a></li>
			<li><a title="Badword" href="">Badword</a></li>
			<li><a title="Propriety" href="">Propriety</a></li>
			<li><a title="Identify" href="">Identify</a></li>
			<li class="active"><a title="Control" href="">Control</a></li>
			<li><a title="Activity" href="">Activity</a></li>
			<li><a title="Logout" href="">Logout</a></li>
				<div id="content">
					<link rel="stylesheet" type="text/css" href="control_files/countdown.css"><script type="text/javascript">
				var URL_REFRESH = "";
				var URL_PROCESS = "";
				var URL_SENDSMS = "";
				var URL_DISCO = "";
				var URL_REFRESH = "";
				var URL_PROCESS = "";
				var URL_SENDSMS = "";
				var URL_DISCO = "";
						var REFRESH = 2000;
				var PROCESS = new Array();
				PROCESS[0] = new Array(); PROCESS[0]['name'] = 'da_approvare'; PROCESS[0]['values'] = ''; PROCESS[1] = new Array(); PROCESS[1]['name'] = 'approvato'; PROCESS[1]['values'] = '1'; PROCESS[2] = new Array(); PROCESS[2]['name'] = 'onair'; PROCESS[2]['values'] = '2'; PROCESS[3] = new Array(); PROCESS[3]['name'] = 'visto'; PROCESS[3]['values'] = '3'; PROCESS[4] = new Array(); PROCESS[4]['name'] = 'recheck'; PROCESS[4]['values'] = '4'; PROCESS[5] = new Array(); PROCESS[5]['name'] = 'eliminato'; PROCESS[5]['values'] = '9'; 
				<script type="text/javascript" src="control_files/date.js"></script>		<script type="text/javascript" src="control_files/countdown.js"></script>				<script type="text/javascript" src="control_files/countdown-it.js"></script>		<script type="text/javascript" src="control_files/timeout.js"></script>		<script type="text/javascript" src="control_files/control.js"></script>                <script type="text/javascript" src="control_files/sendsms.js"></script>		
		<div class="controlphones index">
			Control	</h2>
			<div id="return"></div>
			<table id="control" cellpadding="0" cellspacing="0">
					<th class="actions">Actions</th>
		<div class="actions">
			<h3>Sms AJAX</h3>
		<form id="ActioninboxIndexForm" method="post" action="/eng/actioninboxes" accept-charset="utf-8"><div style="display:none;"><input name="_method" value="POST" type="hidden"></div>	<fieldset>
			<div class="input select"><label for="ActioninboxUserId">User</label><select name="data[Actioninbox][user_id]" id="ActioninboxUserId"><option selected="selected" id="DiscoOnline" value="22">ITdisc1</option></select></div><div class="input textarea"><label for="ActioninboxSmssent">Smssent</label><textarea name="data[Actioninbox][smssent]" cols="30" rows="6" id="ActioninboxSmssent"></textarea></div><input name="data[Actioninbox][idnation]" id="ActioninboxIdnation" type="hidden">	</fieldset>
		<div class="submit"><input value="Submit" id="submit1698940554" onclick="return false;" type="submit"></div><script type="text/javascript">
		$("#submit1698940554").bind('click', function(){ $.ajax({async:true, type:'post', url:'/eng/Actioninboxes/saveMessageFromPC', data:$(this).parents('form:first').serialize()}); $("#ActioninboxSmssent").val(""); })
				<div id="footer">
					<a href="http://www.cakephp.org/" target="_blank"><img src="control_files/cake.gif" alt="CakePHP: the rapid development php framework" border="0"></a>		</div>

Java Code:
		function refresh() {
		function getXML(){
				type: "POST",
				url: URL_REFRESH,
				dataType: "xml",
				success: parseXml
			$.timeout(refresh, REFRESH);
		var i = 0;
		var DIFFERENCE =  new Date();
		function parseXml(xml){
				//impostazione data server
				REFRESH = $(this).find('timer').text();
		function setMessage(msg){
			var message = "<tr id='controlmsg' class='"+i+"' > <td>"+ msg.find('smsadministrator').text()+
			"</td><td><div id='end"+i+"'></div></td><td><div id='actions"+i+"'></div></td></tr>";
			if(msg.find('id').text() != ''){
				//var mess = msg.find('actioninbox');
				actionMessage(msg.find('process').text(), msg.find('actioninbox').find('id').text());//TODO passare l'id del messaggio
		function removeMessages(){
		function endMessage(end){
			if(end != ''){
				var date = new Date(); 
				date = Date.parseExact(end, "yyyy-M-d H:mm:ss"); //date = Date.parseExact("2011-04-14 13:59:55", "yyyy-M-d H:mm:ss"); 
				date = date.getTime() + DIFFERENCE;
						date = new Date(date);
						$('#end'+i).countdown({until: date, format:'MS'});
		function actionMessage(state,id){
			state = (state*1)+1;
			var actions = '';
			for(var k=state; k<PROCESS.length;k++){
				if(PROCESS[k]['name'] != 'onair' && PROCESS[k]['name'] != 'visto' && PROCESS[k]['name'] != 'recheck'){
					actions += '<a href="javascript:actionSubmit('+id+', '+PROCESS[k]['values']+')">'+PROCESS[k]['name']+'</a> ';
		function actionSubmit(id, process){
			var href = URL_PROCESS+'/'+id+'/'+process;
				   $('#return').html(response).delay(1800).hide('slow').show();//x fdarlo scomparire dopo 800 millisecond e poi lasciarlo visibile.
		function syncroDate(dateserver){
			var server = new Date();
			server = Date.parseExact(dateserver, "yyyy-M-d H:mm:ss");
			var locale = new Date();
			DIFFERENCE = (locale.getTime() - server.getTime());

finally a screenshot of Firebug error console

Errore interpretazione XML: nessun elemento trovato Indirizzo: moz-nullprincipal:{9e2adab2-b678-424a-96eb-9c6ad78bdd19} Linea numero 1, colonna 1:

it means: error xml parsing: no element found .... line 1 col 1

ImageShack® - Online Photo and Video Hosting

ImageShack® - Online Photo and Video Hosting

Thanks to everyone will help me (i'm going completely mad) on how to resolve the problem or suggest a solution