Pessoal estou enviando um arquivo diretamente para uma impressora atraves do jasper. Quando rodo localmente a aplicação funciona normalmente, porem quando faço o upload para o servidor me deparo com o erro java.lang.NullPointerException.
Alguem já passou por isso?
public void doThisHTML(int id) throws IOException, JRException, ClassNotFoundException, SQLException, ServletException {
// obtém o relatório compilado
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
String url = request.getRequestURL().toString();
//ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
InputStream inputStream = getClass().getResourceAsStream(getPath() + "/detalheprodutos.jasper");
Conexao con = new Conexao();
Connection criaConexao = con.criaConexao();
// preenche o mapa de parâmetros
Map<String, Object> parametros = new HashMap<String, Object>();
parametros.put("id", id);
RequestDispatcher rd = null;
try{
JasperPrint jasperPrint = JasperFillManager.fillReport(getPath() + "/detalheprodutos.jasper", parametros, criaConexao);
//RELATÓRIO PARA IMPRESSAO DIRETA
System.setProperty("java.awt.headless", "false");
System.out.println("Passei pela impressao direta");
//configura a impressora
/*PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.PORTRAIT);
aset.add(new Copies(1));//numero de copias
aset.add(new JobName("Relatório", null));*/
PrintService impressora = PrintServiceLookup.lookupDefaultPrintService();//pega a impressora padrão do pc
//Exporta para a impressora
JRPrintServiceExporter export = new JRPrintServiceExporter();
export.setParameter(JRPrintServiceExporterParameter.JASPER_PRINT, jasperPrint);
//export.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, aset);
export.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, impressora.getAttributes());
export.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
export.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
export.exportReport();
FacesContext.getCurrentInstance().getExternalContext().redirect(url+"?id="+id);
}catch (JRException ex){
System.out.println("Erro de impressao: " + ex);
}
}