-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
8u191
-
x86_64
-
windows_10
ADDITIONAL SYSTEM INFORMATION :
************ Start Display Current Environment ************
WebSphere Platform 8.5.5.11 [ND 8.5.5.11 cf111649.01] [IBMJAVA8 8.0.3.0 cf101629.01] [IBMJAVA7 7.0.9.60 cf111647.02] running with process name ispDmgrCell\ispNode\hwServer and process id 7138
Host Operating System is Linux, version 3.0.101-108.21-default
Java version = 1.8.0_191, Java Runtime Version = 8.0.5.25 - pxa6480sr5fp25-20181030_01(SR5 FP25), Java Compiler = j9jit29, Java VM name = IBM J9 VM
was.install.root = /opt/WebSphere/prod/AppServer
user.install.root = /opt/WebSphere/prod/AppServer/profiles/AppSrvs
Java Home = /opt/WebSphere/V8.5.5/AppServer/java/jre
ws.ext.dirs = /opt/WebSphere/prod/AppServer/java/lib:/opt/WebSphere/prod/AppServer/profiles/AppSrvs/classes:/opt/WebSphere/prod/AppServer/classes:/opt/WebSphere/prod/AppServer/lib:/opt/WebSphere/prod/AppServer/installedChannels:/opt/WebSphere/prod/AppServer/lib/ext:/opt/WebSphere/prod/AppServer/web/help:/opt/WebSphere/prod/AppServer/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime
Classpath = /opt/WebSphere/prod/AppServer/profiles/AppSrvs/properties:/opt/WebSphere/prod/AppServer/properties:/opt/WebSphere/prod/AppServer/lib/startup.jar:/opt/WebSphere/prod/AppServer/lib/bootstrap.jar:/opt/WebSphere/prod/AppServer/lib/jsf-nls.jar:/opt/WebSphere/prod/AppServer/lib/lmproxy.jar:/opt/WebSphere/prod/AppServer/lib/urlprotocols.jar:/opt/WebSphere/prod/AppServer/deploytool/itp/batchboot.jar:/opt/WebSphere/prod/AppServer/deploytool/itp/batch2.jar:/opt/WebSphere/prod/AppServer/java/lib/tools.jar:/h/hw/wasClasspath
Java Library path = /opt/WebSphere/prod/AppServer/lib/native/linux/x86_64/:/opt/WebSphere/V8.5.5/AppServer/java/jre/lib/amd64/compressedrefs:/opt/WebSphere/V8.5.5/AppServer/java/jre/lib/amd64:/opt/WebSphere/prod/AppServer/bin:/opt/WebSphere/prod/AppServer/nulldllsdir:/usr/lib64:/usr/lib::/opt/mqm/java/lib64
Orb Version = IBM Java ORB build orb80-20181016.00
************* End Display Current Environment *************
A DESCRIPTION OF THE PROBLEM :
When we sending the Jasper print object to the printer they throwing the below error and jobs stuck in printer queue.
D [06/Jan/2019:17:52:40 -0500] [Job 5290] -dict-
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Error: /undefined in --setpagedevice--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Operand stack:
D [06/Jan/2019:17:52:40 -0500] [Job 5290] --dict:5/5(L)--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Execution stack:
D [06/Jan/2019:17:52:40 -0500] [Job 5290] %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1921 1 3 %oparray_pop 1920 1 3 %oparray_pop 1904 1 3 %oparray_pop 1787 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 1889 1 3 %oparray_pop --nostringval--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Dictionary stack:
D [06/Jan/2019:17:52:40 -0500] [Job 5290] --dict:1170/3371(ro)(G)-- --dict:0/20(G)-- --dict:98/200(L)--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Current allocation mode is local
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Last OS error: 2
D [06/Jan/2019:17:52:40 -0500] [Job 5290] GPL Ghostscript 8.62: Unrecoverable error, exit code 1
E [06/Jan/2019:17:52:40 -0500] PID 12052 (/usr/lib64/cups/filter/pstoraster) stopped with status 1!
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Wrote 1 pages...
D [06/Jan/2019:17:52:40 -0500] PID 12051 (/usr/lib64/cups/filter/pstops) exited with no errors.
E [06/Jan/2019:17:52:40 -0500] [Job 5290] No pages found!
D [06/Jan/2019:17:52:40 -0500] Discarding unused printer-state-changed event...
E [06/Jan/2019:17:52:40 -0500] PID 12053 (/usr/lib64/cups/filter/rastertolabel) stopped with status 1!
D [06/Jan/2019:17:52:40 -0500] PID 12054 (/usr/lib64/cups/backend/socket) exited with no errors.
D [06/Jan/2019:17:52:40 -0500] [Job 5290] File 0 is complete.
E [06/Jan/2019:17:52:40 -0500] [Job 5290] Job stopped due to filter errors.
Same printer with same set of services and drivers are working fine with Java 8 Version 1.8.0.
REGRESSION : Last worked in version 8u191
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just send the jasper print object to the Printer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Reports must be printer
ACTUAL -
Report stuck in printer queue.
---------- BEGIN SOURCE ----------
/*
*
*/
package com.sdm.hw.integration.print.services;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.HashMap;
import java.util.Map;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
import com.sdm.hw.common.constant.UtilConstants;
import com.sdm.hw.exception.services.HwBaseAppException;
import com.sdm.hw.exception.services.HwInterfaceException;
import com.sdm.hw.exception.services.HwSystemException;
import com.sdm.hw.integration.print.dto.HwPrintDTO;
import com.sdm.hw.integration.print.intf.IPrintService;
import com.sdm.hw.logging.intf.HwLogger;
import com.sdm.hw.logging.services.LogManager;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.export.JRPrintServiceExporter;
import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;
/**
* The Class HwPrintServices.
*
* @author TCS
*/
public class HwPrintServices implements IPrintService {
/** The Constant ZERO. */
private static final int ZERO = 0;
private static final int ONE = 1;
private static final String VIALLABEL = "vialLabel";
/** The Constant A2. */
private static final String A2 = "A2";
/** The Constant A5. */
private static final String A5 = "A5";
/** The Constant A3. */
private static final String A3 = "A3";
private static final HwLogger logger = LogManager
.getLogger(HwPrintServices.class);
/**
* Gets the default print service.
*
* @return the default print service
*/
PrintService getDefaultPrintService() {
return PrintServiceLookup.lookupDefaultPrintService();
}
/**
* Gets the jR print service exporter.
*
* @param printDTO
* the print dto
* @return the jR print service exporter
* @throws HwBaseAppException
* the hw base app exception
*/
JRPrintServiceExporter getJRPrintServiceExporter(final HwPrintDTO printDTO)
throws HwBaseAppException {
PrintService printService;
/** The exporter. */
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
// it will set jrPrint file name into INPUT_FILE_NAME
LogManager.getLogger(this.getClass()).logDebug("Jasper print object {}",
printDTO.getJrprint());
exporter.setParameter(JRExporterParameter.JASPER_PRINT,
printDTO.getJrprint());
// it will set print service name into PRINT_SERVICE parameter of
// JRPrintServiceExporterParameter
printService=this.getPrintService(printDTO);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,
printService);
// this will set print atributes in print service attribute of
// JRPrintServiceExporterParameter
exporter.setParameter(
JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
printService!=UtilConstants.NULL?printService.getAttributes():UtilConstants.NULL);
exporter.setParameter(
JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
this.getPrintRequestAttributeSet(printDTO));
// this will set page display dialogue as false
exporter.setParameter(
JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,
Boolean.FALSE);
// this will set print display dialogue as false
exporter.setParameter(
JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,
Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.IGNORE_PAGE_MARGINS, Boolean.FALSE);
return exporter;
}
/**
* Gets the prints the job.
*
* @return the prints the job
*/
private PrinterJob getPrintJob() {
return PrinterJob.getPrinterJob();
}
/**
* Gets the prints the request attribute set.
*
* @param printDTO
* the print dto
* @return the prints the request attribute set
*/
PrintRequestAttributeSet getPrintRequestAttributeSet(
final HwPrintDTO printDTO) {
PrintRequestAttributeSet prntReqAttrSet = new HashPrintRequestAttributeSet();
//Commentted because it is not working in case of thermal printer
if(null != printDTO.getJrprint() && "vialLabel".equalsIgnoreCase(printDTO.getJrprint().getName()))
{
prntReqAttrSet.add(new MediaPrintableArea(0.0f,0.0f,2.0f,4.0f,MediaPrintableArea.INCH));
}
else
{
prntReqAttrSet.add(this.getMediaSizeName(printDTO));
}
return prntReqAttrSet;
}
/**
* Gets the prints the services.
*
* @return the prints the services
*/
private Map<String, PrintService> getPrintServices() {
DocFlavor docFlavor1 = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService[] prntSrvcs = PrintServiceLookup.lookupPrintServices(
docFlavor1, (AttributeSet) null);
for (PrintService printService : prntSrvcs) {
LogManager.getLogger(this.getClass()).logDebug(
"All thr print service names {}", printService.getName());
}
Map<String, PrintService> printServiceMap = new HashMap<String, PrintService>();
if ((prntSrvcs != null) && (prntSrvcs.length != 0)) {
for (PrintService printService : prntSrvcs) {
String name = printService.getName();
String shortName = name.substring(name.lastIndexOf("\\") + 1);
LogManager.getLogger(this.getClass()).logDebug(
"Final Print service shortname {}", shortName);
LogManager.getLogger(this.getClass()).logDebug(
"Final Print service name {}", name);
printServiceMap.put(shortName.toUpperCase(), printService);
}
}
return printServiceMap;
}
/**
* Gets the prints the service.
*
* @param printDTO
* the print dto
* @return the prints the service
* @throws HwBaseAppException
* the hw base app exception
*/
PrintService getPrintService(final HwPrintDTO printDTO)
throws HwBaseAppException {
HwPrintServices.logger.logDebug(
"In print service method || printing {}", printDTO);
String printerName = printDTO.getHostname().toUpperCase();
LogManager.getLogger(this.getClass()).logDebug(
"Printer Name from user {}", printerName);
Map<String, PrintService> printServices = this.getPrintServices();
PrintService prntSrvc;
if (printServices.containsKey(printerName)) {
prntSrvc = printServices.get(printerName);
} else {
prntSrvc = this.getDefaultPrintService();
LogManager.getLogger(this.getClass()).logDebug(
"Default print service is :{}", prntSrvc!=UtilConstants.NULL?prntSrvc.getName():UtilConstants.NULL);
}
if (prntSrvc != null) {
this.setPrintService(this.getPrintJob(), prntSrvc);
}
HwPrintServices.logger.logDebug(
"Exiting print service method || printing {}",
printDTO.getHostname());
LogManager.getLogger(this.getClass()).logDebug(
"Print service for user is ", prntSrvc!=null?prntSrvc.getName():UtilConstants.NULL);
return prntSrvc;
}
private void setPrintService(final PrinterJob job,
final PrintService prntSrvc) throws HwInterfaceException {
try {
LogManager.getLogger(this.getClass()).logDebug(
"Print service which is setting to print job {}",
prntSrvc.getName());
job.setPrintService(prntSrvc);
} catch (PrinterException exp) {
throw new HwInterfaceException("Exception in printing services",
exp);
}
}
/**
* Gets the media size name.
*
* @param printDTO
* the print dto
* @return the media size name
*/
private MediaSizeName getMediaSizeName(final HwPrintDTO printDTO) {
String tray = printDTO.getTray();
MediaSizeName mediaSizeName;
if(tray != null){
if (tray.equalsIgnoreCase(HwPrintServices.A2)) {
mediaSizeName = MediaSizeName.ISO_A2;
} else if (tray.equalsIgnoreCase(HwPrintServices.A3)) {
mediaSizeName = MediaSizeName.ISO_A3;
} else if (tray.equalsIgnoreCase(HwPrintServices.A5)) {
mediaSizeName = MediaSizeName.ISO_A5;
} else {
mediaSizeName = MediaSizeName.ISO_A4;
}
}else{
mediaSizeName = MediaSizeName.ISO_A4;
}
LogManager.getLogger(this.getClass()).logDebug(
"Media size for printing is {}", mediaSizeName);
return mediaSizeName;
}
/**
* Gets the num of copies.
*
* @param printDTO
* the print dto
* @return the num of copies
*/
private int getNumOfCopies(final HwPrintDTO printDTO) {
int copies = printDTO.getNumOfCopies();
int numOfCopies;
if (copies > HwPrintServices.ZERO) {
numOfCopies = copies;
} else {
numOfCopies = 1;
}
return numOfCopies;
}
/*
* (non-Javadoc)
*
* @see
* com.sdm.hw.integration.print.intf.IPrintService#printService(com.sdm.
* hw.integration.print.dto.HwPrintDTO)
*/
@SuppressWarnings("finally")
@Override
public boolean printService(final HwPrintDTO printDTO)
throws HwBaseAppException {
/** The exporter. */
JRPrintServiceExporter exporter = this
.getJRPrintServiceExporter(printDTO);
boolean flag = false;
try {
if(null!=printDTO && null!=printDTO.getJrprint() && null!=printDTO.getJrprint().getName() && HwPrintServices.VIALLABEL.equalsIgnoreCase(printDTO.getJrprint().getName())){
int copies=(HwPrintServices.ZERO!=printDTO.getNumOfCopies()?printDTO.getNumOfCopies():HwPrintServices.ONE);
for(int i=1;i<=copies;i++)
{
exporter.exportReport();
flag = true;
}
}
else
{
exporter.exportReport();
flag = true;
}
return flag;
} catch (JRException exp) {
throw new HwSystemException(
"Exception in exporting report to printer", exp);
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
************ Start Display Current Environment ************
WebSphere Platform 8.5.5.11 [ND 8.5.5.11 cf111649.01] [IBMJAVA8 8.0.3.0 cf101629.01] [IBMJAVA7 7.0.9.60 cf111647.02] running with process name ispDmgrCell\ispNode\hwServer and process id 7138
Host Operating System is Linux, version 3.0.101-108.21-default
Java version = 1.8.0_191, Java Runtime Version = 8.0.5.25 - pxa6480sr5fp25-20181030_01(SR5 FP25), Java Compiler = j9jit29, Java VM name = IBM J9 VM
was.install.root = /opt/WebSphere/prod/AppServer
user.install.root = /opt/WebSphere/prod/AppServer/profiles/AppSrvs
Java Home = /opt/WebSphere/V8.5.5/AppServer/java/jre
ws.ext.dirs = /opt/WebSphere/prod/AppServer/java/lib:/opt/WebSphere/prod/AppServer/profiles/AppSrvs/classes:/opt/WebSphere/prod/AppServer/classes:/opt/WebSphere/prod/AppServer/lib:/opt/WebSphere/prod/AppServer/installedChannels:/opt/WebSphere/prod/AppServer/lib/ext:/opt/WebSphere/prod/AppServer/web/help:/opt/WebSphere/prod/AppServer/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime
Classpath = /opt/WebSphere/prod/AppServer/profiles/AppSrvs/properties:/opt/WebSphere/prod/AppServer/properties:/opt/WebSphere/prod/AppServer/lib/startup.jar:/opt/WebSphere/prod/AppServer/lib/bootstrap.jar:/opt/WebSphere/prod/AppServer/lib/jsf-nls.jar:/opt/WebSphere/prod/AppServer/lib/lmproxy.jar:/opt/WebSphere/prod/AppServer/lib/urlprotocols.jar:/opt/WebSphere/prod/AppServer/deploytool/itp/batchboot.jar:/opt/WebSphere/prod/AppServer/deploytool/itp/batch2.jar:/opt/WebSphere/prod/AppServer/java/lib/tools.jar:/h/hw/wasClasspath
Java Library path = /opt/WebSphere/prod/AppServer/lib/native/linux/x86_64/:/opt/WebSphere/V8.5.5/AppServer/java/jre/lib/amd64/compressedrefs:/opt/WebSphere/V8.5.5/AppServer/java/jre/lib/amd64:/opt/WebSphere/prod/AppServer/bin:/opt/WebSphere/prod/AppServer/nulldllsdir:/usr/lib64:/usr/lib::/opt/mqm/java/lib64
Orb Version = IBM Java ORB build orb80-20181016.00
************* End Display Current Environment *************
A DESCRIPTION OF THE PROBLEM :
When we sending the Jasper print object to the printer they throwing the below error and jobs stuck in printer queue.
D [06/Jan/2019:17:52:40 -0500] [Job 5290] -dict-
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Error: /undefined in --setpagedevice--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Operand stack:
D [06/Jan/2019:17:52:40 -0500] [Job 5290] --dict:5/5(L)--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Execution stack:
D [06/Jan/2019:17:52:40 -0500] [Job 5290] %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1921 1 3 %oparray_pop 1920 1 3 %oparray_pop 1904 1 3 %oparray_pop 1787 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 1889 1 3 %oparray_pop --nostringval--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Dictionary stack:
D [06/Jan/2019:17:52:40 -0500] [Job 5290] --dict:1170/3371(ro)(G)-- --dict:0/20(G)-- --dict:98/200(L)--
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Current allocation mode is local
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Last OS error: 2
D [06/Jan/2019:17:52:40 -0500] [Job 5290] GPL Ghostscript 8.62: Unrecoverable error, exit code 1
E [06/Jan/2019:17:52:40 -0500] PID 12052 (/usr/lib64/cups/filter/pstoraster) stopped with status 1!
D [06/Jan/2019:17:52:40 -0500] [Job 5290] Wrote 1 pages...
D [06/Jan/2019:17:52:40 -0500] PID 12051 (/usr/lib64/cups/filter/pstops) exited with no errors.
E [06/Jan/2019:17:52:40 -0500] [Job 5290] No pages found!
D [06/Jan/2019:17:52:40 -0500] Discarding unused printer-state-changed event...
E [06/Jan/2019:17:52:40 -0500] PID 12053 (/usr/lib64/cups/filter/rastertolabel) stopped with status 1!
D [06/Jan/2019:17:52:40 -0500] PID 12054 (/usr/lib64/cups/backend/socket) exited with no errors.
D [06/Jan/2019:17:52:40 -0500] [Job 5290] File 0 is complete.
E [06/Jan/2019:17:52:40 -0500] [Job 5290] Job stopped due to filter errors.
Same printer with same set of services and drivers are working fine with Java 8 Version 1.8.0.
REGRESSION : Last worked in version 8u191
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just send the jasper print object to the Printer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Reports must be printer
ACTUAL -
Report stuck in printer queue.
---------- BEGIN SOURCE ----------
/*
*
*/
package com.sdm.hw.integration.print.services;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.HashMap;
import java.util.Map;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
import com.sdm.hw.common.constant.UtilConstants;
import com.sdm.hw.exception.services.HwBaseAppException;
import com.sdm.hw.exception.services.HwInterfaceException;
import com.sdm.hw.exception.services.HwSystemException;
import com.sdm.hw.integration.print.dto.HwPrintDTO;
import com.sdm.hw.integration.print.intf.IPrintService;
import com.sdm.hw.logging.intf.HwLogger;
import com.sdm.hw.logging.services.LogManager;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.export.JRPrintServiceExporter;
import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;
/**
* The Class HwPrintServices.
*
* @author TCS
*/
public class HwPrintServices implements IPrintService {
/** The Constant ZERO. */
private static final int ZERO = 0;
private static final int ONE = 1;
private static final String VIALLABEL = "vialLabel";
/** The Constant A2. */
private static final String A2 = "A2";
/** The Constant A5. */
private static final String A5 = "A5";
/** The Constant A3. */
private static final String A3 = "A3";
private static final HwLogger logger = LogManager
.getLogger(HwPrintServices.class);
/**
* Gets the default print service.
*
* @return the default print service
*/
PrintService getDefaultPrintService() {
return PrintServiceLookup.lookupDefaultPrintService();
}
/**
* Gets the jR print service exporter.
*
* @param printDTO
* the print dto
* @return the jR print service exporter
* @throws HwBaseAppException
* the hw base app exception
*/
JRPrintServiceExporter getJRPrintServiceExporter(final HwPrintDTO printDTO)
throws HwBaseAppException {
PrintService printService;
/** The exporter. */
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
// it will set jrPrint file name into INPUT_FILE_NAME
LogManager.getLogger(this.getClass()).logDebug("Jasper print object {}",
printDTO.getJrprint());
exporter.setParameter(JRExporterParameter.JASPER_PRINT,
printDTO.getJrprint());
// it will set print service name into PRINT_SERVICE parameter of
// JRPrintServiceExporterParameter
printService=this.getPrintService(printDTO);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,
printService);
// this will set print atributes in print service attribute of
// JRPrintServiceExporterParameter
exporter.setParameter(
JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
printService!=UtilConstants.NULL?printService.getAttributes():UtilConstants.NULL);
exporter.setParameter(
JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
this.getPrintRequestAttributeSet(printDTO));
// this will set page display dialogue as false
exporter.setParameter(
JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,
Boolean.FALSE);
// this will set print display dialogue as false
exporter.setParameter(
JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,
Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.IGNORE_PAGE_MARGINS, Boolean.FALSE);
return exporter;
}
/**
* Gets the prints the job.
*
* @return the prints the job
*/
private PrinterJob getPrintJob() {
return PrinterJob.getPrinterJob();
}
/**
* Gets the prints the request attribute set.
*
* @param printDTO
* the print dto
* @return the prints the request attribute set
*/
PrintRequestAttributeSet getPrintRequestAttributeSet(
final HwPrintDTO printDTO) {
PrintRequestAttributeSet prntReqAttrSet = new HashPrintRequestAttributeSet();
//Commentted because it is not working in case of thermal printer
if(null != printDTO.getJrprint() && "vialLabel".equalsIgnoreCase(printDTO.getJrprint().getName()))
{
prntReqAttrSet.add(new MediaPrintableArea(0.0f,0.0f,2.0f,4.0f,MediaPrintableArea.INCH));
}
else
{
prntReqAttrSet.add(this.getMediaSizeName(printDTO));
}
return prntReqAttrSet;
}
/**
* Gets the prints the services.
*
* @return the prints the services
*/
private Map<String, PrintService> getPrintServices() {
DocFlavor docFlavor1 = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService[] prntSrvcs = PrintServiceLookup.lookupPrintServices(
docFlavor1, (AttributeSet) null);
for (PrintService printService : prntSrvcs) {
LogManager.getLogger(this.getClass()).logDebug(
"All thr print service names {}", printService.getName());
}
Map<String, PrintService> printServiceMap = new HashMap<String, PrintService>();
if ((prntSrvcs != null) && (prntSrvcs.length != 0)) {
for (PrintService printService : prntSrvcs) {
String name = printService.getName();
String shortName = name.substring(name.lastIndexOf("\\") + 1);
LogManager.getLogger(this.getClass()).logDebug(
"Final Print service shortname {}", shortName);
LogManager.getLogger(this.getClass()).logDebug(
"Final Print service name {}", name);
printServiceMap.put(shortName.toUpperCase(), printService);
}
}
return printServiceMap;
}
/**
* Gets the prints the service.
*
* @param printDTO
* the print dto
* @return the prints the service
* @throws HwBaseAppException
* the hw base app exception
*/
PrintService getPrintService(final HwPrintDTO printDTO)
throws HwBaseAppException {
HwPrintServices.logger.logDebug(
"In print service method || printing {}", printDTO);
String printerName = printDTO.getHostname().toUpperCase();
LogManager.getLogger(this.getClass()).logDebug(
"Printer Name from user {}", printerName);
Map<String, PrintService> printServices = this.getPrintServices();
PrintService prntSrvc;
if (printServices.containsKey(printerName)) {
prntSrvc = printServices.get(printerName);
} else {
prntSrvc = this.getDefaultPrintService();
LogManager.getLogger(this.getClass()).logDebug(
"Default print service is :{}", prntSrvc!=UtilConstants.NULL?prntSrvc.getName():UtilConstants.NULL);
}
if (prntSrvc != null) {
this.setPrintService(this.getPrintJob(), prntSrvc);
}
HwPrintServices.logger.logDebug(
"Exiting print service method || printing {}",
printDTO.getHostname());
LogManager.getLogger(this.getClass()).logDebug(
"Print service for user is ", prntSrvc!=null?prntSrvc.getName():UtilConstants.NULL);
return prntSrvc;
}
private void setPrintService(final PrinterJob job,
final PrintService prntSrvc) throws HwInterfaceException {
try {
LogManager.getLogger(this.getClass()).logDebug(
"Print service which is setting to print job {}",
prntSrvc.getName());
job.setPrintService(prntSrvc);
} catch (PrinterException exp) {
throw new HwInterfaceException("Exception in printing services",
exp);
}
}
/**
* Gets the media size name.
*
* @param printDTO
* the print dto
* @return the media size name
*/
private MediaSizeName getMediaSizeName(final HwPrintDTO printDTO) {
String tray = printDTO.getTray();
MediaSizeName mediaSizeName;
if(tray != null){
if (tray.equalsIgnoreCase(HwPrintServices.A2)) {
mediaSizeName = MediaSizeName.ISO_A2;
} else if (tray.equalsIgnoreCase(HwPrintServices.A3)) {
mediaSizeName = MediaSizeName.ISO_A3;
} else if (tray.equalsIgnoreCase(HwPrintServices.A5)) {
mediaSizeName = MediaSizeName.ISO_A5;
} else {
mediaSizeName = MediaSizeName.ISO_A4;
}
}else{
mediaSizeName = MediaSizeName.ISO_A4;
}
LogManager.getLogger(this.getClass()).logDebug(
"Media size for printing is {}", mediaSizeName);
return mediaSizeName;
}
/**
* Gets the num of copies.
*
* @param printDTO
* the print dto
* @return the num of copies
*/
private int getNumOfCopies(final HwPrintDTO printDTO) {
int copies = printDTO.getNumOfCopies();
int numOfCopies;
if (copies > HwPrintServices.ZERO) {
numOfCopies = copies;
} else {
numOfCopies = 1;
}
return numOfCopies;
}
/*
* (non-Javadoc)
*
* @see
* com.sdm.hw.integration.print.intf.IPrintService#printService(com.sdm.
* hw.integration.print.dto.HwPrintDTO)
*/
@SuppressWarnings("finally")
@Override
public boolean printService(final HwPrintDTO printDTO)
throws HwBaseAppException {
/** The exporter. */
JRPrintServiceExporter exporter = this
.getJRPrintServiceExporter(printDTO);
boolean flag = false;
try {
if(null!=printDTO && null!=printDTO.getJrprint() && null!=printDTO.getJrprint().getName() && HwPrintServices.VIALLABEL.equalsIgnoreCase(printDTO.getJrprint().getName())){
int copies=(HwPrintServices.ZERO!=printDTO.getNumOfCopies()?printDTO.getNumOfCopies():HwPrintServices.ONE);
for(int i=1;i<=copies;i++)
{
exporter.exportReport();
flag = true;
}
}
else
{
exporter.exportReport();
flag = true;
}
return flag;
} catch (JRException exp) {
throw new HwSystemException(
"Exception in exporting report to printer", exp);
}
}
}
---------- END SOURCE ----------
FREQUENCY : always