Problema
Al intentar ejecutar un archivo jsp, se obtiene un error en la instancia error.log similar al siguiente:
14:55:42 *ERROR* entrega: Excepción no manejada: java.lang.IllegalStateException: OutputStream ya obtenido java.lang.IllegalStateException: OutputStream ya obtenido
Solución
Utilice eliminadores de línea y asegúrese de que no haya espacios ni retornos de carro en el archivo. La implementación apropiada del jsp mostrado arriba es la siguiente:
<%@ page import="java.io.*" %><% %><%@ page import="com.day.cq.delivery.DeliveryHttpServletRequest" %><% %><%@ page import="com.day.cq.activation.MimeTab" %><% %><%@ page import="com.day.cq.contentbus.*" %><% %><%@ page import="com.day.util.IO" %><% // Instanciate a Communiqué Request Object based on the implicite JSP-request DeliveryHttpServletRequest cqRequest = (DeliveryHttpServletRequest) request; // set the response ContentType information based on the request uri extension String mimeType = MimeTab.getContentType(cqRequest.getRequestURI()); response.setContentType(mimeType); // Using the request.getAtom() method if the Selectors define the Content Atom Atom atom = (Atom) cqRequest.getAtom(); // Instanciate and cast the Content Atom to a Java stream InputStream inputStream = atom.getStream(); IO.spool(inputStream, response.getOutputStream()); // close the input stream inputStream.close(); %>
Puede utilizar servlets para procesar imágenes en lugar de jsp.
Información adicional
Este problema ocurre si en su jsp intenta obtener el flujo de salida de respuesta, pero ya se ha obtenido. Podría haber una línea vacía en el código jsp. Aquí hay un ejemplo de gestión de impresión de imágenes que genera este error:
<%@ page import="java.io.*" %> <%@ page import="com.day.cq.delivery.DeliveryHttpServletRequest" %> <%@ page import="com.day.cq.activation.MimeTab" %> <%@ page import="com.day.cq.contentbus.*" %> <%@ page import="com.day.util.IO" %> <% // Instanciate a Communiqué Request Object based on the implicite JSP-request DeliveryHttpServletRequest cqRequest = (DeliveryHttpServletRequest) request; // set the response ContentType information based on the request uri extension String mimeType = MimeTab.getContentType(cqRequest.getRequestURI()); response.setContentType(mimeType); // Using the request.getAtom() method if the Selectors define the Content Atom Atom atom = (Atom) cqRequest.getAtom(); // Instanciate and cast the Content Atom to a Java stream InputStream inputStream = atom.getStream(); IO.spool(inputStream, response.getOutputStream()); // close the input stream inputStream.close(); %>
Inicia sesión en tu cuenta