Erro: OutputStream já obtido

Problema

Quando tenta executar seu arquivo jsp, você recebe um erro em sua instância error.log semelhante ao seguinte:

14:55:42 *ERROR* delivery: Unhandled Exception: java.lang.IllegalStateException: OutputStream already obtained java.lang.IllegalStateException: OutputStream already obtained

Solução

Use quebras de linha e certifique-se de que não haja espaços ou CRs no arquivo. A implementação adequada do jsp mostrado acima é a seguinte:

<%@ 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(); %>

Observação:

Você pode usar servlets para processar imagens em vez de jsp.

Informações adicionais

Esse problema ocorre se você tentar obter o fluxo de saída da resposta no seu jsp, mas ele já tiver sido obtido. Poderá haver uma linha vazia no código jsp. Aqui está um exemplo de spool de imagem que gera este erro:

<%@ 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(); %>

Logotipo da Adobe

Fazer logon em sua conta