How to access XML search request from script?

Jaime Luis Ramirez-Riberos January 23, 2018

I am trying to create a script that needs to process an xml output from a JQL search request.

I am having issues just reading the url, and is very likely due to permissions, but can't seem to find a way to make it work.

I am trying a simple script to test:


String xml_url = 'http://jira.my-company.com:8080/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+T500+AND+issuetype+%3D+Task'

return xml_url.toURL().text

but get a 400 error:

2018-01-23 17:25:36,400 WARN [common.UserScriptEndpoint]: Script console script failed: java.io.IOException: Server returned HTTP response code: 400 for URL: http://jira.my-company.com:8080/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+T500+AND+issuetype+%3D+Task at Script360.run(Script360.groovy:5)

 

I have trying passing the &?os_authType=basic and even &?os_username=un&?os_password=pwd (which I agree is not a good idea), and still same error.

If I use a non authenticated url, i.e. 'http://www.google.com', it works.

Does anyone know a reasonable way to access and read XML output from a JQL request using scripts in JIRA? 

Thanks!

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Michel Tremblay [Adaptavist] January 31, 2018

It's more a question than an Answer, 

But is there a reason you want your search to return an XML.

When I use Script to do an Issue search, I usually prefer to get a collection of IssueObjects

This way you don't have to deal with an unofficial way to get your issues.

Like something like this : 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

public static List JqlSearch(String jqlString) {
try {
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlString)
if (parseResult.isValid()) {
def result = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()).getIssues()
return result
} else {
return null
}
}
catch (Exception e) {
}
}

 

Another solution would be to go through the Real REST API, and then convert the JSON result into XML

Like in this example

https://stackoverflow.com/questions/29937254/convert-json-to-xml-using-groovy

Jaime Luis Ramirez-Riberos February 2, 2018

Thanks for your input. 

To answer your question, I am using XSLT processing to create output from XML, so I did not want to necessarily add another step to go from JSON to XML. 

TAGS
AUG Leaders

Atlassian Community Events