Jump to content
We've recently updated our Privacy Statement, available here ×

Invalid name of PrintService


stdi

Recommended Posts

Hello,

i have wrapped my JasperReports based printing Software as a Windows Service some weeks ago. I am using Apache Procrun to invoke the Main Loop. Apache Procrun gives the Option to run in "JRE mode" where Procrun has Access to the running runtime Environment to call Service Methods for Service Controls like "start", "stop" and "restart". We have put our formerly directly started main Loop into a Singleton Object that is called asynchronously from Procrun to signal Events to the running Main Loop.

The first experiments went very well. Now, where i am installing the Software on a different Machine, I am experiencing a strange behaviour: Whenever I start the Software as a Service, the JRPrintSerciceExporter.exportReport()-Method throws the following Exception:

net.sf.jasperreports.engine.JRException: java.awt.print.PrinterException: Invalid name of PrintService.
        at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:159)
        [...]
Caused by: java.awt.print.PrinterException: Invalid name of PrintService.
        at sun.awt.windows.WPrinterJob.setNativePrintService(Native Method)
        at sun.awt.windows.WPrinterJob.setPrintService(Unknown Source)
        at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:155)

There seem to be problems with the underlying AWT Print System whenever I start my Software as a Service. When I call exactly the same Functions from within Main, there aren't any Exceptions. Once, the Code is wrapped into a separate Thread, the Exception appears. I have tried different -Xms and -Xmx setttings because I have read about memory leak issues in http://bugs.sun.com/view_bug.do?bug_id=6445576, with no success.

The Code where the Exception appears is like the following:

 PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
 JRPrintServiceExporter exporter = new JRPrintServiceExporter();
 exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
 exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[druckerNr]);
 exporter.exportReport();

(druckerNr was evaluated before and set correctly. My Log-Output assure, that an existing Printservice was selected.)

Does anyone know how to fix this? I definately have to run my Software as a Service. Please make no Suggestions like "try XY to wrap your Software as a Service" or "I Guess it is an Apache Procrun issue" unless you exactly know what the problem is. I expect the Problem to be more general. Are there any known Bugs that deal with AWT printing and Jasperreports? In an other Thread at the Java Forums (http://forums.sun.com/thread.jspa?threadID=5240907)  i read  that

 PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat page = printerJob.defaultPage();
if (printerJob.printDialog()) {
...

could be helpful.

SO I PATCHED JRPrintServiceExporter of JasperReports 3.7.2 at Line 155:

try  {
printerJob.defaultPage();
System.out.println(printService.getName());

printerJob.setPrintService(printService);
}
catch (PrinterException e)
{
    throw new JRException(e);
}

It had no effect. The PrintService Name is ok. I am currently using JasperReports 3.7.2. Whatsoever: Whenever the Code is Executed from whithin Main, the Problem doesn't appear. When I wrap the Code into a separate Thread, it doesn't work on SOME machines. On others, it does. For example It works fine on a Windows Server 2008 Machine. On an other Windows Server 2003 Machine, it doesn't work. Both Machines were using JRE 1.6.0_15. I tried JRE 1.6.0_21x64 - same behaviour, no success.

Do you have any useful hints?

Greetings,

Stefan



Post Edited by stdi at 2010-08-30 14:23
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello again,

I tried different things, without success.

I assume that my problems are related to

Bug ID: 6446094 Win32PrintServiceLookup.getPrintServiceByName() should not recreate duplicate instances.

My Operating System is: Windows Server 2003 Enterprise x64 Edition, Service Pack 2

My initial Java version was JRE6_u21 -> didn't work.

In JDK7 the Java BUG 6446094 is solved, so I tried to run Apache Procrun with jdk-7-ea-bin-b107-windows-x64-26_aug_2010.exe.

Unfortunately I can't get Procrun working with this beta JDK, because there seems to be missing a File. Apache Procrun makes use of jvm.dll to invoke the jvm. In older JRE versions there is a folder JAVA_HOME/bin/client/jvm.dll, in JRE7 there is only JAVA_HOME/bin/server/jvm.dll

Has anyone got Apache Procrun working with JRE7 in jvm mode?

What is the difference between "client/jvm.dll" and "server/jvm.dll" ?

 

Stefan

 



Post Edited by stdi at 2010-08-31 11:01
Link to comment
Share on other sites

Hi,

my problems seem to depend on bad Windows user rights settings. Friday I got an identical Problem on a Windows Server 2007 Machine that already served my Service very well. I had installed the same Service a second time to Run with a different user account on that machine. Suddenly it didn't work with that users settings. After changing the User in  the "run as"- settings of my service to the User it already worked with, the "Invalid name of PrintService" Exceptions disappeared.

In the end it seems like my problems are related to wrong  user account settings. There are serveral Rights that have got to be discussed.

Are there any Issues related to Windows User Rights and JasperReports?

 

Please let me know!

stdi

 

 

 

 

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...