Problema
Quando tenti di eseguire il file jsp, viene visualizzato un errore nel file error.log di istanza simile al seguente:
14:55:42 *ERROR* delivery: Eccezione non gestita: java.lang.IllegalStatoException: OutputStream già ottenuto java.lang.IllegalStateException: OutputStream già ottenuto
Soluzione
Usa i line killer e assicurati che non ci siano spazi o ritorni a capo nel file. La corretta implementazione del jsp sopra indicato è la seguente:
<%@ 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(); %>
È possibile utilizzare i servlet per elaborare le immagini al posto di jsp.
Informazioni aggiuntive
Questo problema si verifica se nel vostro jsp cerchi di ottenere il flusso di risposta in uscita, ma è già stato ottenuto. Potrebbe esserci una riga vuota nel codice jsp. Ecco un esempio di spooling dell'immagine che genera questo errore:
<%@ 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(); %>
Accedi al tuo account