Печатаю в консольном приложении через JasperReport-6 несколько тысяч заданий в день на разные сетевые принтеры. Периодически вылетает ошибка:
Ошибка:No suitable print service found.
net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:323)
При повторной отправке задания все отлично. Отловить отладчиком не могу. Этих ошибок в день около 100, а заданий несколько тысяч. Печатаю вот так:
jasperPrint = JasperFillManager.fillReport(getClass().getResourceAsStream(fn), parameters, cn);
if (!jasperPrint.getPages().isEmpty()) {
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new JobName("Picklist_ID" + picklistId + "", null));
if (ps != null) {
System.out.println("PICKLIST_ID:" + picklistId + " WID:" + workshopId + " MS:" + ms + " " + curWorkMode.toString() + " PRINTER:" + ps.getName() + " " + new Date().toString() + " Prior" + priority);
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
SimplePrintServiceExporterConfiguration conf = new SimplePrintServiceExporterConfiguration();
conf.setPrintRequestAttributeSet(printRequestAttributeSet);
conf.setPrintServiceAttributeSet(ps.getAttributes());
conf.setDisplayPageDialog(Boolean.FALSE);
conf.setDisplayPrintDialog(Boolean.FALSE);
exporter.setConfiguration(conf);
exporter.exportReport();
}}
Ошибка вылетает на последней строчке:
exporter.exportReport();
PrintService psDefault = PrintServiceLookup.lookupDefaultPrintService(); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Looking for printers:"); for (PrintService service : services) { ... }