Announcement

Collapse
No announcement yet.

Trying to Understand JAVA Code Output

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

  • Trying to Understand JAVA Code Output

    I am fairly new to Mirth and recently setup a Mirth service on a VM I am running. I am trying to understand some of the JAVA code used in Mirth. I placed the following code on a destination transformer of a channel that was setup to pick up a file and move it to another folder. It is a PDF file if you need to know that. The move works but then I was trying to do some manipulation of the data through JAVA I was having some issue getting the data into a variable and working with it.

    Code:
        var pdfString = new String;
        var tiff = getAttachments().get(0).getContent();
        pdfString = getAttachments().get(0);
        logger.info(pdfString)
        pdfString = FileUtil.decode(new java.lang.String(getAttachments().get(0).getContent()));
        logger.info(pdfString)
        pdfString = getAttachments();
        logger.info(pdfString)
     
    	tiff = FileUtil.decode(new java.lang.String(tiff));
    	logger.info(tiff);
    	tiff = getAttachments().get(0).getContent();
    	pdfString = getAttachments().get(0);
        logger.info(pdfString)
        pdfString = FileUtil.decode(new java.lang.String(getAttachments().get(0).getContent()));
        logger.info(pdfString)
        pdfString = getAttachments();
        logger.info(pdfString)
     
    	tiff = FileUtil.decode(new java.lang.String(tiff));
    	logger.info(tiff);
    I didn't understand what was being displayed in the log output and it made it even more confusing when I did the exact same code twice as I got two different sets of output. Can someone maybe explain what I am seeing in the log(see below) and why when I run the same exact code twice I get different outputs in the log.


    INFO 2019-11-19 11:19:10,027 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [email protected] b0
    INFO 2019-11-19 11:19:10,039 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [[email protected]
    INFO 2019-11-19 11:19:10,041 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [[email protected] 08]
    INFO 2019-11-19 11:19:10,050 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [[email protected]
    INFO 2019-11-19 11:19:10,052 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [email protected] 52
    INFO 2019-11-19 11:19:10,058 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [[email protected]
    INFO 2019-11-19 11:19:10,059 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [[email protected] 9]
    INFO 2019-11-19 11:19:10,060 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [[email protected]
    Shouldn't the .getContent() be a text representation of the PDF document? I might be misunderstanding what that should be returning exactly.

  • #2
    This should actually be in the support forum, not development, but I'll try to answer a few of your questions.

    getAttachments().get(0) returns an instance of com.mirth.connect.server.userutil.Attachment, which is documented in the User API.

    getAttachments().get(0).getContent() returns a byte[], which is the binary representation of the base64 encoding of your pdf file.

    FileUtil.decode(new java.lang.String(getAttachments() .get(0).getContent())) returns a byte[], which is the binary representation of your pdf file.

    If you were to then convert that to a string, it would be like opening the pdf file in a text editor.

    Here's a code template that might help you https://github.com/nextgenhealthcare...t%20From%20PDF

    Comment

    Working...
    X