Forums

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

How to call Confluence Copy Space App from Jira ScriptRunner Script

Bastian Stehmann
Community Champion
February 16, 2020

Hi,

 

I'm trying to call the Copy Space App from a Scriptrunner Groovy Script.

 

What I have so far is this:

 def request = URLEncoder.encode("newName", "UTF-8") + "=" + URLEncoder.encode(spaceName, "UTF-8")+
        "&"+ URLEncoder.encode("newKey", "UTF-8") + "=" + URLEncoder.encode(spaceKey, "UTF-8")+
        "&"+ URLEncoder.encode("copyComments", "UTF-8") + "=" + URLEncoder.encode("true", "UTF-8")+
        "&"+ URLEncoder.encode("copyAttachments", "UTF-8") + "=" + URLEncoder.encode("true", "UTF-8")+
        "&"+ URLEncoder.encode("confirm", "UTF-8") + "=" + URLEncoder.encode("Save", "UTF-8")

def url = new URL (baseURL+"/spaces/docopyspace.action?key="+sourceKey)

HttpURLConnection connection = url.openConnection() as HttpURLConnection
   

 connection.setDoOutput(true)
    connection.setRequestMethod("POST")
 connection.setRequestProperty("Authorization", "Basic "+encodedAuth);
 connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
    connection.setRequestProperty("charset","utf-8")
 connection.setRequestProperty("cache-control","no-cache")
    connection.setRequestProperty("Content-Length", Integer.toString(request.getBytes(StandardCharsets.UTF_8).length));

 //connection.outputStream.withWriter("UTF-8"){new StreamingJsonBuilder(it, request)}
 //connection.connect()

    DataOutputStream wr = new DataOutputStream (
                  connection.getOutputStream ());
      wr.write(request.getBytes(StandardCharsets.UTF_8));
    wr.flush()

def requestSuccesful = connection.getResponseCode() == 201 || connection.getResponseCode() == 200

 log.error(connection.getResponseCode())
   
    def responseReader = requestSuccesful?new BufferedReader(new InputStreamReader(connection?.getInputStream(),"UTF-8")):new BufferedReader(new InputStreamReader(connection?.getErrorStream(),"UTF-8"))

 String inputLine
 StringBuffer response = new StringBuffer()

 while ((inputLine = responseReader.readLine()) != null){
     response.append(inputLine)
 }

 responseReader.close()
   
    log.error(response)

But it seems, that it does not send the request string correct, I'm getting a 200 Response, but it sends me only the page with form and does not copy the space.

 

Any ideas whats wrong? 

0 answers

Suggest an answer

Log in or Sign up to answer