Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to export Crystal Report using BOXI 4 Web Services

Hi Forum,

We have a custom Java web app, from where the user can launch BOXI reports. Behind the scenes, a servlet does the following:

a. connect with BOXI server

b. Pass on the values chosen by the user

c. Retrieve report

d. Display report in PDF format on the browser


Our BOXI setup was upgraded from BOXI 3 to BOXI 4 and since then this functionality does not work.


So far, I have been able to connect to BOXI 4server, get a session and retrieve the report ID. How can I next export this report in a PDF format.

I tried downloading the file and then writing the stream to both a local file object and the servlet's response stream. Both dont work.


The file gets created. But when I try opening the pdf file, I get the error:"Adobe could not open the file because it is either not a supported file type or because the file has been damaged".


I could find no sample code for exporting a report using Web Services. I only see Webi examples, but I need Web Services


Help please? (My code below)


ResponseHolder rh;

String servicesURL = "http://<server>:8080/dswsbobje/services/

Connection oConnection = new Connection(new URL(servicesURL+"session"));


//set credentials

EnterpriseCredential oEnterpriseCredential = EnterpriseCredential.Factory.newInstance();

           

            oEnterpriseCredential.setLogin(userName);  

            oEnterpriseCredential.setPassword(password);           

            oEnterpriseCredential.setAuthType("SecLDAP");

//get session

oSession = new Session(oConnection);

oSession.login(oEnterpriseCredential);

//connect to BIPlatform

oConnection.setURL(new URL(servicesURL+"biplatform"));

BIPlatform oBIPlatform = new BIPlatform(oConnection,oSession.getConnectionState());

GetOptions oGetOptions = GetOptions.Factory.newInstance();

oGetOptions.setIncludeSecurity(FALSE);

//set report Path

String path = "path://InfoObjects/Root Folder/"+properties.getString("REPORT_PATH")+reportName;

//get report to response holder

rh = oBIPlatform.get(path, null);

InfoObjects infoObjects = rh.getInfoObjects();

if (infoObjects == null || infoObjects.getInfoObjectArray().length == 0){

                  System.out.println("Failed to find report: " + reportName);

                  return;

                }

//get report ID

InfoObject reportInfoObject = infoObjects.getInfoObjectArray(0);

String reportCUID = reportInfoObject.getCUID();

int reportID = reportInfoObject.getID();

//IT WORKS UNTIL HERE

//next I tried both writing the report to a file as well as to the response stream. Both are not working!

//set response values

response.setContentType("application/pdf");

response.addHeader("Content-Disposition", "inline;filename=" + reportName +".pdf");

java.io.OutputStream os = response.getOutputStream();

//start downloading report

String downloadID = oBIPlatform.startSingleDownload(reportCUID, 0, null);

//file object

java.io.File newFileObj = new java.io.File(filePath);

if(newFileObj.exists()){

                  newFileObj.delete();

                }

newFileObj.createNewFile();

java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(newFileObj);

//download the report

DownloadStatus status = oBIPlatform.downloadFile(downloadID, Long.valueOf("0"));

//write stream to file object and response

fileOutputStream.write(status.getBinaryData());

os.write(status.getBinaryData());

//continue file writing

while(!status.getEndOfFile()){

                 

                  oBIPlatform.downloadFile(downloadID, Long.valueOf(status.getNextReferencePosition()));        

                  System.out.println("Writing.." + status.getBinaryData());

                  fileOutputStream.write(status.getBinaryData()); //write tofile

                  os.write(status.getBinaryData()); //write to response

                }

//close streams

fileOutputStream.close();

os.close();

oBIPlatform.finishDownload(downloadID);

Any help please!!

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question