Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-4813

Using External Script located inside a directory in REST Endpoint causes HTTP 500 error and Found by class scanning and can't be edited here

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Invalid
    • Affects Version/s: 6.11.0
    • Fix Version/s: None
    • Component/s: REST EndPoint
    • Labels:
      None
    • Sprint:
      SR4J Sprint 89
    • Critical Points:
      3.6

      Description

      Using External Script located inside a directory in REST Endpoint causes:

      • HTTP 500 error (error500.txt)
      • Found by class scanning and can't be edited here

      Step To Reproduce

      1. In Script Editor, create a directory named test-resources.
      2. Create a script in that directory with the following named doSomething.groovy:
         
        import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
        import groovy.json.JsonBuilder
        import groovy.transform.BaseScript
        
        import javax.ws.rs.core.MultivaluedMap
        import javax.ws.rs.core.Response
        
        @BaseScript CustomEndpointDelegate delegate
        
        doSomething(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
            return Response.ok(new JsonBuilder([abc: 42]).toString()).build();
        }
        
      3. Create a REST endpoint with the external script: doSomething.groovy.
      4. Click on the link to test the endpoint:
      5. You should get an HTTP 500 error in a new tab.

      Notes

      Looking at the error, you will notice the following:

       
      Caused by: groovy.util.ResourceException: Cannot open URL: file:/Users/benzkek/JIRA_HOME/8.11.1/scripts/doSomething.groovy at groovy.util.GroovyScriptEngine.getResourceConnection(GroovyScriptEngine.java:400)
      

      It seems that it is looking for doSomething.groovy at the root instead of /test-resources directory.
      The script is located at /Users/benzkek/JIRA_HOME/8.11.1/scripts/test-resources/doSomething.groovy

      Workaround

      Moving the script to the root will be able to work around the bug.

      OR

      Use the package statement where your script is in a directory and make sure that your directory is a valid package name. For example, the script is located in $JIRA_HOME/scripts/testresources then your script should be like below:

       
      package testresources
      
      import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
      import groovy.json.JsonBuilder
      import groovy.transform.BaseScript
      
      import javax.ws.rs.core.MultivaluedMap
      import javax.ws.rs.core.Response
      
      @BaseScript CustomEndpointDelegate delegate
      
      doSomething(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
          return Response.ok(new JsonBuilder([abc: 42]).toString()).build();
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              bkek Benz Kek
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: