Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. require 'savon'
  2. # create a client for the service
  3. # http://<confluence-install>/rpc/soap-axis/pdfexport?wsdll
  4. client = Savon.client(wsdl: 'https://example.atlassian.net/wiki/rpc/soap-axis/pdfexport?wsdl', read_timeout: 200)
  5.  
  6. # call the 'findUser' operation
  7. response = client.call(:login, message: {username: "user", password: "pass"})
  8.  
  9. token = response.body[:login_response][:login_return]
  10.  
  11. response = client.call(:export_space, message:{token: token, space_key: "SPACE KEY"})
  12.  
  13. void exportSpaceAsPdf(spaceKey, File outputFile) {
  14. // Setup Pdf Export Service
  15. PdfExportRpcServiceLocator serviceLocator = new PdfExportRpcServiceLocator()
  16. serviceLocator.setpdfexportEndpointAddress("${url}/rpc/soap-axis/pdfexport")
  17. serviceLocator.setMaintainSession(true)
  18. def pdfService = serviceLocator.getpdfexport()
  19.  
  20. // Login
  21. def token = pdfService.login(user, password)
  22.  
  23. // Perform Export
  24. def pdfUrl = pdfService.exportSpace(token, spaceKey)
  25.  
  26. // Download Pdf
  27. HttpClient client = new DefaultHttpClient();
  28. HttpGet httpget = new HttpGet(pdfUrl)
  29. httpget.addHeader(
  30. BasicScheme.authenticate(
  31. new UsernamePasswordCredentials(user,password),"UTF-8", false))
  32. HttpResponse response = client.execute(httpget)
  33. HttpEntity entity = response.getEntity()
  34.  
  35. if (entity != null) {
  36. InputStream inputStream = entity.getContent()
  37. FileOutputStream fos = new FileOutputStream(outputFile)
  38. int inByte
  39. while ((inByte = inputStream.read()) != -1)
  40. fos.write(inByte)
  41. inputStream.close()
  42. fos.close()
  43. } else {
  44. throw new GradleException("""Cannot Export Space to PDF:
  45. Space: ${spaceKey}
  46. Dest: ${outputFile.absolutePath}
  47. URL: ${pdfUrl}
  48. Status: ${response.getStatusLine()}
  49. """)
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement