Confluence: 5.9.7
ScriptRunner for Confluence: 5.2.12
The code below works as expected in script console
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.tr {
td("test")
td("test2")
}
writer.toString()
but throws an error in script REST endpoint
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovy.xml.MarkupBuilder
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
doSomething(httpMethod: "GET", groups: ["confluence-administrators"]) { MultivaluedMap queryParams, String queryBody ->
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.tr {
td("test")
td("test2")
}
return Response.ok(writer.toString()).build();
}
Error:
2018-03-12 17:58:24,231 ERROR [http-nio-8090-exec-4] [runner.rest.common.UserCustomScriptEndpoint] doEndpoint *************************************************************************************
-- url: /rest/scriptrunner/latest/custom/doSomething | userName: admin | sr.execution.id: b67e214f-5fa7-4834-8933-c42b82fbfb29
2018-03-12 17:58:24,232 ERROR [http-nio-8090-exec-4] [runner.rest.common.UserCustomScriptEndpoint] doEndpoint Script endpoint failed on method: GET doSomething
-- url: /rest/scriptrunner/latest/custom/doSomething | userName: admin | sr.execution.id: b67e214f-5fa7-4834-8933-c42b82fbfb29
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'test' with class 'java.lang.String' to class 'groovy.lang.Closure'
at com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate.methodMissing(CustomEndpointDelegate.groovy:22)
at Script39$_run_closure1$_closure2.doCall(Script39.groovy:15)
at Script39$_run_closure1$_closure2.doCall(Script39.groovy)
at Script39$_run_closure1.doCall(Script39.groovy:14)
at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:308)
at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:195)
Is it my mistake or it is a bug?
Hi Kirill,
This appears to be a ScriptRunner bug. Ordinarily the call to the missing method 'td' would be handled by the builder object, causing a <td> tag to appear in the outputted markup - this is what happens at the Script Console. In the REST endpoint code, however, the call gets intercepted by the CustomEndpointDelegate, which tries to interpret it as a declaration of an endpoint and fails.
I've filed this bug as SRJIRA-2751 so you can go and vote/watch/comment on it if you like.
Thanks,
J
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.