Forums

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

REST endpoint works as in line script but not as file, Cannot open URL: bundle://200.0:1/rest_Create

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.
November 28, 2022
I am using this REST endpoint for a fragment and it works perfectly as an inline script. 
Capture.PNG
Here is my code below and here is a screenshot of the page where I am redirected after clicking on the button. 
Capture1.PNG

import groovy.transform.BaseScript

import com.atlassian.jira.issue.Issue;

import javax.ws.rs.core.Response

import org.apache.log4j.Logger

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 javax.ws.rs.core.Response

import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks

import com.atlassian.jira.project.Project

@BaseScript CustomEndpointDelegate delegate

callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->

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

log1.warn("MOUNA CAMELIA223");

Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()

def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()

String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;

log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);

 def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser

  def issueId = queryParams.getFirst("issueId") as Long

  Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)

  def issueKey = myissue.getKey()

  def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)

  def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())

  log1.warn("The rest endpoint has been executed by the user " +user)

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

 

}

When I specify a file for the code that I refer to in my script editor. Everything fails when I click on the button and I am redirected to an error page as you can see below. 

Capture3.PNG
anyone knows what the problem is?
Capture2.PNG
Capture4.PNG

2 answers

1 vote
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.
February 1, 2023

We need a package declatation at the top of the code so we need **package BulkSplitter** at the top of the code. We need to go to REST endpoint and execute an update. Otherwise, Jira doesn't recognize our changes.

package BulkSplitter 
import groovy.transform.BaseScript

import com.atlassian.jira.issue.Issue;

import javax.ws.rs.core.Response

import org.apache.log4j.Logger

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 javax.ws.rs.core.Response

import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks

import com.atlassian.jira.project.Project

@BaseScript CustomEndpointDelegate delegate

callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->

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

log1.warn("MOUNA CAMELIA223");

Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()

def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()

String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;

log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);

def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser

def issueId = queryParams.getFirst("issueId") as Long

Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)

def issueKey = myissue.getKey()

def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)

def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())

log1.warn("The rest endpoint has been executed by the user " +user)

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



}
1 vote
ChristopherChilds
Contributor
January 30, 2023

did you get an answer for this?

 

I am having the same problem.

Suggest an answer

Log in or Sign up to answer