Oi pessoal estou tentando enviar uma string bem grande gerada pela biblioteca XStream de um servidor http para outro, e só está chegando parte dessa string do outro lado.
Já depurei o código, a string enviada tem aproximadamente 98KB e só chega 3,7KB para o outro servidor.
Aqui está o código para envio da string:
HashMap map = new HashMap();
XStream stream = new XStream();
URLConnection urlConnection;
DataOutputStream outStream;
DataInputStream inStream;
// Cria o corpo da página
if (userName != null && userName.length() > 0) {
map.put("login", userName);
}
if (password != null && password.length() > 0) {
map.put("password", User.encryptPasswork(password));
}
map.put("service", service);
map.put(GenericService.GET_DATABASE_FILE, database);
map.put("params", params);
XStream xStream = new XStream();
String body = xStream.toXML(map);
FileUtils.writeStringToFile(new File("/home/eduardo/Desktop/xml_client.xml"), body);
// Cria a conexão com a página
URL serverUrl = new URL(ServerConnection.PROTOCOL + getServerAddress() + ServerConnection.BASE_PAGE + ServerConnection.SERVICE);
urlConnection = serverUrl.openConnection();
((HttpURLConnection)urlConnection).setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "multipart/form-data; charset=UTF-8");
//urlConnection.setRequestProperty("Content-Length", ""+ body.length());
// Cria os streams
outStream = new DataOutputStream(urlConnection.getOutputStream());
// Manda o request
outStream.write(body.getBytes());
outStream.flush();
outStream.close();
No outro lado estou pegando a string da seguinte forma:
//a variável req é a requisição da sessão do servlet
byte[] b = null;
int bytesRead = 0;
String body = "";
do {
b = new byte[req.getInputStream().available() > 1024 ? 1024 : req.getInputStream().available()];
bytesRead = req.getInputStream().read(b);
body += new String(b);
} while(bytesRead >= 1024);
FileUtils.writeStringToFile(new File("/home/eduardo/Desktop/xml_server.xml"), body);
Já testei este código com o tomcat e também com o servidor embutido do GWT que usa o Jetty, em ambos a string chega imcompleta.
Alguém ai já passou por isso?
Obrigado.