[Ajuda] SeamTest + Download de PDF - NullPointerException

0 respostas
F
Bom dia pessoal do GUJ. Venho aqui pedir ajuda com o SeamTest, estou tendo um problema que não consigo arrumar de jeito nenhum. Eu tenho uma classe X e uma classe de teste XTest. XTest chama
protected void renderResponse() throws Exception {
				colocaUsuarioAutenticado();
				EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
				Os os = entityManager.find(Os.class, 42357);
				Context context = Contexts.getConversationContext();
				context.set("idOs",os.getIdOs().toString());
				assert invokeAction("#{x.confirmar}") != null;
				invokeAction("#{x.downloadRelatorio}");
				
			}
Internamente dentro da classe X, após alguns testes para a verificação se existe mesmo o relatório, é chamado:
public void downloadRelatorio() throws IOException {
		if (isParametrosJaCadastrados()) {
			try {
				byte[] pdfRelatorio = parametroParecer.getRelatorio()
						.getRelatorioDefinitivo().getPdf();
				UtilRelatorio.exportarPDF(pdfRelatorio, NOME_RELATORIO_BIRT);
				StringBuffer descOperacao = new StringBuffer(
						"Download de parecer da OS ");
				descOperacao.append(os.getIdOs());
				descOperacao.append(" Relatório Definitivo: Sim");
				logService.registraLog(descOperacao.toString());
			} catch (IOException io) {
				log.error("Erro na exibição do relatório definitivo em PDF",io);
			}
		}
E dentro dessa classe UtilRelatorio, tenho o método:
public static void exportarPDF(byte[] conteudo, String fileName) throws IOException {
		FacesContext context = UtilContexto.getContextoAtual();
		HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
		ServletOutputStream servletOutputStream = response.getOutputStream();
		response.setContentType("application/pdf");
		response.setContentLength(conteudo.length);
		response.setHeader("Content-Disposition", "inline; filename=\"" + fileName + ".pdf\"");
		servletOutputStream.write(conteudo, 0, conteudo.length);
		servletOutputStream.flush();
		servletOutputStream.close();
		context.responseComplete();
	}
Só que no servletOutputStream.write eu recebo um NullPointerException, e olhando a implementação:
public void write(byte b[], int off, int len) throws IOException {
	if (b == null) {
	    throw new NullPointerException();
	} else if ((off < 0) || (off > b.length) || (len < 0) ||
		   ((off + len) > b.length) || ((off + len) < 0)) {
	    throw new IndexOutOfBoundsException();
	} else if (len == 0) {
	    return;
	}
	for (int i = 0 ; i < len ; i++) {
	    write(b[off + i]);
	}
    }

Verifica-se que a variável conteúdo deve estar chegando com o valor null. Eu não posso mexer no código, apenas na classe de teste.
Alguém tem experiência com esse tipo de erro? Eu debuguei, coloquei asserts antes do servletOutPutStream.write e verifiquei que o conteudo antes da chamada não era null.
Seria algum bug do SeamTest?
Na classe de XTest fiz a chamada dentro de FacesRequest, de NonFacesRequest, mas nas duas retorno com o mesmo erro no mesmo momento.
Agradeço a ajuda desde já. :thumbup:

Criado 17 de novembro de 2009
Respostas 0
Participantes 1