简体   繁体   中英

Error when converting to PDF using xsl

I am facing a strange problem when converting xml to pdf using xsl (java code creates xml and applies xsl at runtime).

The code is deployed on Jboss server. When the code is executed, it fails with the following error

    10:50:49,068 ERROR [stderr] (http--0.0.0.0-9080-3) Caused by: java.lang.reflect.InvocationTargetException

10:50:49,068 ERROR [stderr] (http--0.0.0.0-9080-3)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

10:50:49,069 ERROR [stderr] (http--0.0.0.0-9080-3)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

....

10:50:49,070 ERROR [stderr] (http--0.0.0.0-9080-3) Caused by: java.lang.StackOverflowError

10:50:49,070 ERROR [stderr] (http--0.0.0.0-9080-3)           at sun.misc.FloatingDecimal.dtoa(FloatingDecimal.java:532)

10:50:49,070 ERROR [stderr] (http--0.0.0.0-9080-3)           at sun.misc.FloatingDecimal.<init>(FloatingDecimal.java:459)

Below is the relevant Java code

public String transformWOCFormToPDF(IDfId xmlId,String folderId,String userName)throws DfException {    
 System.out.println("Preparing...");
 DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
 Date date= new Date();
 prop=readProperties();
 IDfSysObject pdfObject = (IDfSysObject)session.newObject("jh_exported_doc");
 System.out.println("object created");
 ByteArrayOutputStream pdfResult = new ByteArrayOutputStream();
 try  {
    System.out.println("in try");
    FopFactory fopFactory = FopFactory.newInstance();       
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();      
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,foUserAgent, pdfResult);
    System.out.println("fop object created");

    // Get the XSLT object from the docbase             
    IDfId objID = (IDfId) session.getIdByQualification("dm_document where object_name='"+ FORM_XSLT_OBJ_NAME + "'");
    System.out.println("Object ID created  "+objID.getId());
    IDfSysObject xsltObj = (IDfSysObject) session.getObject(objID);       

    // Get XSLT content as a stream
    Source xsltSrc = new StreamSource(xsltObj.getContent());
    System.out.println("xsltSrc is  --  "+xsltSrc.toString());
    // Create a new transformer for this style sheet 
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(xsltSrc);
    transformer.setParameter("versionParam", "1.0");

    IDfSysObject xmlObject = (IDfSysObject) session.getObject(xmlId);

       // Get xml content as a stream          
       Source xmlSrc = new StreamSource(xmlObject.getContent());
       System.out.println("Fetched xml source  "+xmlSrc.toString());
    // Setup input for XSLT transformation      

    // Resulting SAX events (the generated FO) must be piped through to FOP
    Result res = new SAXResult(fop.getDefaultHandler());
    System.out.println("res is -- "+res.toString());

    // Start XSLT transformation and FOP processing
    transformer.transform(xmlSrc, res);     

    System.out.println("size of pdf"+pdfResult.size());
    //IDfSysObject pdfObject = (IDfSysObject)session.newObject("dm_document");
    System.out.println("object created");
    pdfObject.setObjectName(FORM_PDF_OBJ_NAME+"_"+dateFormat.format(date)+"_"+userName);        
    pdfObject.setContentType("pdf");        
    pdfObject.setContent(pdfResult);    

    System.out.println("setting content");
    pdfObject.link(folderId);
    pdfObject.save();       
    System.out.println("path is "+pdfObject.getObjectId().toString());

} catch (Exception e) {
    System.out.println("Inside catch block");
    e.printStackTrace();
} finally {
    try {
        pdfResult.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
return pdfObject.getObjectId().getId();

}

It seems the error is coming at this point as println's before this are getting printed

transformer.transform(xmlSrc, res);

Below is the xml. Even though this is generated on the fly, I have copied it from logs and put it here for reference. Attached is the xslt as well.

<WOC_Form>
<Evaluators>
    <Evaluators>
        <department>Clinical Research</department>
        <evaluator_name>DISPNAME hod_clinicalres_user1</evaluator_name>
        <status>Accepted</status>
        <vested_interest>no</vested_interest>
        <doi_approver>N/A</doi_approver>
    </Evaluators>
    <Evaluators>
        <department>Allied Health Administration</department>
        <evaluator_name>DISPNAME hod_aha_user1</evaluator_name>
        <status>Accepted</status>
        <vested_interest>no</vested_interest>
        <doi_approver>N/A</doi_approver>
    </Evaluators>
</Evaluators>
<Attachments>
    <Attachments>
        <object_name>WOC_18-06-2015_hod_fammed_user1.pdf</object_name>
        <owner_name>DISPNAME woc_req_user1</owner_name>
        <r_creation_date>7/24/2015 11:58:09 AM</r_creation_date>
    </Attachments>
    <Attachments>
        <object_name>xCP 2.1 Sample Application - ICM 2.1.0.pdf</object_name>
        <owner_name>DISPNAME woc_buyer_user1</owner_name>
        <r_creation_date>7/24/2015 12:03:30 PM</r_creation_date>
    </Attachments>
</Attachments>
<requesting_department>Allied Health Administration</requesting_department>
<institutions>
    <institutions-value index="0">JH</institutions-value>
    <institutions-value index="1">JC</institutions-value>
    <institutions-value index="2">JR</institutions-value>
</institutions>
<vendoe_for_woc>erferewr</vendoe_for_woc>
<dh_ch_requesting_dept>DISPNAME hod_aha_user1</dh_ch_requesting_dept>
<total_waiver_of_competition>4433</total_waiver_of_competition>
<specialist_dept/>
<specialist_name/>
<is_approved_by_specialist>0</is_approved_by_specialist>
<description_of_goods_servic>dsfdsf</description_of_goods_servic>
<background>sdf</background>
<req_of_goods_or_services>sdfds</req_of_goods_or_services>
<proposals_from_vendors>sfdsf</proposals_from_vendors>
<negotiations_and_bafo>sdfsd</negotiations_and_bafo>
<calculation_of_contract_sum>ret</calculation_of_contract_sum>
<contract_period>ewte</contract_period>
<reason_request1>0</reason_request1>
<reason_request2>0</reason_request2>
<reason_request3>0</reason_request3>
<reason_request4>0</reason_request4>
<reason_request5>0</reason_request5>
<reason_request6>1</reason_request6>
<reason_request7>0</reason_request7>
<reason_request8>0</reason_request8>
<dh_ch_requesting_dept>DISPNAME hod_aha_user1</dh_ch_requesting_dept>
<dh_ch_approval_time>7/24/2015 12:00:50 PM</dh_ch_approval_time>
<specialist_name/>
<specialist_approval_time>nulldate</specialist_approval_time>
<mmd_manager_name>DISPNAME woc_mmd_mgr_user1</mmd_manager_name>
<mmd_mgr_approval_time>7/24/2015 12:07:09 PM</mmd_mgr_approval_time>
<finance_controller_name/>
<finance_controller_approval>nulldate</finance_controller_approval>

the strange part is that this whole thing works fine on 2 servers (VMs) but fails on another 2 servers (VMs) with the error mentioned above (each server is a separate VM with Jboss installed). All VMs are windows and have completely identical Jboss configuration.

I did some google search and found couple of potential reasons for this problem. One reason could be some recursive calls in the xslt which are resulting in stackoverflow error. However, why the transformation would work in other two VMs does not make sense. But then there is a possibility that there is difference in test data (which I am not able to catch) which is causing this recursive behavior. I have linked the xsl here, in case an xslt expert in the forum notices something drastically wrong with the xsl.

http://filedb.experts-exchange.com/incoming/2015/08_w32/927711/WOCFormXSLT.xsl

Second potential reason that I found was that there may not be enough Java memory allocated. The Jboss where this code is deployed has the following memory arguments

set USER_MEM_ARGS=-Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Xss256k -XX:+DisableExplicitGC -Xrs

set JAVA_OPTS=%USER_MEM_ARGS% -Djboss.server.base.dir=%JBOSS_BASE_DIR% -Duser.name=dmadmin

I have tried increasing -Xss from 256k to 1024k and 2048k but it did not help

set USER_MEM_ARGS=-Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Xss1024k -XX:+DisableExplicitGC -Xrs

set JAVA_OPTS=%USER_MEM_ARGS% -Djboss.server.base.dir=%JBOSS_BASE_DIR% -Duser.name=dmadmin

I am just creating a 2 page pdf so it should not need more momory than this. Moreover, the VMs where code is working, it works with the default settings, that is -Xss256k.

These VMs are clone of the same VM, so have completely identical Java and Jboss versions (and settings). I am not able to make out as to what could be the problem. Could it be something related to environment or something related to xslt code?

Any help would be highly appreciated as I have really hit the wall.

Thank you

The stacktrace shows a stackoverflow error inside FOP:

org.apache.fop.fo.flow.table.TableColumn.toString calling
org.apache.fop.fo.properties.PercentLength.toString(PercentLength.java:121) calling
org.apache.fop.datatypes.LengthBase.toString calling TableColumn toString

This is a clear sign of a bug inside FOP.

Here is a bug report which reports the same error and mentions a patched version of FOP which eliminates the error. Can you check your four servers - even if you they are all a clone of the same VM - if they really all run the same version of FOP?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM