codelibs/elasticsearch-dataformat

Unable to export xlsx

martinszy opened this issue ยท 6 comments

Hello, I'm testing this extension and it seems promising. Thanks.

Exporting in csv and xls works, but xlsx I get an error in the logs:

Elastic 7.9.2 and dataformat 7.9.0

fatal error in thread [elasticsearch[es-cluster-0][search][T#2]], exiting
{"type": "server", "timestamp": "2020-10-20T18:10:07,413Z", "level": "ERROR", "component": "o.e.b.ElasticsearchUncaughtExceptionHandler", "cluster.name": "es-poppins", "node.name": "es-cluster-0", "message": "fatal error in thread [elasticsearch[es-cluster-0][search][T#2]], exiting", "cluster.uuid": "PRm5aemyT4u-odNtaZ9dsA", "node.id": "lJDDSUbyRMmMAuJ41EBkPQ" , 
"stacktrace": ["java.lang.InternalError: java.lang.reflect.InvocationTargetException",
"at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86) ~[?:?]",
"at java.security.AccessController.doPrivileged(AccessController.java:312) ~[?:?]",
"at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) ~[?:?]",
"at java.awt.Font.getFont2D(Font.java:497) ~[?:?]",
"at java.awt.Font.canDisplayUpTo(Font.java:2244) ~[?:?]",
"at java.awt.font.TextLayout.singleFont(TextLayout.java:469) ~[?:?]",
"at java.awt.font.TextLayout.<init>(TextLayout.java:530) ~[?:?]",
"at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273) ~[?:?]",
"at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117) ~[?:?]",
"at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:82) ~[?:?]",
"at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684) ~[?:?]",
"at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:676) ~[?:?]",
"at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:88) ~[?:?]",
"at org.codelibs.elasticsearch.df.content.xls.XlsContent$OnLoadListener.lambda$new$1(XlsContent.java:122) ~[?:?]",
"at java.security.AccessController.doPrivileged(AccessController.java:312) ~[?:?]",
"at org.codelibs.elasticsearch.df.content.xls.XlsContent$OnLoadListener.<init>(XlsContent.java:122) ~[?:?]",
"at org.codelibs.elasticsearch.df.content.xls.XlsContent.write(XlsContent.java:91) ~[?:?]",
"at org.codelibs.elasticsearch.df.rest.RestDataAction$SearchResponseListener.onResponse(RestDataAction.java:173) ~[?:?]",
"at org.codelibs.elasticsearch.df.rest.RestDataAction$SearchResponseListener.onResponse(RestDataAction.java:137) ~[?:?]",
"at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:89) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:83) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.support.ContextPreservingActionListener.onResponse(ContextPreservingActionListener.java:43) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.AbstractSearchAsyncAction.sendSearchResponse(AbstractSearchAsyncAction.java:545) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.ExpandSearchPhase.run(ExpandSearchPhase.java:117) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.AbstractSearchAsyncAction.executePhase(AbstractSearchAsyncAction.java:350) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:344) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.FetchSearchPhase.moveToNextPhase(FetchSearchPhase.java:231) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.FetchSearchPhase.lambda$innerRun$1(FetchSearchPhase.java:119) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:125) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.FetchSearchPhase.access$000(FetchSearchPhase.java:47) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:95) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:44) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:737) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.9.2.jar:7.9.2]",
"at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[?:?]",
"at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[?:?]",
"at java.lang.Thread.run(Thread.java:832) [?:?]",
"Caused by: java.lang.reflect.InvocationTargetException",
"at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]",
"at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64) ~[?:?]",
"at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]",
"at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]",
"at java.lang.reflect.Constructor.newInstance(Constructor.java:481) ~[?:?]",
"at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84) ~[?:?]",
"... 37 more",
"Caused by: java.lang.NullPointerException: Cannot load from short array because \"sun.awt.FontConfiguration.head\" is null",
"at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262) ~[?:?]",
"at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225) ~[?:?]",
"at sun.awt.FontConfiguration.init(FontConfiguration.java:107) ~[?:?]",
"at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:718) ~[?:?]",
"at sun.font.SunFontManager$2.run(SunFontManager.java:352) ~[?:?]",
"at sun.font.SunFontManager$2.run(SunFontManager.java:309) ~[?:?]",
"at java.security.AccessController.doPrivileged(AccessController.java:312) ~[?:?]",
"at sun.font.SunFontManager.<init>(SunFontManager.java:309) ~[?:?]",
"at sun.awt.FcFontManager.<init>(FcFontManager.java:35) ~[?:?]",
"at sun.awt.X11FontManager.<init>(X11FontManager.java:56) ~[?:?]",
"at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]",
"at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64) ~[?:?]",
"at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]",
"at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]",
"at java.lang.reflect.Constructor.newInstance(Constructor.java:481) ~[?:?]",
"at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84) ~[?:?]",
"... 37 more"] }
java.lang.InternalError: java.lang.reflect.InvocationTargetException
	at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
	at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at java.desktop/java.awt.Font.getFont2D(Font.java:497)
	at java.desktop/java.awt.Font.canDisplayUpTo(Font.java:2244)
	at java.desktop/java.awt.font.TextLayout.singleFont(TextLayout.java:469)
	at java.desktop/java.awt.font.TextLayout.<init>(TextLayout.java:530)
	at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
	at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
	at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:82)
	at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)
	at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:676)
	at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:88)
	at org.codelibs.elasticsearch.df.content.xls.XlsContent$OnLoadListener.lambda$new$1(XlsContent.java:122)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
	at org.codelibs.elasticsearch.df.content.xls.XlsContent$OnLoadListener.<init>(XlsContent.java:122)
	at org.codelibs.elasticsearch.df.content.xls.XlsContent.write(XlsContent.java:91)
	at org.codelibs.elasticsearch.df.rest.RestDataAction$SearchResponseListener.onResponse(RestDataAction.java:173)
	at org.codelibs.elasticsearch.df.rest.RestDataAction$SearchResponseListener.onResponse(RestDataAction.java:137)
	at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:89)
	at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:83)
	at org.elasticsearch.action.support.ContextPreservingActionListener.onResponse(ContextPreservingActionListener.java:43)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.sendSearchResponse(AbstractSearchAsyncAction.java:545)
	at org.elasticsearch.action.search.ExpandSearchPhase.run(ExpandSearchPhase.java:117)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.executePhase(AbstractSearchAsyncAction.java:350)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:344)
	at org.elasticsearch.action.search.FetchSearchPhase.moveToNextPhase(FetchSearchPhase.java:231)
	at org.elasticsearch.action.search.FetchSearchPhase.lambda$innerRun$1(FetchSearchPhase.java:119)
	at org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:125)
	at org.elasticsearch.action.search.FetchSearchPhase.access$000(FetchSearchPhase.java:47)
	at org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:95)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:44)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:737)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
	... 37 more
Caused by: java.lang.NullPointerException: Cannot load from short array because "sun.awt.FontConfiguration.head" is null
	at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
	at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
	at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
	at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:718)
	at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:352)
	at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:309)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
	at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:309)
	at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
	at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
	... 43 more

What is JDK and version?

This was on 7.9.2, official docker version, I don't know the JDK version.

@martinszy A drive-by tip, but I had similar issues with OpenJDK 15 and Apache POI. Adding the required libraries as documented here fixed it for me: https://blog.adoptopenjdk.net/2021/01/prerequisites-for-font-support-in-adoptopenjdk/.

By installing the fonts on the server it does generate an xlsx file. I'm stil having issues opening the file, I guess it's an encoding issue.

The line in my Dockerfile is:

#Install fonts for dataformat xlsx export
RUN yum install -y freetype fontconfig dejavu-sans-fonts

I will update this issue.

Files seem to be corrupted, I don't know why. For instance the xlsx file shows this message when I try to unzip it

$ unzip test.xlsx
Archive:  test.xlsx
error [test.xlsx]:  missing 868049901 bytes in zipfile
  (attempting to process anyway)
error [test.xlsx]:  start of central directory not found;
  zipfile corrupt.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

Any idea what could be causing this?

I tried using charset=binary in the headers to no avail.

These are my headers, according to curl:

HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, X-Requested-With
Access-Control-Allow-Methods: GET, OPTIONS
content-type: application/octet-stream; charset=binary
content-disposition: attachment; filename="test.xlsx"
Date: Wed, 24 Mar 2021 22:15:05 GMT
Connection: keep-alive
Transfer-Encoding: chunked

BTW, I'm accessing elastic through exegesis-express https://github.com/exegesis-js/exegesis/

I have confirmed that the extension produces good xlsx files, it's during the transit via either the nodejs es client or exegesis that they get corrupted. I don't know if it's a problem on their side not supporting binary files or what.

I will report the issue elsewhere, please don't close.