MarvinBeans: Problems with EMF and PDF in headless mode!

User c1f77e1011

14-12-2006 14:44:24

Hi,





we're using SuSe Linux Enterprise Server v9.3 with Java RE v1.5.0_05b and MarvinBeans v4.14. Our servlet converts mol files to other image formats and is runing on OC4J 10g (v10.1.3). There is no problem converting from mol to jpg, bmp, png, svg or ppm on Linux server as well as on my Windows XP workstation. Only if I want to use the emf- or pdf-export function from MarvinBeans, which uses the VectorGraphics package of FreeHEP Java Library, it works under Windows XP but our Linux server is sending me the following exception:





Exception in web browser:
Quote:
500 Internal Server Error





java.lang.NullPointerException


at chemaxon.marvin.modules.ImageExport.paint(Unknown Source)


at chemaxon.marvin.modules.VectGraphicsExport.convert(Unknown Source)


at chemaxon.struc.Molecule.exportToObject(Unknown Source)


at chemaxon.struc.Molecule.exportToObject(Unknown Source)


at chemaxon.struc.Molecule.exportToBinFormat(Unknown Source)


at chemaxon.struc.Molecule.toBinFormat(Unknown Source)


[...]
Exception in server console:
Quote:
java.lang.reflect.InvocationTargetException


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


at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)


at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)


at java.lang.reflect.Method.invoke(Unknown Source)


at chemaxon.marvin.modules.VectGraphicsExport.createGraphics(Unknown Source)


at chemaxon.marvin.modules.VectGraphicsExport.callback(Unknown Source)


at chemaxon.marvin.common.swing.ExportGraphics.getGraphics2D(Unknown Source)


at chemaxon.marvin.modules.VectGraphicsExport.convert(Unknown Source)


at chemaxon.struc.Molecule.exportToObject(Unknown Source)


at chemaxon.struc.Molecule.exportToObject(Unknown Source)


at chemaxon.struc.Molecule.exportToBinFormat(Unknown Source)


at chemaxon.struc.Molecule.toBinFormat(Unknown Source)


[...]





Caused by: java.awt.HeadlessException


at sun.awt.HeadlessToolkit.getScreenSize(Unknown Source)


at org.freehep.graphicsio.emf.EMFGraphics2D.writeHeader(EMFGraphics2D.java:162)


at org.freehep.graphicsio.AbstractVectorGraphicsIO.startExport(AbstractVectorGraphicsIO.java:186)


... 29 more





Error in the initalization of EMFGraphics2D:null
The Java VM on the Linux server is running in headless mode using the "-Djava.awt.headless=true" parameter. So I changed the parameter to "-Djava.awt.headless=false" and it worked on my Windows XP workstation but not on our Linux server because it has no X-Server. This exception is thrown when a mol file is converted to emf or pdf. The other image exports are not available at this time. I know the solution with Xvfb-Server but we can't run this product in our certified production environment.





The next step was PJA. The Pure Java AWT Toolkit is a Java library for drawing graphics developed by eTeks (http://www.eteks.com/pja/en/). It is 100% Pure Java and doesn't use any native graphics resource of the system on which the Java Virtual Machine runs. But there might be an incompatibility with Java v1.5.x:





Exception in web browser:
Quote:
500 Internal Server Error





java.lang.AbstractMethodError: sun.java2d.SunGraphicsEnvironment.createFontConfiguration()Lsun/awt/FontConfiguration;


at sun.java2d.SunGraphicsEnvironment$1.run(Unknown Source)


at java.security.AccessController.doPrivileged(Native Method)


at sun.java2d.SunGraphicsEnvironment.<init>(Unknown Source)


at com.eteks.java2d.PJAGraphicsEnvironment.<init>(PJAGraphicsEnvironment.java:66)


at com.eteks.java2d.PJABufferedImage.createGraphics(PJABufferedImage.java:112)


at java.awt.image.BufferedImage.getGraphics(Unknown Source)


at com.eteks.java2d.PJAGraphicsManager2D.getFontMetrics(PJAGraphicsManager2D.java:86)


at com.eteks.awt.PJAToolkit.getFontMetrics(PJAToolkit.java:551)


at sun.awt.HeadlessToolkit.getFontMetrics(Unknown Source)


at chemaxon.marvin.util.MolPainter.calcBounds(Unknown Source)


at chemaxon.marvin.util.MolPainter.setBoundsFor(Unknown Source)


at chemaxon.marvin.util.MolPainter.setBoundsFor(Unknown Source)


at chemaxon.marvin.modules.ImageExport.initPainter(Unknown Source)


at chemaxon.marvin.modules.VectGraphicsExport.convert(Unknown Source)


at chemaxon.struc.Molecule.exportToObject(Unknown Source)


at chemaxon.struc.Molecule.exportToObject(Unknown Source)


at chemaxon.struc.Molecule.exportToBinFormat(Unknown Source)


at chemaxon.struc.Molecule.toBinFormat(Unknown Source)


[...]
I has found another solution directly from FreeHep (http://forum.freehep.org/index.php?t=msg&goto=677&rid=0&S=620411d4c43ea67ede90ad80c77b9ef8&srch=headless)


but I use the MarvinBean interface to convert image formats.





I use this code to convert a mol file to emf:





Code:
mol.toBinFormat("emf:w200h100");






Is there a mistake using the "toBinFormat" method or have you other ideas which would solve this problem?





Thanks


Tobias





P.S.: The application has to go live within 2006 :)

ChemAxon 7c2d26e5cf

14-12-2006 18:52:30

Hi Tobias,


You see the problem correctly.


As I know, Freehep - generally - expects a graphical component to use its graphics object for drawing.


In MolConverter, there is not any (displayable) component for it. Because of it, we use directly the


org.freehep.graphicsio.pdf.PDFGraphics2D class for PDF export. (EMF export is similar.):


Code:
OutputStream out = ...


Dimension d = ...


PDFGraphics2D vg2 = new PDFGraphics2D(out, d);


vg2.startExport();


paint(vg2); // Marvin paints the structure to the specified graphics


vg2.endExport();


byte[] data = out.toByteArray(); // the PDF output



Currently, I don't know how to solve this issue but we will take a research to solve it.


If you have got some experience in Freehep API and you have got any idea, we would be pleasure to share it.

ChemAxon 7c2d26e5cf

28-12-2006 15:07:27

Hi Tobias,


I have found a workaround to the HeadlessException by EMF creating.


EMF/PDFGraphics2D should be in device independent mode: org.freehep.graphics2d.VectorGraphics.setDeviceIndependent(true)


Code:
OutputStream out = ...


Dimension d = ...


PDFGraphics2D vg2 = new PDFGraphics2D(out, d);


vg2.setDeviceIndependent(true);


vg2.startExport();


paint(vg2); // Marvin paints the structure to the specified graphics


vg2.endExport();


byte[] data = out.toByteArray(); // the PDF output



If the graphics is device independent, Freehep API will not throw exception in headless mode.


I've inserted this workaround in the code of EMF/PDF export of Marvin.


Thus, in the next Marvin release (4.1.5), EMF and PDF creating are going to work in headless mode (with or without X server).

User c1f77e1011

22-02-2007 09:35:15

Hi Tamas,





thanks for fixing our problem with generating EMF- and PDF-files in headless


mode and especially for building a test release on 29th December 2006. It


was the right decision using your product.





Kind regards


Tobias