Forums

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

ScriptRunner Confluence REST endpoint with @BaseScript, @WithPlugin, and @PluginModule

Alexander Batis April 26, 2018

I'm trying to create a rest endpoint (in ScriptRunner) which uses the mywork-confluence-host-plugin java api

Here's the code :

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

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.mywork.host.service.LocalNotificationServiceImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.mywork.mywork-confluence-host-plugin")
@PluginModule LocalNotificationServiceImpl notificationService

@BaseScript CustomEndpointDelegate delegate
someEndpoint(httpMethod: "GET", groups: ["someGroup"]) { MultivaluedMap queryParams, String body ->
def notifications = notificationService.findAll("someUsername")
return Response.ok(new JsonBuilder(notifications).toString()).build();
}

 

However, when i include the @PluginModule annotation, the endpoint in ScriptRunner becomes invalid.  When i try to hit the endpoint, I get a 404. In my configuration, 

What a valid endpoint looks like in my configuration:api-endpoint-example.PNG

 

 

What the endpoint using @PluginModule looks like in my configuration:

api-endpoint-error.PNG

 

api-endpoint-error.PNG

1 answer

1 accepted

1 vote
Answer accepted
Stephen Cheesley _Adaptavist_
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.
April 27, 2018

Hi Alexander,

Do you have any anomalous output in your logs? Any stacktraces or any other errors perhaps?

Alexander Batis April 27, 2018

@Stephen Cheesley _Adaptavist_ It wasn't outputting any logs so after some troubleshooting i disabled the ScriptRunner plugin, thene re-enabled it and the same code runs just fine

Alexander Batis April 27, 2018

@Stephen Cheesley _Adaptavist_ after not running the code for a while, it started giving the following error :

 

{

message: "Cannot invoke method findAll() on null object",

stack-trace: "java.lang.NullPointerException: Cannot invoke method findAll() on null object at Script486$_run_closure1.doCall(Script486.groovy:21) at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:308) at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:195) ",

status-code: "INTERNAL_SERVER_ERROR"

}
Stephen Cheesley _Adaptavist_
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.
April 27, 2018

What version of ScriptRunner are you using?

Alexander Batis April 27, 2018

@Stephen Cheesley _Adaptavist_ ScriptRunner version 5.2.12

Alexander Batis April 27, 2018

Here's what the configuration looks like now:

api-endpoint-error-2.PNG

Also , I haven't changed any of the code, or have even updated it from what you see above.  

Stephen Cheesley _Adaptavist_
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.
April 27, 2018

Are you using Data Centre or Server?

Alexander Batis April 27, 2018

Data Centre

Stephen Cheesley _Adaptavist_
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.
April 27, 2018

I would recommend updating to the latest version of ScriptRunner as we patched some DC issues for REST endpoints in that release

Alexander Batis April 27, 2018

ill give that a shot and ill check back here if I still experience the issue - thanks!

Stephen Cheesley _Adaptavist_
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.
April 30, 2018

Hey Alexander,

Did the upgrade fix your issue?

Alexander Batis May 1, 2018

I haven't had any issues since I've upgraded - I'll mark this as resolved. Thanks Stephen!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events