Error converting to PDF using xsl

I got a weird problem while converting xml to pdf using xsl (java code creates xml and applies xsl at runtime).

The code is deployed to the 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 that the error occurs at this point, since println is being printed before

transformer.transform(xmlSrc, res);

      

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

<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 weird part is that it all works fine on two servers (VM), but crashes on the other 2 servers (VM) with the above error (each server is a separate VM with Jboss installed). All virtual machines are windows and have a completely identical Jboss configuration.

I went through google and found a couple of potential causes for this problem. One reason might be some recursive calls in xslt that lead to stackoverflow error. However, why the conversion would work in the other two virtual machines doesn't make sense. But then there is a chance that there is a difference in the test data (which I cannot grasp) that is causing this recursive behavior. I linked the xsl here, in case an xslt expert on the forum notices something completely wrong with the xsl.

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

The second potential reason I've found is that there might be insufficient Java memory allocated. 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 tried to increase -Xss from 256k to 1024k and 2048k but it didn't 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 just create a 2 page PDF so it doesn't need more momory than this. Moreover, the virtual machines where the code is running work with the default settings, i.e. -Xss256k.

These virtual machines are clones of the same virtual machine, therefore they have completely identical Java and Jboss versions (and settings). I can't figure out what the problem might be. Maybe it has something to do with the environment or something related to the xslt code?

Any help would be much appreciated as I did hit the wall.

thank

+3


source to share


1 answer


The stack 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 an error inside FOP.

Here is a bug report that reports the same bug and mentions a fixed version of FOP that fixes the bug. Can you test your four servers - even if they are all clones of the same virtual machine - if they are indeed all running the same version of FOP?

+1


source







All Articles