Eu tenho este exemplo, mas o último println que obtenho é o 3. Logo, o programa parece que fica bloqueado na linha oostr.writeObject(obj);.
O Object obj contém informação. Ou seja, não é null.
Alguém tem sugestões?
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletResponse;
public class ServletUtil {
/**
* Create a HTTP servlet response from the given result object.
* The given object is serialized into the response output stream.
* @param resp the HTTP servlet response to be filled
* @param obj the object to be transmitted in the HTTP servlet response
* @throws IOException in case of stream henaling / serialization problems
*/
public static void createResponse(HttpServletResponse resp, Object obj) throws IOException {
final String contentType = "application/x-java-serialized-object";
resp.setContentType(contentType);
// Serialize obj into a byte array stream first so that we can determine
// the length - setting Content-Length is a precondition for HTTP keep-alive.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
System.out.println("1");
ObjectOutputStream oostr = new ObjectOutputStream(bos);
System.out.println("2");
OutputStream os = resp.getOutputStream();
System.out.println("3");
oostr.writeObject(obj);
System.out.println("4");
int contentLength = bos.size();
System.out.println("5");
resp.setContentLength(contentLength);
System.out.println("6");
bos.writeTo(os);
System.out.println("7");
bos.flush();
System.out.println("8");
bos.close();
System.out.println("9");
oostr.close();
System.out.println("10");
os.close();
System.out.println("11");
System.out.println("RESP.TOSTRING(): " + resp.toString());
}
}
Obrigado