neeraja Report post Posted June 30, 2011 Hello, I have problem configuring Fusion charts for exporting PDF/images into springs framework. My big doubt was i followed below steps to set up the environment which was specified in ReadMe which came with FusionCharts_Evaluation FusionCharts Server-side Export Handler - J2EE ============================================== For exporting the chart as image/pdf at server side using JSP, the following library files are required on your server: 1. fcexporter.jar (contains all the dependency classes) 2. fcexporthandler.jar (contains the export handler servlet and resources) 3. /classes/fusioncharts_export.properties (configuration file) Setup ----- Step1: Copy the neccessary files Please place the export jars fcexporter.jar and fcexporthandler.jar in WEB-INF/lib and fusioncharts_export.properties in WEB-INF/classes folder. FusionCharts Exporter has been tested with JDK 1.5. Note that the FusionCharts Exporter jars for jdk1.4.2 is also available in ExportHandlers/JDK1.4 folder Step2: Configure web.xml Add the following servlet mapping in your application's web.xml <servlet> <display-name>FCExporter</display-name> <servlet-name>FCExporter</servlet-name> <servlet-class>com.fusioncharts.exporter.servlet.FCExporter</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>FCExporter</servlet-name> <url-pattern>/JSP/ExportExample/FCExporter</url-pattern> </servlet-mapping> Please modify the url-pattern as per your application needs. Step3: Specify the xml attribute exportHandler='FCExporter' assuming that the jsp rendering the chart is present in /JSP/ExportExample folder. Step4: Configuration of save folder for server-side save -------------------------------------------------- This is to be done in fusioncharts_export.properties file. Make sure that the folder path that you specify has write permissions to it. I am facing problem while configuring <url-pattern>/JSP/ExportExample/FCExporter</url-pattern> As we are using Springs framework navigation to different pages were done via ModelView mapper that mean we use MVC . For generating the chart I use the following method public ModelViewMapper showBarchartReport(final HttpServletRequest request, final HttpServletResponse response) throws IOException { LOGGER.info("ReportsHandler:showBarchartReport:Enter"); // added for dynamic levels int inputHid1 = Integer.parseInt(request.getParameter("InputHid")); String inputHid = inputHid1 + ""; inputHid = inputHid.trim(); String startDate = ""; String endDate = ""; String sztimestamp = ReportsHandler.getServerTime(); startDate = (String) request.getParameter("startDate"); endDate = (String) request.getParameter("endDate"); try { if (inputHid != null) { ChartReportsImpl fimpl = new ChartReportsImpl(); String strxml = fimpl.generateChartReport(startDate, endDate, inputHid); XmlElement xmlElement = null; xmlElement = XmlElement.createXmlElement(strxml); xmlElement.setAttribute("caption"," Application Name: "+szApplicationName+ " Report Created On:- "+sztimestamp); int count = xmlElement.getCountByXPath("//set"); int i = 0; for (int j = 1; j <= count; j++) { String value = null; value = xmlElement.getElementByXPath( "//set[" + j + "]").getAttribute("value"); if (value.equals("")) { i++; //LOGGER.info("Val---" + i); } } if (i == count) { //LOGGER.info("counting for null--"); request.setAttribute("count", NO_RECORDS_FOUND); return new ModelViewMapper(RETURN_FAILURE); } else { String path = (String) request.getRealPath("/"); FileWriter fw = new FileWriter( new File(path + "/modular/swf/data/Column3D.xml")); strxml = xmlElement.getXmlString(); //added by sandeep strxml = strxml.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", ""); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(strxml)); Document doc = db.parse(is); NodeList nodeList; Element element; String label; nodeList = doc.getElementsByTagName("set"); for(int j=0; j< nodeList.getLength() ; j++) { element = (Element)nodeList.item(j); label = element.getAttribute("label"); if(label.equalsIgnoreCase("RESPONSE RECEIVED")) { element.getParentNode().removeChild(element); } } Element root = doc.getDocumentElement(); root.normalize(); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(doc); trans.transform(source, result); strxml = sw.toString(); LOGGER.info("**************** Bar chart XML test : **************"+strxml); //end of sandeep code. fw.write(strxml); fw.flush(); fw.close(); String szUserId = (String)request.getParameter("userid"); InputStream inputStream = getClass().getResourceAsStream("/properties/config.properties"); Properties properties = new Properties(); properties.load(inputStream); String path_attachments = properties.getProperty("attachment_location"); String path_zip = properties.getProperty("attachment_location_zip"); //String path_zip1=path_zip.substring(23,58); if(szUserId.length() > 0){ getBarChartAttachments(strxml); ReportsImpl reportsimpl = new ReportsImpl(); reportsimpl.sendEmail(szUserId, path_zip); /*File attachments = new File(path_attachments); String[] children = attachments.list(); boolean status = false; for (int f=0; f<children.length; f++) { status = new File(attachments, children[f]).delete(); } status = attachments.delete(); if(status){ File zip = new File(path_zip); status = zip.delete(); }*/ } } } else { LOGGER.info(RETURN_FAILURE); } } catch (Exception e) { LOGGER.error(" Exception in showBarchartReport : " , e); } request.setAttribute("reportstatus", RETURN_SUCCESS); LOGGER.info("ReportsHandler:showBarchartReport:Exit"); return new ModelViewMapper(RETURN_SUCCESS); } which would be present in one of java handler and when it returns status either success/ failure it is directed to some jsp pages my big quest is for this url-pattern what would be the rendering jsp to be placed in url_pattern? as when i specify the jsp which actually renders the chart i'm not able to export the report instead it pops up the window which was attached and when i try to open it i get the following message displayed instead of chart statusMessage= Insufficient data. Width/height not provided.Background Color not specified. Taking White (FFFFFF) as default background color. statusCode=0 width=0 height=0 DOMId=null Please help me out with this ASAP. Thanks in advance, Neeraja. Share this post Link to post Share on other sites
srividya_sharma Report post Posted July 2, 2011 See below post Share this post Link to post Share on other sites
srividya_sharma Report post Posted July 2, 2011 Hi Neeraja, Let me try to understand the problem first. 1. I understand that you have some xml document generation code. When this xml is provided to the chart, is the chart getting rendered in the first place? a. If chart is getting rendered, can you please share the generated xml? This can be obtained by either printing the xml document to a string or by turning on the debugMode in FusionCharts. b. else, if the chart itself is not rendering, we have to take a look at the view source of the html page. 2. If Chart is getting rendered, but export is not working, then a. Share the generated xml. Screen-shot / copy-paste of the debug window will also help. b. tell me the browser and FusionCharts version you are using. Lets take it from there. Srividya Sharma Share this post Link to post Share on other sites
neeraja Report post Posted July 6, 2011 (edited) Hi Srividya, That was a quick reply and i appriciate it. Sorry couldnt respond back sooner. Yes, the chart was getting rendered and i am attaching the screenshot and the xml which was generated so that we can move forward. Waiting for your reply. Thanks, Neeraja Meka. Pie3D.xml Edited July 6, 2011 by neeraja Share this post Link to post Share on other sites
srividya_sharma Report post Posted July 7, 2011 Hi Neeraja, As far as I can see, since you are using the FusionCharts Servlet export handler, you will have to configure the servlet mapping. Can you tell me which step in the export is failing, what is the output/error you are seeing on the screen? regards, Srividya Sharma Share this post Link to post Share on other sites
neeraja Report post Posted July 7, 2011 Hi Srividya, I basically have problem while configuring <servlet-mapping> as i am donot know what is the value to be substituted in <url-pattern> tag I mean to what jsp or servlet page i need to map this servlet (FCExporter) when defining it as a servlet in web.xml file. Thank you, Neeraja Meka. Share this post Link to post Share on other sites
srividya_sharma Report post Posted July 7, 2011 Hi Neeraja, Can you possibly share your web.xml or other configuration file where you have defined the HandlerServlet etc? Srividya Sharma Share this post Link to post Share on other sites
neeraja Report post Posted July 7, 2011 Sure, Please find the attached file. web.xml Share this post Link to post Share on other sites
srividya_sharma Report post Posted July 8, 2011 Hi Neeraja, I took a look at your web.xml. As you had mentioned earlier, the problem seems to be here: <servlet-mapping> <servlet-name>FCExporter</servlet-name> <url-pattern>/cgretail-reports/showPiechartReport.allfon</url-pattern> </servlet-mapping> Please note that the value that you provide to exportHandler attribute in the xml should be same as the value provided in the url-pattern. Only then, the chart will direct to the correct url for handling export. Please try to invoke the FCExporter servlet directly from the browser and the path that you use there will be the url-pattern or the exportHandler value. Hope this helps. regards, Srividya Sharma Share this post Link to post Share on other sites