REST endpoint - can't create using script on disk

Sergey Kachanovskiy January 2, 2019

Hi there,

 

Jira 7.12.3, ScriptRunner 5.4.45

 

trying to create a REST endpoint using ScriptRunner for Jira, and observing the following behavior:

1) all is ok when inline script is used
2) when I want to use file on disk, it creates an endpoint I want with the code from this file (with the name, say, "projects/endpoints/dialog1/endpoint.groovy" and a cog next to it), AND another endpoint named "dialog1.groovy" with no cog and comment "Found by class scanning and can't be edited here" instead.

I can't access the REST endpoint at all since the automatically configured one takes precedence and causes the following error:


2019-01-02 09:23:17,617 http-nio-8080-exec-26 ERROR s.kachanovskiy 563x44088x1 ks0owv 10.0.0.134,0:0:0:0:0:0:0:1 /rest/scriptrunner/latest/custom/showDialog [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: Cannot open URL: bundle://178.0:0/endpoint.groovy
groovy.util.ResourceException: Cannot open URL: bundle://178.0:0/endpoint.groovy
        at groovy.util.GroovyScriptEngine.getResourceConnection(GroovyScriptEngine.java:410)
        at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:552)
        at groovy.util.GroovyScriptEngine$loadScriptByName$1.call(Unknown Source)
        at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.loadScriptByName(ScriptRunnerImpl.groovy:692)
        at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:321)
        at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:256)
        ... 2 filtered
        at java.lang.reflect.Method.invoke(Method.java:498)
        ... 19 filtered
        at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:154)
        ... 1 filtered
        at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:68)
        ... 41 filtered
        at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
        ... 53 filtered
        at com.atlassian.jira.security.JiraSecurityFilter.lambda$doFilter$0(JiraSecurityFilter.java:66)
        ... 1 filtered
        at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:64)
        ... 16 filtered
        at com.atlassian.plugins.rest.module.servlet.RestSeraphFilter.doFilter(RestSeraphFilter.java:37)
        ... 19 filtered
        at com.atlassian.jira.servermetrics.CorrelationIdPopulatorFilter.doFilter(CorrelationIdPopulatorFilter.java:30)
        ... 10 filtered
        at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
        ... 4 filtered
        at com.atlassian.web.servlet.plugin.LocationCleanerFilter.doFilter(LocationCleanerFilter.java:36)
        ... 26 filtered
        at com.atlassian.jira.servermetrics.MetricsCollectorFilter.doFilter(MetricsCollectorFilter.java:25)
        ... 24 filtered
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: groovy.util.ResourceException: Cannot open URL: file:/var/atlassian/application-data/jira/scripts/endpoint.groovy
        at groovy.util.GroovyScriptEngine.getResourceConnection(GroovyScriptEngine.java:408)
        ... 236 more

deleting the "long name" endpoint also deletes the other one.

to me it looks like for some reason I cannot configure an endpoint using an arbitrary file.

 

any ideas/suggestions here?

Cheers.
Sergey.

2 answers

1 vote
Sergey Balakhonov October 6, 2022

Check if package defined in script.
Looks like it's working WITHOUT package while inline, but as file script it needs a package.
Works for me.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 2, 2019

Where is it getting "bundle://178.0:0/endpoint.groovy" from?  That's a broken url, so it's never going to work.

Sergey Kachanovskiy January 2, 2019

it's indeed broken.

 

I've tested it again using example from here: https://scriptrunner.adaptavist.com/latest/jira/fragments/WebItem.html#_dialogs_advanced (well - I've actually used this example to create my own code :))

the result is exactly the same: it creates TWO endpoints, one with a cog and the other from class scanning, both with the same resource names, auto-configured one is used first, and log records say file "/var/atlassian/application-data/jira/scripts/example.groovy" cannot be found (it is intentionally placed under subfolder).

Like Rolf Lader likes this
Sergey Kachanovskiy January 2, 2019

there's one thing that actually kind of moves it forward:
https://community.atlassian.com/t5/Marketplace-Apps-questions/Scriptrunner-endpoint-rest-script-location/qaq-p/583633

when I start my endpoint script with package declaration, all is fine: a single endpoint is created, name is ok, and it immediately works no matter how deep in subfolders I put the file.

now I am wondering if this is the recommended (or maybe the sole?) workaround, and if it is - what is the root cause of such behavior, and should I go through all scripts I have for postfunctions/conditions/validators and put the same package declaration line on top? and do I get i right that the package declaration reflects the folder structure, so that if I have condition, validator and postfunction scripts for transition in the same folder, they all are going to have the same package declaration line?

Cheers.
Sergey.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events