Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

MarkupBuilder throws an error in script REST endpoint in Confluence

Kirill Fedorov March 12, 2018 edited

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?

1 answer

1 accepted

0 votes
Answer accepted
Joanna Choules
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 16, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events