Pessoal, estou tentando gerar um boleto na web utilizando o JBoleto em um Servlet:
public class JBoletoSvlt extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
ArrayList<Boleto> boletos = (ArrayList<Boleto>)request.getAttribute("boletos");
//out.print("Qtde de boletos: "+boletos.size()+"<br><br>");
String vencimento = "";
String emissao = "";
String processamento = "";
SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy" );
for (int x = 0; x < boletos.size(); x++) {
Boleto b = new Boleto();
b = boletos.get(x);
emissao = sdf.format( b.getData_emissao());
processamento = sdf.format(b.getData_processamento());
vencimento = sdf.format( b.getVencimento());
//Inicio JBoleto
JBoletoBean jBoletoBean = new JBoletoBean();
jBoletoBean.setDataDocumento(emissao);
jBoletoBean.setDataProcessamento(processamento);
jBoletoBean.setCedente(b.getNome_cedente());
jBoletoBean.setCarteira(b.getCarteira());
jBoletoBean.setNomeSacado(b.getNome_sacado());
jBoletoBean.setEnderecoSacado(b.getEndereco_sacado());
jBoletoBean.setBairroSacado(b.getBairro_sacado());
jBoletoBean.setCidadeSacado(b.getCidade_sacado());
jBoletoBean.setUfSacado(b.getEstado_sacado());
jBoletoBean.setCepSacado(b.getCep_sacado());
jBoletoBean.setCpfSacado(b.getCgc());
jBoletoBean.setDataVencimento(vencimento);
jBoletoBean.setInstrucao1("Após vencimento cobrar 2% de juros");
jBoletoBean.setInstrucao2("Após o vencimento cobrar R$ 0,50 centavos de mora por dia");
jBoletoBean.setAgencia(b.getAgencia());
jBoletoBean.setContaCorrente(b.getCedente());
jBoletoBean.setDvContaCorrente(b.getDvContaCorrente());
jBoletoBean.setNossoNumero(b.getNosso_numero(), 8);
jBoletoBean.setValorBoleto(b.getValor());
Vector<String> descricoes = new Vector<String>();
descricoes.add(b.getMensagem());
jBoletoBean.setDescricoes(descricoes);
JBoleto jBoleto = new JBoleto();
jBoleto.addBoleto(jBoletoBean,JBoleto.ITAU);
jBoleto.writeToFile("boleto.pdf");
URL url = request.getSession().getServletContext().getResource("/boleto.pdf");
System.out.println("URL: "+url);
BufferedInputStream leitor = new BufferedInputStream(url.openStream(), 4*1024);
ServletOutputStream escritor = response.getOutputStream();
byte[]buffer = new byte[4 * 1024];
int size;
while((size = leitor.read(buffer, 0, buffer.length)) != -1 ){
escritor.write(buffer, 0, size);
}
escritor.close();
leitor.close();
}
}
}
Acontece que a URL está ficando NULA URL url = request.getSession().getServletContext().getResource("/boleto.pdf");, onde ocorre o erro!!!
Quais as saídas que tenho para resolver este problema ?
Valew.