Thursday, February 5, 2015

The viewer is unable to connect with the CrystalReportViewerServlet that handles asynchronous requests...

In the process of upgrading cr4je 11 to 12 version. Using crjava-runtime_12.2.218.jar inside my JavaEE Struts Application.

You would need to update your runtimes from the below link

http://scn.sap.com/docs/DOC-29757

Download 'SAP Crystal Reports for Java runtime components - Java Reporting Component (JRC) (~ 45 MB)'

Problem:

Managed to display the reports using ReportViewer jsp. However in the report with pagination, when I click next page an alert box showing this message.

The viewer is unable to connect with the CrystalReportViewerServlet that handles asynchronous requests. Please ensure that the Servlet and Servlet-Mapping have been properly declared in the application’s web.xml file

My ReportViewer jsp location:

   Webcontent
         + crystalreportviewers
         + common
              + reports
                   - ReportViewer.jsp
Web.xml:
<context-param>
      <param-name>crystal_document_view</param-name>
      <param-value>weblayout</param-value>
 </context-param>

 <context-param>
       <param-name>crystal_image_uri</param-name>
       <param-value>MyWebApp/crystalreportviewers</param-value>
 </context-param>

 <context-param>
        <param-name>crystal_image_use_relative</param-name>
        <param-value>webapp</param-value>
  </context-param>

  <servlet>
         <display-name>CrystalReportViewerServlet</display-name>  
         <servlet-name>CrystalReportViewerServlet</servlet-name>
         <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
   </servlet>

   <servlet-mapping>
         <servlet-name>CrystalReportViewerServlet</servlet-name>
         <url-pattern>/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>


ReportViewer jsp:

    <%@ page import = "com.crystaldecisions.report.web.viewer.*"%>
    <%@ page import = "com.crystaldecisions.sdk.occa.report.data.*"%>
    <%@ page import = "com.crystaldecisions.sdk.occa.report.data.*"%>
   
   
   
 
   
    <%
         CrystalReportViewer viewer = new CrystalReportViewer();
         viewer.setName("Pending Report");

        //Enable Active-X print mode.
        viewer.setPrintMode(CrPrintMode.PDF);

        //Obtain report source of the report that the viewer will display. 
        Object reportSource = session.getAttribute("pendingReport");

        viewer.setReportSource(reportSource);

        Fields fields = (Fields) session.getAttribute("fields");
        viewer.setParameterFields(fields);
        viewer.setHasLogo(false); 
        viewer.setOwnPage(true);
        viewer.setDisplayGroupTree(false);
        viewer.setEnableDrillDown(true);  
        viewer.setBestFitPage(true);
        viewer.setURI("ReportActionClass.do?do=getPendingReport");
        viewer.setHasToggleGroupTreeButton(false);
         viewer.setHasViewList(false);
        viewer.setReuseParameterValuesOnRefresh(true);
        viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);

    %>
   

   
   
Solution:

Problem get resolved if I move my report viewer jsp file to the same level as 'crystalreportviewers' folder and change context-param.

Report viewer location:

    Webcontent
           + crystalreportviewers
           - ReportViewer.jsp
web.xml  context param:

<context-param>
<param-name>crystal_image_uri</param-name>
<param-value>MyWebApp/crystalreportviewers</param-value>
</context-param>


Alternate method:

I was in a situation to find an alternate way because  I don't have this issue in version 11. Moreover we have many reports at different folder levels.


So I've gone through the html source of created report viewer on both cases.(with problem & with solution)



If you check the generated source of crystal report viewer, you will find below code

Working condition (if crystal report viewer jsp is placed in the same level of \crystalreportviewers folder)



new bobj.crv.ViewerListener('AccountsPendingCallReport', new bobj.crv.ServletAdapter('CSAcctRewRpt.do?do=getPendingCallReport','CrystalReportViewerHandler'));

Otherwise you will see below (if crystal report viewer jsp is not placed in the same level of \crystalreportviewers folder)



new bobj.crv.ViewerListener('AccountsPendingCallReport', new bobj.crv.ServletAdapter('CSAcctRewRpt.do?do=getPendingCallReport','../../CrystalReportViewerHandler'));

The only difference is the second parameter of ServletAdapter constructor. Basically all user interactions (like navigation, export, download...) in crystal report are carried out by javascripts. So locate allInOne.js in \crystalreportviewers folder and find the below snippet where bobj.crv.ServletAdapter object been invoked.

Here I've replaced 'servletUrl' with "CrystalReportViewerHandler".

before
bobj.crv.ServletAdapter=function(pageUrl,servletUrl){this._pageUrl=pageUrl;this._servletUrl=servletUrl;this._form=null;}

after
bobj.crv.ServletAdapter=function(pageUrl,servletUrl){this._pageUrl=pageUrl;this._servletUrl="CrystalReportViewerHandler";this._form=null;}

This will fix the issue. In this way you may not need to place your report viewer jsp at same level as '\crystalreportviewers' folder.



5 comments:

  1. I am integrating my Crystal Report code with Spring Framework. Initially I had developed simple web application with only jsps (without spring feature) and CRystal Reports are rendering properly. I had tested it with parameters and DB connection Also.

    Now I am trying to integrate it with Spring framework. I did all necessary set-up. Reports are rendering properly, with parameters and DB connection. But when I click on next button I am getting error.

    "The viewer is unable to connect with the CrystalReportViewerServlet that handles asynchronous requests. Please ensure that the Servlet and Servlet-Mapping have been properly declared in the application's web.xml file."
    Also, images on reports are not displaying (showing cross).I tried to above stated solution but no luck.No error is shown this time, but page doesn't proceed.

    Please help me.

    Thank you,
    Sarika Chavan

    ReplyDelete
  2. Hi Sarika,

    Since no alert message shown, I suspect could be javascript error. Is there any javascript error shown in your browser?
    Did you check the html source of your report viewer, both before & after change?

    Regards,
    Suresh

    ReplyDelete
  3. Thank you for your help.

    I have checked, some JS error is showing. Actually after changing allInOne.js, it's giving error as "Uncaught ReferenceError: CrystalReportViewerHandler is not defined".

    Reason for not displaying images also, I understood little bit

    In normal jsp, if I view source code in browser for images it's showing path as
    "http://localhost:8080/webappname/CrystalReportViewerHandler?dynamicimage=crystal14388685391796882208436083798917.png"

    But when I try for spring app, image path is showing as
    "http://localhost:8080/CrystalReportViewerHandler?dynamicimage=crystal14388685391796882208436083798917.png"

    Basically images are not found on specified path I think..I am totally lost what things to change.

    Thanks,
    Sarika Chavan

    ReplyDelete
  4. Hi Sarika,

    Have you found the solution? I am also facing the same issue on my code. I am using struts2 with crystal report viewer and getting same error on click of export or next button. Please advise how you handle this.

    "The viewer is unable to connect with the CrystalReportViewerServlet that handles asynchronous requests.Please ensure that the Servlet and Servlet-Mapping have been properly declared in the application's web.xml file"

    Thanks,

    ReplyDelete