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
- In Script Editor, create a directory named test-resources.
- 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(); }
- Create a REST endpoint with the external script: doSomething.groovy.
- Click on the link to test the endpoint:
- 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
- is related to
-
SRJIRA-4245 Problem in displaying the File path for REST Endpoints
-
- Done
-
-
SRPLAT-1271 Existing REST Endpoints using an inline script cannot switch to File tab
-
- Done
-