Unable to create sheet when using SXSSFWorkbook in docker with apache poi - apache-poi

When executing following code in docker context, the page just hangs and I do not get any exceptions either:
File file = fileService.createTempFile('some-file.xlsx')
log.info("CREATED EXCEL FILE : ${file.path}")
Workbook workbook = new SXSSFWorkbook(SXSSFWorkbook.DEFAULT_WINDOW_SIZE)
log.info("WORKBOOK CREATED")
workbook.createSheet(WorkbookUtil.createSafeSheetName('TEST'))
log.info("SHEET CREATED")
FileOutputStream fos = new FileOutputStream(file)
workbook.write(fos)
//workbook.dispose()
fos.close()
I can see the file is craeted and also see WORKBOOK CREATED log generated but nothing after that.
This happens only when running the code in the docker container and not when I run the app outside of docker context.
I am using poi 4.1.2 and jdk 11.0.16.
UPDATE:
I have read on other posts about the temp directory not existing or not being writable. Just to test this out, I went to the node and created pre-defined folder with all read write permissions as well and updated the code to point SXXF to write to that temp folder as well :
try {
//THIS FOLDER ALREADY EXISTS IN NODE AND HAS ALL PERMS
String path = '/usr/local/tomcat/temp/reporting-service-16769203353988068118/'
File tmpdir = new File(path)
log.info("TMP DIR IS ${tmpdir.path}")
File file = new File("${tmpdir.path}/surveyQuestionExport.xlsx")
log.info("CREATED EXCEL FILE : ${file.path}")
TempFile.setTempFileCreationStrategy(new DefaultTempFileCreationStrategy(tmpdir))
Workbook workbook = new SXSSFWorkbook(new XSSFWorkbook(), SXSSFWorkbook.DEFAULT_WINDOW_SIZE)
log.info("WORKBOOK CREATED")
workbook.createSheet(WorkbookUtil.createSafeSheetName('TEST'))
log.info("SHEET CREATED")
FileOutputStream fos = new FileOutputStream(file)
workbook.write(fos)
workbook.dispose()
fos.flush()
fos.close()
return file
} catch (Exception ex) {
log.error("EXPORT FAILED", ex)
}
But still same issue.

Related

How to handle windows pop up to upload a file in Linux machine using selenium script

I am trying to automate a windows popup for file upload in selenium and want to trigger the script on LINUX.
There are tools like autoIT, JACOB which can handle these kinda pop-ups, but these doesn't work on LINUX directly.
I need help in any tool which does the job.
I have tried AutoIT, but due to autoIt exe not able to run the code on linux.
Then I tried JACOB but to use jacob needs to save two .dll files and did some exploration and found out taht Linux doen't support .dll it supports .so and as i am very new to linux don't have ides how to perform this.
private void fileUploadData(String fileName) {
String workingDir = "";
AutoItX uploadWindow = new AutoItX();;
try {
workingDir = System.getProperty("user.dir");
final String jacobdllarch =
System.getProperty("sun.arch.data.model")
.contains("32") ? "jacob-1.18-x86.dll" : "jacob-1.18-x64.dll";
String jacobdllpath = workingDir + "/" + jacobdllarch;
File filejacob = new File(jacobdllpath);
System.setProperty(LibraryLoader.JACOB_DLL_PATH,
filejacob+System.getProperty("user.dir"));
}
catch(Exception e) {
e.printStackTrace();
}
String filepath = workingDir + "\\src\\test\\resources\\testdata\\" +
fileName ;
File file=new File(filepath);
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
browseButton.click();
uploadWindow.winActive( "File Upload", "" );
uploadWindow.sleep(2000);
uploadWindow.ControlSetText( "Open", "", "Edit1", filepath);
uploadWindow.controlClick( "", "", "&Open" );
}
Getting below error on LINUX code is working fine on Windows -
Unsatisfied link error: no jacob-1.18-x64 in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]

Android.Write file to sdcard

I know this question was asked hundred times but for some reason accepted answers don't work for me.
I can write to device internal memory with this code:
File root = context.getExternalFilesDir(null);
root = new File(root, DATA_FOLDER);
if (!root.exists())
root.mkdir();
File pack = new File(root, "pack???");
if (!pack.exists())
pack.mkdir();
File progress = new File(pack, "save.dat");
try {
progress.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//write file goes here
I can see folder structure in the app's folder
However if I change root to
File root=Environment.getExternalStorageDirectory();
no folders on the sdcard are created.Also I tried with this code:
File progress = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!progress.exists()) {
progress.mkdir();
}
No success as well.
Manifest contains permission
android.permission.WRITE_EXTERNAL_STORAGE
UPD:Actually the last code does create new folder but this folder is in internal memory while I need it to be on sdcard

XMLDocument.Load() Does not load the file while running test project

I have a test case which validates an XML file.
When using VS2010 with .Net 3.5 framework, the below code works perfectly fine, i am able to load the XML file. My file is location is Source folder of the application.
XmlDocument doc = new XmlDocument();
try
{
doc.Load("Terms_and_Conditions.xml");
XmlNode node;
XmlElement root = doc.DocumentElement;
//Select and display the value of the element.
node = root.SelectSingleNode(NodeSelection);
return node.InnerText;
}
catch (Exception ex)
{
throw ex;
}
Solution Folder:
When I run the same code in .Net 4.6.1, file path resolves to
C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Terms_and_Conditions.xml
Anyone have an idea why this issue with .Net 4.6.1
This happens because your unit tests run in the test runner, which is located in the Common7 folder and not in your projects bin folder. Since you specify a relative path to the xml file, the program will look for the file in the current folder, which is the Common7 folder.
Thanks everyone for the quick help.
Here is how I solved the problem with above link.
XmlDocument doc = new XmlDocument();
try
{
var path = System.IO.Directory.GetParent(System.IO.Directory.GetParent(TestContext.CurrentContext.TestDirectory).ToString());
doc.Load("Terms_and_Conditions.xml");
XmlNode node;
XmlElement root = doc.DocumentElement;
//Select and display the value of the element.
node = root.SelectSingleNode(NodeSelection);
return node.InnerText;
}
catch (Exception ex)
{
throw ex;
}

File server to SharePoint Online: folder to document library structure diff tool?

Do you know if there is any kind of tool (it would be cool if it is for free) that compares the file structure of a folder in a File Server to a SharePoint Online Document Library and tells you the difference?
The point is we are getting hands on a partially migrated File Server to SharePoint Online and the migration status of some folders is unknown to us. We already have a 3rd party migration tool to finish the migration but we need to know what is still pending to be uploaded. Any idea?
Thanks in advance.
We use sharegate for our migration. In your situation I might just run migrations on small sections with it set to "skip existing". That doesn't directly answer your question though.
In your case I would map both the File server and the SharePoint online instance as drives on a computer (using WebDAV) and hack together an app in your favorite language to compare the two directory structures.
Here is a java program that does that:
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class Launcher {
static PrintWriter fileOut;
public static void main(String[] args) throws IOException {
File fileStore = new File("N:\\"); //filestore dir top level
File sp = new File("M:\\");//sp directory top level (mapped)
File out = new File("C:\\Temp\\results.txt");
fileOut = new PrintWriter(out);
recurse(fileStore, sp);
fileOut.close();
}
private static void recurse(File dir1, File dir2)
{
File [] dirFiles;
if(dir2 == null)
dirFiles = new File[0];
else
dirFiles=dir2.listFiles();
File match;
for(File f1 : dir1.listFiles())
{
System.out.println(f1.getAbsolutePath());
match=null;
for(File f2:dirFiles)
if(f1.getName().equalsIgnoreCase(f2.getName()))
match=f2;
if(f1.isDirectory() && f1.canRead())
try{
recurse(f1,match);
}
catch(Exception e){}
else if (match == null)
fileOut.write(f1.getAbsolutePath()+"\r\n");
}
}
}
It writes to the given text file each file that is not in the 2nd directory structure.
You could run this code in an IDE like eclipse.

Write to file via jenkins post-groovy script on slave

I'd like to do something very simple: Create/write to a file located in the remote workspace of a slave via the jenkins groovy post-build script plug-in
def props_file = new File(manager.build.workspace.getRemote() + "/temp/module.properties")
def build_num = manager.build.buildVariables.get("MODULE_BUILD_NUMBER").toInteger()
def build_props = new Properties()
build_props["build.number"] = build_num
props_file.withOutputStream { p ->
build_props.store(p, null)
}
The last line fails, as the file doesn't exist. I'm thinking it has something to do with the output stream pointing to the master executor, rather than the remote workspace, but I'm not sure:
Groovy script failed:
java.io.FileNotFoundException: /views/build_view/temp/module.properties (No such file or directory)
Am I not writing to the file correctly?
While writing onto slave you need to check the channel first and then you can successfully create a file handle and start reading or writing to that file:
if(manager.build.workspace.isRemote())
{
channel = manager.build.workspace.channel;
}
fp = new hudson.FilePath(channel, manager.build.workspace.toString() + "\\test.properties")
if(fp != null)
{
String str = "test";
fp.write(str, null); //writing to file
versionString = fp.readToString(); //reading from file
}
hope this helps!
Search for words The post build plugin runs on the manager and doing it as you say will fail if you are working with slaves! on the plugin page (the link to which you've provided) and see if the workaround there helps.
Does the folder /views/build_view/temp exist?
If not, you will need to do new File( "${manager.build.workspace.remote}/temp" ).mkdirs()

Resources