Error generating billet using Stella Boleto

Asked

Viewed 347 times

1

I’m having trouble generating a ticket for Bradesco Bank. I’m using Stella from Caelum and IDE Intellij, only the basic code for testing that follows:

public class BradescoBoleto  {


        public static void main(String[] args) {

            Datas datas = Datas.novasDatas()
                    .comDocumento(1, 5, 2016)
                    .comProcessamento(1, 5, 2016)
                    .comVencimento(2, 12, 2016);

            Endereco enderecoBeneficiario = Endereco.novoEndereco()
                    .comLogradouro("Av das Empresas, 555")
                    .comBairro("Bairro Grande")
                    .comCep("01234-555")
                    .comCidade("São Paulo")
                    .comUf("SP");

            //Quem emite o boleto

            Beneficiario beneficiario = Beneficiario.novoBeneficiario()
                    .comNomeBeneficiario("Fulano de Tal")
                    .comAgencia("1824").comDigitoAgencia("4")
                    .comCodigoBeneficiario("76000")
                    .comDigitoCodigoBeneficiario("5")
                    .comNumeroConvenio("1207113")
                    .comCarteira("18")
                    .comEndereco(enderecoBeneficiario)
                    .comDocumento("05.606.206/0001-83")
                    .comNossoNumero("9000206").comDigitoNossoNumero("3");

            Endereco enderecoPagador = Endereco.novoEndereco()
                    .comLogradouro("Av dos testes, 111 apto 333")
                    .comBairro("Bairro Teste")
                    .comCep("01234-111")
                    .comCidade("São Paulo")
                    .comUf("SP");

            //Quem paga o boleto

            Pagador pagador = Pagador.novoPagador()
                    .comNome("Fulano da Silva")
                    .comDocumento("111.222.333-12")
                    .comEndereco(enderecoPagador);

            Banco banco = new Bradesco();

            Boleto boleto = Boleto.novoBoleto()
                    .comBanco(banco)
                    .comDatas(datas)
                    .comBeneficiario(beneficiario)
                    .comPagador(pagador)
                    .comValorBoleto("200.00")
                    .comNumeroDoDocumento("1234")
                    .comInstrucoes("instrucao 1", "instrucao 2", "instrucao 3", "instrucao 4", "instrucao 5")
                    .comLocaisDePagamento("local 1", "local 2");

            GeradorDeBoleto gerador = new GeradorDeBoleto(boleto);


            System.out.println(gerador.toString());
            File pdf = new File("/home/hortela/testeboleto/BancoSemear.pdf");
            gerador.geraPDF(pdf);

        }


}

I’m getting the bug:

Exception in thread "main" br.com.caelum.stella.boleto.exception.GeracaoBoletoException: net.sf.jasperreports.engine.JRException: Error loading object from InputStream
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.<init>(GeradorDeBoleto.java:63)
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.<init>(GeradorDeBoleto.java:73)
    at SemearBoleto.main(SemearBoleto.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: net.sf.jasperreports.engine.JRException: Error loading object from InputStream
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:249)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:229)
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.<init>(GeradorDeBoleto.java:61)
    ... 7 more
Caused by: java.io.StreamCorruptedException: invalid stream header: 3C3F786D
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:58)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:244)
    ... 9 more

Process finished with exit code 1

No debug indicates fault in this stretch:

try {
        this.templateJasper = GeradorDeBoleto.class.getResourceAsStream("/br/com/caelum/stella/boleto/templates/boleto-default.jrxml");
        this.parametros.put("REPORT_LOCALE", new Locale("pt", "BR"));
        InputStream e = GeradorDeBoleto.class.getResourceAsStream("/br/com/caelum/stella/boleto/templates/boleto-default_instrucoes.jrxml");
        this.parametros.put("SUB_INSTRUCOES", JRLoader.loadObject(e));
    } catch (JRException var3) {
        throw new GeracaoBoletoException(var3);
    }
}

I have checked and all libraries and all have been added properly.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.