Forums

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

How to retrieve/get document download or attached to ticket by calling Jar using postfunction

Tamil April 25, 2022


Hi,

I have a application code converted to Jar(developed in Spring). This Jar when called using Jira credentials and ticket, will prepare and return a document having ticket details and is downloadable. From my local it is working fine and i am able to download document.

 

When i try to do this from Workflow postfunctions(Using Scriptrunner), I am not able to return browser downloadable document.

 

Jar is placed in Jira Server which is executable and in workflow postfunctions script is placed to call jar file to generate and download document.

From Logs, word document is generated in server, but i am not able to return response to browser. Could you please help on this?

 

import java.net.http.HttpResponse;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()


def issueManager = ComponentAccessor.getIssueManager()

//def myIssue = event.issue
String myIssueKey = issue.getKey()
log.error("DeliveryID:"+ myIssueKey)
log.error(issue)

String user="user"
log.error("Username"+ user)
String pass="password"
log.error("Password"+ pass)
//CloseableHttpClient client = HttpClients.createDefault();
try{
String URL="http://Jira Server IP:8090/server-Jar-path/Username/Password/Ticket-number";
URL url = new URL(URL);

log.error("Conn IN")

HttpURLConnection con = (HttpURLConnection) url.openConnection();
log.error("Open connection"+con)

con.setRequestMethod("GET");
String contentType = con.getHeaderField("Content-Type");
log.error("Content type"+contentType)

log.error("Get Method In")
con.setDoOutput(true);
log.error("getcontentmethod"+con.getRequestMethod())
con.connect();
OutputStream out = con.getOutputStream();
log.error("Output stream " +out)
log.error("Response" +con.getResponseCode())
out.write("".getBytes());
out.flush();


con.disconnect();

log.error("Disconnect")
//client.close();
log.error("Close")
Response.ok(out).build();
log.error("Completed")

 

} catch (Exception e){
log.error(e);
}

 

 

0 answers

Suggest an answer

Log in or Sign up to answer