Cannot create a fragment with a corresponding REST endpoint

Mouna Hammoudi
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.
August 12, 2022

I am trying to create a custom web item that navigates to a link when clicking on it. Here is a screenshot of the way in which I have created the custom web item: 

Capture.PNG

 

I have also defined a REST endpoint as you can see in the following screenshot 

RESTEndpoint.PNG

 

Here is the corresponding code for my REST Endpoint that I have written in the script editor. The problem is that nothing works, even the string that I am writing to the log "THIS IS MOUNA'S TEST" is not displayed in the log. So when I click on the menu item "Mouna Bulk Summary", I get redirected to this error page. How can I fix this and make my fragment/REST endpoint work? 

ErrorPage.PNG

import groovy.transform.BaseScript

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate

import javax.ws.rs.core.MultivaluedMap

import com.atlassian.jira.component.ComponentAccessor

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

import com.atlassian.sal.api.ApplicationProperties

import com.atlassian.sal.api.UrlMode

import javax.ws.rs.core.Response

import org.apache.log4j.Logger

@BaseScript CustomEndpointDelegate delegate

 

callFeaturePerformanceImpactAnalysis(httpMethod: "GET") { MultivaluedMap queryParams ->

    def log = Logger.getLogger("atlassian-jira.log")

    log.warn("THIS IS MOUNA'S TEST")

    def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser

    def issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)

    def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)

    def redirectUrl = "https://secapps.eur.ad.sag:9888/FPIA/?iTrac=${issue.key}&reporter=${user.key}&baseURL=${baseUrl}"

    Response.temporaryRedirect(URI.create(redirectUrl)).build()

}

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _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.
August 17, 2022

Hi @Mouna Hammoudi

The approach that you are taking will not work.

If you observe your REST Endpoint code, you named the method callFeaturePerformanceImpactAnalysis, i.e.:-

callFeaturePerformanceImpactAnalysis(httpMethod: "GET") { MultivaluedMap queryParams ->

However, when you try to invoke the REST Endpoint, the URL you are using is:-

http://itrac-dev.eur.ad.sag/rest/scriptrunner/latest/custom/MounaBulkSummary?issueId=1281074

Which will not work. In your REST Endpoint configuration, there is no such method called MounaBulkSummary.

You should instead invoke the callFeaturePerformanceImpactAnalysis method, and the URL your should use is something like:-

http://itrac-dev.eur.ad.sag/rest/scriptrunner/latest/custom/callFeaturePerformanceImpactAnalysis?issueId=1281074

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer