Bug 63346 - Xlsx corrupted on IBM server
Summary: Xlsx corrupted on IBM server
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-14 11:14 UTC by Alex
Modified: 2019-06-20 08:46 UTC (History)
0 users



Attachments
File corrupted (3.18 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2019-04-14 11:14 UTC, Alex
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2019-04-14 11:14:38 UTC
Created attachment 36526 [details]
File corrupted

On ibm server, the xlsx is corrupted. From back end string base 64 to Fe where is decode and downloaded in jsp
Comment 1 Andreas Beeker 2019-04-14 11:27:08 UTC
Please try with POI 4.1.0 first, usually we don't even try to find out, what the problem in old versions of POI were.

The corrupt file is a truncated zip (... .xlsx is a .zip) - without knowing the your webapp, my guess would be, you are closing the stream to the browser to early.

What you could try is to save the worksheet locally on the server. If this file is corrupt, it might be POIs problem (use 4.1.0!) ... if not, your servlet logic is faulty.
Comment 2 Alex 2019-04-14 11:34:48 UTC
In Back end:

ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
workbook.write(fileOut);		        
fileOut.flush();
 byte[] ba = fileOut.toByteArray();	
String encoded = DatatypeConverter.printBase64Binary(ba);
		        
fileOut.close();
workbook.close();		        
				
res.setJSonObject(encoded);
				
return res;
Comment 3 Andreas Beeker 2019-04-14 18:52:22 UTC
I see two issues here:

- you haven't reacted to what I've requested, i.e. saving to a file (instead of the ByteArrayOutputStream). This is just temporarily for testing, to assist in finding the problem. you can use the ByteArrayOutputStream.writeTo() method to forward to the FileOutputStream

- how do you handle a base64 encoded JSON String? when saving the file on client/browser side, this might lead to further errors. Is it really necessary to handle this in an AJAX call ... or can't you simply return a byte stream of content-type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
" and leave the handling to the browser?
Comment 4 Alex 2019-04-14 22:47:45 UTC
On Development server my code works. The problem is on IBM testing server where i have a corrupted xlsx. On IBM server I can only deploy the war on weblogic
On development server i also use weblogic . 

In Front End 

function base64ToArrayBuffer(base64) {
var binaryString = window.atob(base64);
var binaryLen = binaryString.length;
var bytes = new Uint8Array(binaryLen);
for (var i = 0; i < binaryLen; i++) {
   var ascii = binaryString.charCodeAt(i);
   bytes[i] = ascii;
}
return bytes;
}
Comment 5 Alex 2019-04-14 22:59:07 UTC
or can't you simply return a
> byte stream of content-type
> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
> " and leave the handling to the browser?


Sorry for my second message. I also tried to return a byte stream but i have the same problem. I made many attempts :( Thanks you so much and sorry for my english
Comment 6 Andreas Beeker 2019-04-15 05:49:47 UTC
Ok, let us ignore the AJAX client for now - we need to stay on the server first. You can write to a temp folder on the testing server.

For now I assume the file is invalid on the server.

The difference can be the loaded classes.

Please check the following for classpath issues:
https://stackoverflow.com/questions/4925901/classcastexception-while-parsing-xml-with-weblogic

Also try to set the classloader order to parent last:
https://stackoverflow.com/questions/31583968/how-to-specify-order-of-jar-class-loading-in-weblogic

IIRC you can activate a jar browser in the management console of weblogic to check for duplicated jars - please check that too.
Comment 7 Dominik Stadler 2019-06-20 08:46:57 UTC
I don't think this is really caused by Apache POI itself. If you still have this problem, please create a more isolated test-case which allows to see where the problem is actually happening.

As there was no response for some time we are closing this as INVALID for now. 

Please work on a more narrowed down test-case if you want us to continue investigation.