Announcement

Collapse
No announcement yet.

Transformer Error on create PDF attachment code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transformer Error on create PDF attachment code

    Hi,
    I am migrating channel from Mirth 1.8 to 3.5.1 .
    I have a channel that creates pdf attachments and it started giving errors .
    I replaced messageObject with connectorMessage . still i am getting the following error.
    Transformer error
    ERROR MESSAGE: Error evaluating transformer
    com.mirth.connect.server.MirthJavascriptTransforme rException:
    CHANNEL: TDH_AP_REMIT_ADVICE_EMAILER_824
    CONNECTOR: sourceConnector
    SCRIPT SOURCE: TRANSFORMER
    SOURCE CODE:
    783: var fisTargetFile = new Packages.java.io.FileInputStream(new Packages.java.io.File(templateFilePath));
    784:
    785: var styleSheet = Packages.org.apache.commons.io.IOUtils.toString(fi sTargetFile);
    786:
    787: var replacer = new com.mirth.connect.server.util.TemplateValueReplace r;
    788: var template = replacer.replaceValues(styleSheet, connectorMessage);
    789:
    790: // create w3 document and import stylesheet
    791: var builder = new DocumentBuilderFactory.newInstance().newDocumentBu ilder();
    792: var buf = new StringBufferInputStream(template.toString());
    LINE NUMBER: 788
    DETAILS: Can't find method com.mirth.connect.server.util.TemplateValueReplace r.replaceValues(java.lang.String,com.mirth.connect .userutil.ImmutableConnectorMessage).
    at ae2dc56b-4c14-40ec-aa55-05b424d9b742:788 (doTransform)
    at ae2dc56b-4c14-40ec-aa55-05b424d9b742:830 (doScript)
    at ae2dc56b-4c14-40ec-aa55-05b424d9b742:832
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    ----------------------------------------------------------------

    Here is the code i am using in transformer.
    ...

    importPackage(Packages.javax.xml.parsers);
    importPackage(Packages.org.w3c.dom);
    importPackage(Packages.java.io);

    var templateFilePath = 'E:\\Program Files\\velocity\\remit_advice_slip.html';
    var fisTargetFile = new Packages.java.io.FileInputStream(new Packages.java.io.File(templateFilePath));

    var styleSheet = Packages.org.apache.commons.io.IOUtils.toString(fi sTargetFile);

    var replacer = new com.mirth.connect.server.util.TemplateValueReplace r;
    var template = replacer.replaceValues(styleSheet, connectorMessage);

    // create w3 document and import stylesheet
    var builder = new DocumentBuilderFactory.newInstance().newDocumentBu ilder();
    var buf = new StringBufferInputStream(template.toString());
    //var buf = new ByteArrayInputStream(template.toString().getBytes( ));
    var document = builder.parse(buf);

    // create pdf from html
    var renderer = new Packages.org.xhtmlrenderer.pdf.ITextRenderer;
    renderer.setDocument(document,null);
    renderer.layout();

    var PDF = new ByteArrayOutputStream();

    renderer.createPDF(PDF,true);

    var encDocument = FileUtil.encode(PDF.toByteArray());

    channelMap.put('PDFencoded',encDocument);
    // encDocument has the base64 encoded PDF file, ready to store in SQL database



    Thanks.
    AJ

  • #2
    replacer.replaceValues(styleSheet, connectorMessage);

    This is causing your error. I am not aware of this function. So, it may be a user defined function that has not been moved over. Or, with going from 1.8 to 3.5, there is a good possibility that it has become deprecated.

    Comment


    • #3
      This is the working code in 1.8
      ...............
      importPackage(Packages.javax.xml.parsers);
      importPackage(Packages.org.w3c.dom);
      importPackage(Packages.java.io);


      var templateFilePath = 'c:\\Program Files\\Mirth\\lib\\extensions\\velocity\\remit_adv ice_slip.html';
      var fisTargetFile = new Packages.java.io.FileInputStream(new Packages.java.io.File(templateFilePath));

      var styleSheet = Packages.org.apache.commons.io.IOUtils.toString(fi sTargetFile);

      var replacer = new Packages.org.mule.providers.TemplateValueReplacer;
      var template = replacer.replaceValues(styleSheet, messageObject);

      // create w3 document and import stylesheet
      var builder = new DocumentBuilderFactory.newInstance().newDocumentBu ilder();
      var buf = new StringBufferInputStream(template.toString());
      //var buf = new ByteArrayInputStream(template.toString().getBytes( ));
      var document = builder.parse(buf);

      // create pdf from html
      var renderer = new Packages.org.xhtmlrenderer.pdf.ITextRenderer;
      renderer.setDocument(document,null);
      renderer.layout();

      var PDF = new ByteArrayOutputStream();

      renderer.createPDF(PDF,true);

      var encDocument = FileUtil.encode(PDF.toByteArray());

      channelMap.put('PDFencoded',encDocument);
      // encDocument has the base64 encoded PDF file, ready to store in SQL database

      Comment


      • #4
        When I remove 'connectorMessage' from line 788 . The Pdf is getting generated without error but without the content .

        Comment


        • #5
          I think that mule as been removed. Take a look at this page...

          https://github.com/nextgenhealthcare...eValueReplacer

          Comment


          • #6
            You actually don't need to create replacer yourself. Mirth already has a variable named replacer in the default context that is an instance of TemplateValueReplacer.

            The issue is that it wants a ConnectorMessage, but you are passing in an ImmutableConnectorMessage, which is actually not a subclass, but a wrapper instead.

            You could instead use the replaceValues(template, channelId, map) method and pass the relevant map (channel?) like
            Code:
            var template = replacer.replaceValues(styleSheet, channelId, channelMap);
            If you need values from multiple maps, you can build a new one with the ones you need. Make sure you add them in the correct order. The configurationMap, globalMap, and globalChannelMap should already be included for you from passing the channelId.
            Code:
            var replacerMap = new java.util.HashMap();
            replacerMap.putAll(sourceMap);
            replacerMap.putAll(connectorMap);
            replacerMap.putAll(channelMap);

            Comment


            • #7
              Thank you so much . This resolved my issue .

              Comment

              Working...
              X