Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'savon'
- # create a client for the service
- # http://<confluence-install>/rpc/soap-axis/pdfexport?wsdll
- client = Savon.client(wsdl: 'https://example.atlassian.net/wiki/rpc/soap-axis/pdfexport?wsdl', read_timeout: 200)
- # call the 'findUser' operation
- response = client.call(:login, message: {username: "user", password: "pass"})
- token = response.body[:login_response][:login_return]
- response = client.call(:export_space, message:{token: token, space_key: "SPACE KEY"})
- void exportSpaceAsPdf(spaceKey, File outputFile) {
- // Setup Pdf Export Service
- PdfExportRpcServiceLocator serviceLocator = new PdfExportRpcServiceLocator()
- serviceLocator.setpdfexportEndpointAddress("${url}/rpc/soap-axis/pdfexport")
- serviceLocator.setMaintainSession(true)
- def pdfService = serviceLocator.getpdfexport()
- // Login
- def token = pdfService.login(user, password)
- // Perform Export
- def pdfUrl = pdfService.exportSpace(token, spaceKey)
- // Download Pdf
- HttpClient client = new DefaultHttpClient();
- HttpGet httpget = new HttpGet(pdfUrl)
- httpget.addHeader(
- BasicScheme.authenticate(
- new UsernamePasswordCredentials(user,password),"UTF-8", false))
- HttpResponse response = client.execute(httpget)
- HttpEntity entity = response.getEntity()
- if (entity != null) {
- InputStream inputStream = entity.getContent()
- FileOutputStream fos = new FileOutputStream(outputFile)
- int inByte
- while ((inByte = inputStream.read()) != -1)
- fos.write(inByte)
- inputStream.close()
- fos.close()
- } else {
- throw new GradleException("""Cannot Export Space to PDF:
- Space: ${spaceKey}
- Dest: ${outputFile.absolutePath}
- URL: ${pdfUrl}
- Status: ${response.getStatusLine()}
- """)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement