Jump to content
Changes to the Jaspersoft community edition download ×

HeadlessException when printing


wjones14

Recommended Posts

I use code like this to send a report to the printer:

 

JasperReport jasperReport = buildContent();

JasperPrint jasperPrint =

JasperFillManager.fillReport(jasperReport, data, new JREmptyDataSource());

JasperPrintManager.printReport(jasperPrint, true);

 

This code works fine on a PC with a local weblogic server instance running. It brings up a Windows print dialog and sends report to the default printer.

 

However, when the application is deployed on a remote Sun server with weblogic, I get this error:

 

net.sf.jasperreports.engine.JRException: Error printing report.

at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:200)

at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:88)

at net.sf.jasperreports.engine.JasperPrintManager.printPages(JasperPrintManager.java:348)

at net.sf.jasperreports.engine.JasperPrintManager.printReport(JasperPrintManager.java:239)

at com.pfizer.lynx.reports.ContainerLabelReportBean.printLabel(ContainerLabelReportBean.java:169)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)

at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)

at javax.faces.component.UICommand.broadcast(UICommand.java:106)

at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)

at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)

at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)

at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1072)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)

at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)

at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)

at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)

at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)

at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6987)

at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)

at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)

at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3892)

at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2766)

at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)

at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)

Caused by: java.awt.HeadlessException

at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:465)

at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:184)

... 29 more

 

 

Anyone know how to fix this?

 

 

Thanks,

 

Bill J.

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

I see now that JasperPrintManager is really not for printing on a remotely deployed web application. The packaged demo samples have a webapp that can print a report, using an applet.

 

We'd rather not use an applet if possible. Does anyone know another printing solution, for instance if we know the printer address of the logged-in user?

 

 

Thanks,

 

Bill J.

Link to comment
Share on other sites

Hi,

 

You could print to a specified network printer if you use the JRPrintServiceExporter as shown in the /demo/samples/printservice sample provided with the project.

With this exporter you can direct printer output to a network printer that you can locate by name or based on its printing capabilities using the Java Print Service API.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

Okay, using your example, I think the code is close now. It works on a local instance of Weblogic server, running on a PC hooked up to a Windows network. It brings up a javax.Swing print dialog.

 

However, it fails when deployed to a remote Sun server running Weblogic, with this exception:

 

net.sf.jasperreports.engine.JRException: No suitable print service found.

 

Here is the code:

 

JasperReport jasperReport = buildContent();

JasperPrint jasperPrint =

JasperFillManager.fillReport(jasperReport, data, new JREmptyDataSource());

// if local weblogic server, can directly use JasperPrintManager,

// but for remote weblogic must use JRPrintServerExporter

// JasperPrintManager.printReport(jasperPrint, true);

 

// code from the demo samples

long start = System.currentTimeMillis();

PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();

printRequestAttributeSet.add(MediaSizeName.ISO_A4);

 

String networkName = "\\grogrdprt10\MFD443";

PrinterName printerName = new PrinterName(networkName, null);

 

PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();

printServiceAttributeSet.add(printerName);

 

JRPrintServiceExporter exporter = new JRPrintServiceExporter();

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);

 

log.debug("Exporting report...");

exporter.exportReport();

log.debug(("Printing time : " + (System.currentTimeMillis() - start)));

 

 

Is the problem that the Unix system doesn't recognize the Windows network address?

 

Thanks for the help!

 

 

Bill J.

Link to comment
Share on other sites

  • 2 years later...

Hi everyone,

I tried to send a report to printer using this sample. It works,but the result is not what I wanted.

More specifically,I have a client-server web application and I want to send a report from a client to a printer that is connected with the client's local network.

Using this sample I get the PRINT DIALOG at the server machine , but I want it at the client's pc.

Can anyone help with this?

 

Thank you in advance,

Antonis.

Link to comment
Share on other sites

prezakis
Wrote:

Hi everyone, I tried to send a report to printer using this sample. It works,but the result is not what I wanted. More specifically,I have a client-server web application and I want to send a report from a client to a printer that is connected with the client's local network. Using this sample I get the PRINT DIALOG at the server machine , but I want it at the client's pc. Can anyone help with this? Thank you in advance, Antonis.

Any Java code that you put in an web application/servlet container will obviously run on the server machine.

If you want to run Java code on the client machines, use applets.

Regards,

Lucian

Link to comment
Share on other sites

  • 2 years later...

I know this is a grave dig, but I get the same exception.

 

My scenario is priting from a windows service (batch processor), running on Win2K8. The batch processor invokes a java applet to render documents and runs in headless mode. The command looks like:

java -cp %CLASSPATH% -Djava.awt.headless=true BuildReport4

The java code is almost identical to wjones14 and throws the same exception. Ironically however, the documents actually print!

Our exception points the finger towards java.awt as per:

net.sf.jasperreports.engine.JRException: Error printing report.
    at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:197)
    at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:84)
    at net.sf.jasperreports.engine.JasperPrintManager.printPages(JasperPrintManager.java:197)
    at net.sf.jasperreports.engine.JasperPrintManager.printReport(JasperPrintManager.java:88)
    at BuildReport4.sendToPrinter(BuildReport4.java:258)
    at BuildReport4.main(BuildReport4.java:162)
Caused by: java.awt.print.PrinterException: No print service found.
    at sun.print.RasterPrinterJob.print(Unknown Source)
    at sun.print.RasterPrinterJob.print(Unknown Source)
    at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:192)
    ... 5 more

 

Is this one of those double slash things to escape the slashs for the UNC printer queue name ? our printer queues are locally defined on the server machine itself which may help. However it still looks nasty with the exceptions.

 

Was there any eventual solution or work around to tidy this up ?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...