any thoughts on this, works fine in CF 2021, fail...
# lucee
c
any thoughts on this, works fine in CF 2021, fails in Lucee 5.3.8/5.3.9. The init method is failing on passing in fileReader.
Copy code
csvFile ="#expandPath('.')#/csv_data/addresses.csv";
    csvData = [];

    fileReader = createobject("java","java.io.FileReader").init(csvFile);

    writeDump(fileReader);
 
    csvReader = createObject("java","com.opencsv.CSVReader").init(fileReader);
    writeDump(csvReader);
    csvData = csvReader.readAll();
    writeDump(csvData);
b
What's the full stack trace?
@cwigginton
"failing" could mean a lot of things 🙂
c
I still have to look at the stack trace. It's the constructor method. FileReader is a child of Reader class. This is a dump of CSVReader without a contructor creation. It's not accepting FileReader in Lucee. Basically says class not found with the constructor.
b
I'm not sure what you're trying to say, but none of it matters without the stack trace, lol
That's the first piece of information required to be able to help you
c
Ok, It's because Lucee doesn't have org.apache.commons.lang3.ObjectUtils and CF does.
lucee.runtime.exp.NativeException: org/apache/commons/lang3/ObjectUtils at com.opencsv.CSVParser.<init>(CSVParser.java:99) at com.opencsv.CSVReader.<init>(CSVReader.java:99) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at lucee.runtime.reflection.pairs.ConstructorInstance.invoke(ConstructorInstance.java:53) at lucee.runtime.reflection.Reflector.callConstructor(Reflector.java:832) at lucee.runtime.java.JavaObject.init(JavaObject.java:331) at lucee.runtime.java.JavaObject.call(JavaObject.java:256) at lucee.runtime.java.JavaObject.call(JavaObject.java:292) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1762) at index_cfm$cf$1.call(/index.cfm:28) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1043) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:935) at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:65) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:45) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2475) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2465) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2436) at lucee.runtime.engine.Request.exe(Request.java:45) at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1194) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1140) at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97) at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:590) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) at org.cfmlprojects.regexpathinfofilter.RegexPathInfoFilter.doFilter(RegexPathInfoFilter.java:47) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at runwar.Server$1.handleRequest(Server.java:510) at io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:280) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:260) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1423) at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils ... 66 more Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.ObjectUtils at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source)
b
Right, I don't know what
org.apache.commons.lang3.ObjectUtils
is, but it must ship in the default classloader of ACF, but not be a part of Lucee
if you can drop in that jar, you may be good
c
yeah, thinking on that.
c
If you just want to read a CSV in a cross-engine compat way, this might save you some bother: https://github.com/cfsimplicity/spreadsheet-cfml/wiki/csvToQuery
👍 1
c
openCSV has some nice support for conversion. I was answering someone's question on FaceBook ColdFusion and was going to give an example and decided to test it on lucee. What's nice is it automatically handles qualified strings that have comma's. like so
b
From the examples, the spreadsheet-cfml library also supports quoted values
c
Just looked at that. It has a java piece using apache POI to work with MS XML formats and which I'm pretty familiar with since I took ownership of Ben's POI Utility when I upgraded it for xlsx and other new features. The utility is still a little long on the tooth and could probably use a better design, but I wanted to keep it backward compatible. opencsv has a lot of other features as well if you're mostly into ETL.
e
Why even bother with using another library, you do not need it to create a CSV file. <cfheader name="Content-Disposition" value="inline; filename=SELECTED #DateFormat(Now(), "mm/dd/yyyy")#.csv"> (or you could use .xls, it will complain but open anyways) <cfcontent type="application/vnd.mcel"> <table border="2"> <tr> <td>Header1</td> <td>Header2</td> <td>Header3</td> </tr> <cfloop query="qryYourCrap"><tr> <td>#qryyourCrap.1#</td> <td>#qryyourCrap.2#</td> <td>#qryyourCrap.3#</td></tr></cfloop></table></cfcontent>
That sample BTW is for CSV file that will open in Excel. You could just use Commas, and create a true CSV file, or your tab Stops to create a delimited file.