I'm trying to create a REST Endpoint to allow pulling a list of issues. In this example - Epics in a given project that are not Done. When I try to call the endpoint, I get the following error:
{"message":null,"stack-trace":"java.lang.StackOverflowError\n","status-code":"INTERNAL_SERVER_ERROR"}
This is a simplified example, my actual script is doing more, but this is isolated to the problem area.
Anyone able to do this?
Here is my REST Endpoint code:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.PermissionManager
import com.atlassian.jira.permission.ProjectPermissions
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
@BaseScript CustomEndpointDelegate delegate
getEpicsInProject(httpMethod: "GET") { MultivaluedMap queryParams ->
def projectKey = queryParams.getFirst("project") as String
def retHash = [:]
def projectList = []
def errorList = []
def resultstatus = 1
def projData
if(projectKey == null){
resultstatus = 0
errorList.push('Invalid Project')
retHash["errors"] = errorList
}else{
def jqlSearch = "type = Epic and project = " + projectKey + " and status != Done"
ApplicationUser adminUser = ComponentAccessor.getUserManager()getUserByName("admin")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(adminUser)
def searchService = ComponentAccessor.getComponentOfType(SearchService.class)
SearchService.ParseResult parseResult = searchService.parseQuery(adminUser, jqlSearch)
def results = searchService.search(adminUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = results.getIssues()
retHash["issues"] = issues
}
retHash["status"] = resultstatus
Response.ok(JsonOutput.toJson(retHash)).build()
}
I got it working by transferring the data to a new object instead of passing back the Issues List:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.PermissionManager
import com.atlassian.jira.permission.ProjectPermissions
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
class objSummary{
String key
String summary
}
@BaseScript CustomEndpointDelegate delegate
getEpicsInProject(httpMethod: "GET") { MultivaluedMap queryParams ->
def projectKey = queryParams.getFirst("project") as String
def retHash = [:]
def issueList = []
def errorList = []
def resultstatus = 1
def projData
if(projectKey == null){
resultstatus = 0
errorList.push('Invalid Project')
retHash["errors"] = errorList
}else{
def jqlSearch = "type = Epic and project = " + projectKey + " and status != Done" // the jql query you want to search with
ApplicationUser adminUser = ComponentAccessor.getUserManager()getUserByName("admin")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(adminUser)
def searchService = ComponentAccessor.getComponentOfType(SearchService.class)
SearchService.ParseResult parseResult = searchService.parseQuery(adminUser, jqlSearch)
def isscount = 0
def results = searchService.search(adminUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = results.getIssues()
issues.each(){Issue oneIssue ->
def oSum = new objSummary()
oSum["key"] = oneIssue.getKey()
oSum["summary"] = oneIssue.getSummary()
issueList.add(oSum)
}
retHash["issues"] = issueList
// results.clear()
// issues.clear()
//retHash["issues"] = searchService.searchCount(adminUser, parseResult.getQuery())
}
retHash["status"] = resultstatus
Response.ok(JsonOutput.toJson(retHash)).build()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Steve Kamens!
Check server logs atlassian/application-data/jira/log. What is there?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2018-10-25 11:22:32,917 http-nio-8080-exec-176 ERROR admin 682x33057x1 vk0t3k 172.28.145.52 /rest/scriptrunner/latest/custom/getEpicsInProject [c.o.s.r.rest.common.UserCustomScriptEndpoint] Script endpoint failed on method: GET getEpicsInProject
java.lang.StackOverflowError
2018-10-25 11:23:15,559 Caesium-1-4 ERROR ServiceRunner [o.o.c.entity.jdbc.SQLProcessor] !!! ABANDONED SQLProcessor DETECTED !!!
This probably means that somebody forgot to close an EntityListIterator.
Connection: DelegatingConnectionImpl[connectionPoolInfo=ConnectionPoolInfo{maxSize=20, minSize=20, initialSize=null, maxIdle=20, maxWait=30000, sleepTime=300000, lifeTime=600000, deadLockMaxWait=600000, deadLockRetryWait=10000, validationQuery='select 1', minEvictableTimeMillis=60000, timeBetweenEvictionRunsMillis=300000, poolPreparedStatements=null, testOnBorrow=false, testOnReturn=null, testWhileIdle=true, maxOpenPreparedStatements=null, numTestsPerEvictionRun=null, removeAbandonedOnBorrow=true, removeAbandonedOnMaintanance=null, removeAbandonedTimeout=300, validationQueryTimeout=3, defaultCatalog=null},sqlConnectionInterceptor=org.ofbiz.core.entity.jdbc.interceptors.connection.SafeDelegatingSqlConnectionInterceptor@58ad0bf7]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.