Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to create a Custom Response using Scripting option in Parasoft?

Hi , I am new to Parasoft. I want knowledge on how to create a "Custome Response" using Scripting. I see the tool is having an option "Scripted" in the Response Tab--> Input Mode to generate a Response by writing code using Java or a Groovy or some other language mentioned.

If someone can provide me a small example or a Case Study or a Tutorial it will be great and it will help me a lot. Thanks in Advance. You can share me a link here or can send me a mail over to my Personal Mail Id: avinash246891@gmail.com

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    If someone can provide me a small example

    Like this?

    Groovy:

    import com.parasoft.api.*
    
    String foo(ScriptingContext context) {
        return "hello world"
    }
    

    Jython:

    from com.parasoft.api import *
    
    def foo(context):
        return "hello world"
    

    Also see:
    Extensibility and Scripting Basics

  • AvinashPanditi
    AvinashPanditi Posts: 32
    edited December 2019

    Hi Benken, Thanks for the response. I have written a java code which will generate an XML message as output. I have made a Jar file with the code and added the Jar file to the class path by clicking on the "Modify Classpath" in the "Response Tab". When i tested i could see the below error in the Events Log. Please help me with this issue. I have tested this by deploying the Virtual Service to "Parasoft Server". Should i need to place this jar file to "Parasoft Server".

    Test Name: 1. JSON Message Responder
    Source: JSON Message Responder
    Message: com.parasoft.api.UserMethodException: CreateXML

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    When you say Parasoft Server do you mean the "local" server in your desktop? Or a remote server hosted somewhere else? If the server is not the "local" server in your desktop then yes you will need to add the jar to its class path.

    To make it easier to deploy your asset without needing the extra jar you could try using the Groovy scripting language. You can probably almost use the same code from your Java jar in groovy with a few minor changes.

  • Hi William, Thanks for the reply. I am testing the Virtual Service by deploying the to remote server. Is there a way to add the class file instead of Jar, since I am comfort with Java coding. Is there a way along with the Virtual Service deployment we can add the jar or a class file to the remote server.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    There isn't a way that I know of to deploy just the class file. To deploy the jar file to the remote server upload it into the remote servers "Virtual Assets" project into a folder named "system_jars"

    After the jar file is uploaded (and before the virtual asset is deployed) you should trigger the rest api resource that reloads the "System Properties" which will load your uploaded jar file.

    curl -X POST -O http://timewarp:9080/soavirt/api/v6/preferences/systemProperties/reload

    Then you can upload your virtual asset and it should load your custom code from the jar file.

    Api documentation
    http://:/soavirt/api#!/preferences/preferencesPOST_systemProperties_reload

    Section titled "Adding Jar Files in Bulk and in Headless Instances"
    https://docs.parasoft.com/pages/viewpage.action?pageId=41304609

  • Thanks Will for the info. I checked the Parasoft tool --> "Virtual Server" section and i don't see an option to upload the jar file to the Parasoft remote server. I could see a folder "system_jars", i don't see an option to upload jar file.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    In the server view expand the "Files" or "Workspace Files" under the remote server. Expand the tree until you see the "system_jars" folder. Then drag the jar file from you local workspace and drop it into the "system_jars" folder.

  • I dragged the Jar file but its not getting copied to system_jars folder under "Workspace Files" folder. I am doing this to the Remote Server view which is visible in the tools "Virtual Server" section (Middile Right corner of tool)

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    Are you dragging from the Navigator view to the Virtualize Server view? It works when I do that. Make sure you're not accidentally dropping it onto the folder under the "Virtual Assets" node in the server view because that will not work.

    Here is a screenshot of where I placed the test jar file. In this case I copied it to a remote server into a folder named "bill"

  • Thanks will, i will try this on Monday and will let you know the results.

  • Hi William, I was able to place the jar file to the system_jars of Remote server. I have triggered the REST API resource by replacing the hostname and port number of the remote server which we are using in our project.

    http://timewarp:9080/soavirt/api/v6/preferences/systemProperties/reload

    Theres no response for the REST API POST call instead got a blank response with following headers.

    HTTP/1.1 204 No Content
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
    Access-Control-Allow-Headers: Content-Type, Accept, Authorization
    Date: Mon, 06 Jan 2020 15:09:02 GMT
    Connection: close
    Server: Parasoft Server

    When tested getting the following error which i have mentioned in my other question earlier.

    Message: Unable to instantiate class "oracle.jdbc.driver.OracleDriver". Please check the DB driver classname and the jar file locations in Parasoft > Preferences > JDBC Drivers.: 08001

    Could you please help here. Thanks.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    Is the driver jar also deployed to the remote virtualize server? I think it can be deployed to the same way, to system_jars, but I am not sure if it will require the server to be restarted to pick up the JDBC Driver. I would start by making sure that JDBC Driver jar is uploaded to system_jars and try using the reload rest api (the 204 response code means it reloaded successfully).

  • Hi William, I will try to get the server restarted and see if that works. Thanks.

  • Parasoft is installed in a Linux based Remote server, Can you share us the path where we can directly place the Jar files in the server.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    It doesn't have a default location so you will have to contact who ever setup the server on the Linux machine since they would know where they installed it.

  • Hi William, Parasoft Server admin team has place the "ojdbc" jars in the server and restarted the server, but still DB tool is failing with the below error. Any idea how to solve this issue as we need this issue to be solved in a week time.

    Message: Unable to instantiate class "oracle.jdbc.driver.OracleDriver". Please check the DB driver classname and the jar file locations in Parasoft > Preferences > JDBC Drivers.: 08001

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    It should work from the system_jars directory. I tried a test case and I was able to get a db connection using a driver jar that I put into system_jars. Does the Oracle ojdbc jar have that driver class?

  • Hi William, same Jar file is loaded in Local Machines and it works, only issue with the remote server.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Do you know if the remote server is a war deployment of a virtualizecli? It's possible that if it is the virtualizecl that you will need someone to setup the JDBC Driver similar to how it gets configured on the local machine.

  • Hi William, Yes, we are using a Linux machine. And it execute via virtualizecli. we try copying JDBC file lib directory and also System_jar directory.

    FYI., we are running virtualizeclie with Zjava attribute

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    I am not sure what the "Zjava" attribute is. Also just to make sure the directory is named "system_jars" all lower case and with the 's' at the end.

    https://docs.parasoft.com/display/SOAVIRT9103CTP310/Configuring+Virtualize+Server

  • jakubiak
    jakubiak Posts: 795 admin

    @williammccusker - -Zjava_home is how you tell virtualizecli to use a specified Java installation.

  • Pratikmore
    Pratikmore Posts: 6
    edited April 2020

    @AvinashPanditi I'm new to Parasoft and I don't know how to add my java project to the classpath as mentioned in Extensibility and Scripting Basics
    Even ,when i select the 'Scripted' mode from 'Input mode' of Response tab I could see my 'Modify Classpath' Feature is disabled neither I'm able to type in the text editor that appears. I have Free Community Edition, is this feature not available for free community edition?

    Thank you in advance.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    @Pratikmore

    The Extension tool and scripting is part of the paid version of the product.