Skip to Content
avatar image
Former Member

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".


Note: I skipped passing the prompts to first get the report to download. Could that be the problem?


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!!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 30, 2015 at 07:25 PM

    Hi Rose,

    from your code, you are actually downloading the RPT binary.  To get a PDF, you can schedule the report to PDF and then download the scheduled instance.

    Dan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I finally got this to work!

      The issue was that a logon token retrieved using web service URL oSession.login(oEnterpriseCredential)  does not work. I needed a token retrieved from a CMS session: mySessionMgr.logon(boUserId, boPassword, currentServer, authType);

      Here is the code:

      Original code (that did not work)

      Web Service URL: http://server1:8080/dswsbobje/services/

      //get connection

      servicesURL = http://<server1>:8080/dswsbobje/services/

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

      EnterpriseCredential oEnterpriseCredential = EnterpriseCredential.Factory.newInstance();

      oEnterpriseCredential.setLogin(userName);  

      oEnterpriseCredential.setPassword(password);           

      oEnterpriseCredential.setAuthType("SecLDAP");

      //get session

      SessionInfo boSI = oSession.login(oEnterpriseCredential);

      strLogonToken = boSI.getDefaultToken();

      //construct URL

      String redirectURL = "http://server1:8080/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID="+repID+"&sIDType=CUID&token="+URLEncoder.encode(strLogonToken)+"&lsSowner=Dave&lsSowner_div=HR&sOutputFormat=P";

      response.sendRedirect(redirectURL);

      In this case, it always prompted user to login to BOXI, irrespective of me sending the token.

      Then I changed it as follows:

      //CMS URL

      String cmsUrl = "server2:6400";

      ISessionMgr mySessionMgr = CrystalEnterprise.getSessionMgr();

      IEnterpriseSession eSession = null;

      String[] boxiServers = cmsUrl.split(",");

      Random randomGenerator = new Random();

      int randomPosition = randomGenerator.nextInt(boxiServers.length);

      String currentServer = boxiServers[randomPosition].trim();

      //get session

      eSession = mySessionMgr.logon(boUserId, boPassword, currentServer, authType);

      //get token

      cmsToken = eSession.getLogonTokenMgr().createLogonToken("", 120, 100);

      //URL with CMS token, pointing to web service URL

      String redirectURL = "http://server1:8080/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID="+repID+"&sIDType=CUID&token="+URLEncoder.encode(cmsToken)+"&lsSowner=Dave&lsSowner_div=HR&sOutputFormat=P";

      response.sendRedirect(redirectURL);

      This worked like a charm!

      Thank you Dell & Daniel for your help.

  • avatar image
    Former Member
    Oct 30, 2015 at 07:05 PM

    Per the Developer Guide, Report Engine is deprecated in BOXI 4.

    But I see it listed under List Services:

    http://<myservername>:8080/dswsbobje/services/ReportEngine

    Available Operations

    • getDataSourceObjectLOV
    • getDocumentInformation
    • getImage

    And also in Java Docs:

    com.businessobjects.dsws.reportengine

    Class ReportEngine

    "ReportEngine class is a proxy that can consume the ReportEngine Web Service and that is mapped on its WSDL.  ReportEngine provides services to return DocumentInformation and Image objects."

    However, I am unable to import "com.businessobjects.dsws.reportengine" in my Java code, in spite of having all BOXI 4 JArs.

    So is Report Engine available for use or not? Argh!

    Add comment
    10|10000 characters needed characters exceeded