Service Virtualization

  • 1.  Read excel file using apache poi code not working in Execute JSR-223 step

    Posted Jul 17, 2018 07:17 AM

    Hi,

     

    I am trying to read excel file using java code in Execute JSR---223 step but getting below error -

     

     

    ============================================================================
    | Error in Script
    ============================================================================
    | Step: Execute script (JSR-223)~1
    ----------------------------------------------------------------------------
    | Message: bsh.TargetError: Sourced file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : Object constructor : at Line: 14 : in file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : new XSSFWorkbook ( fin )

    Target exception: java.lang.IllegalArgumentException: 'path' must be given
    in inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' at line number 14
    ----------------------------------------------------------------------------
    | Trapped Exception: bsh.TargetError: Sourced file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : Object constructor : at Line: 14 : in file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : new XSSFWorkbook ( fin )

    Target exception: java.lang.IllegalArgumentException: 'path' must be given
    in inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' at line number 14
    | Trapped Message: javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : Object constructor : at Line: 14 : in file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : new XSSFWorkbook ( fin )

    Target exception: java.lang.IllegalArgumentException: 'path' must be given
    in inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' at line number 14
    ----------------------------------------------------------------------------
    STACK TRACE
    javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : Object constructor : at Line: 14 : in file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' : new XSSFWorkbook ( fin )

    Target exception: java.lang.IllegalArgumentException: 'path' must be given
    in inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermod . . . '' at line number 14
    at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:97)
    at bsh.BshScriptEngine.eval(BshScriptEngine.java:61)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:674)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:427)
    at com.itko.lisa.test.UserScriptNode._execute(UserScriptNode.java:210)
    at com.itko.lisa.editor.UserScriptNodeEditor.execute(UserScriptNodeEditor.java:214)
    at com.itko.lisa.editor.UserScriptNodeEditor.access$000(UserScriptNodeEditor.java:49)
    at com.itko.lisa.editor.UserScriptNodeEditor$1.actionPerformed(UserScriptNodeEditor.java:73)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6533)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
    Caused by: java.lang.IllegalArgumentException: 'path' must be given
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:220)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:188)
    at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:85)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:319)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at bsh.Reflect.constructObject(Reflect.java:575)
    at bsh.BSHAllocationExpression.constructObject(BSHAllocationExpression.java:125)
    at bsh.BSHAllocationExpression.objectAllocation(BSHAllocationExpression.java:114)
    at bsh.BSHAllocationExpression.eval(BSHAllocationExpression.java:62)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
    at bsh.BSHAssignment.eval(BSHAssignment.java:77)
    at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
    at bsh.BSHBlock.eval(BSHBlock.java:80)
    at bsh.BSHBlock.eval(BSHBlock.java:46)
    at bsh.BSHTryStatement.eval(BSHTryStatement.java:88)
    at bsh.Interpreter.eval(Interpreter.java:664)
    at bsh.Interpreter.eval(Interpreter.java:758)
    at bsh.Interpreter.eval(Interpreter.java:747)
    at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:89)
    ... 44 more
    ============================================================================

     

     

     

    Code is working fine in eclipse , can anyone help me on this ?



  • 2.  Re: Read excel file using apache poi code not working in Execute JSR-223 step

    Broadcom Employee
    Posted Jul 18, 2018 01:40 AM

    Hi,

     

    Could you please prepare these below?
    1. DevTest Version
    2. Test case or "Execute Script(JSR-223) step" which you tried
    3. Version of Apache POI in your eclipse environment

     

    Thank you,



  • 3.  Re: Read excel file using apache poi code not working in Execute JSR-223 step
    Best Answer

    Posted Jul 18, 2018 05:15 AM

    This exception is thrown in order to indicate that a method has been passed an illegal or inappropriate argument. Check exactly at line 14 new XSSFWorkbook ( fin ) . Something is wrong with code itself. I believe configurations are fine as per error thrown. I have done this long back but don't have code snippet with me . 

    Check if below helps 

    Read Write From Excel File 

    Writing Response to Excel File - LOG Utility 

     

    Hope this helps !