web stats
send a pdf as response - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2009, 06:14 AM
supertoms supertoms is offline
Mirth Newb
 
Join Date: Jul 2007
Location: Monza, Italy
Posts: 16
supertoms
Default send a pdf as response

I wish to send back as channel response, a generated document.
As seen around the forum, I created the pdf destination and using a postProcessor script I tried to send it back.
Code:
logger.info('http test- MID '+messageObject.getId());
var contents = FileUtil.readBytes('/tmp/http-test/'+channelMap.get('MESSID')+'.pdf');
var encData=FileUtil.encode(contents);
var resp= 'application/pdf;base64,'+encData
responseMap.put('pdf resp',  ResponseFactory.getSuccessResponse(resp));
return;
The result is I can see the base64 code, not the pdf file. Same thing using FileUtil.read() to read the pdf as a string and sending it as is, without encoding.
Should Some suggest anything?
Thank you.
Reply With Quote
  #2  
Old 01-04-2010, 05:32 AM
csmith csmith is offline
OBX.2 Kenobi
 
Join Date: Mar 2009
Posts: 57
csmith is an unknown quantity at this point
Default

Hi supertoms,

Did you have any luck figuring this out? I'm having the same problem using version 1.8.1.4211

Could it be that Mirth doesn't allow us to change the headers?

Thanks!

Last edited by csmith; 01-04-2010 at 09:59 AM. Reason: more info
Reply With Quote
  #3  
Old 01-07-2010, 12:11 AM
supertoms supertoms is offline
Mirth Newb
 
Join Date: Jul 2007
Location: Monza, Italy
Posts: 16
supertoms
Default

Hi.
I've tried without success.
I can't control the mime type of returned file. The browser still handl it as text or html.
I've also tried to included the returned object into an html page, selecting the correct mime type but without success.
Reply With Quote
  #4  
Old 01-07-2010, 08:35 AM
josealmeida josealmeida is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Portugal
Posts: 28
josealmeida is on a distinguished road
Default

see the 4th post in this thread to see if it helps:

http://www.mirthcorp.com/community/f...ead.php?t=3372

I used a postProcessor javascript with that code.

Last edited by josealmeida; 01-07-2010 at 08:39 AM.
Reply With Quote
  #5  
Old 01-08-2010, 07:55 AM
supertoms supertoms is offline
Mirth Newb
 
Join Date: Jul 2007
Location: Monza, Italy
Posts: 16
supertoms
Default

Thanks for suggestions, but the problem is still open.
I've an http source that receive Response from "pdf resp", a responseMap value declared.
My postprocess script is:
Code:
logger.info('http test- MID '+messageObject.getId());
logger.info('file '+'/tmp/http-test/'+channelMap.get('MESSID')+'.pdf');
var contents = FileUtil.readBytes('/tmp/http-test/'+channelMap.get('MESSID')+'.pdf');
logger.info('encode');
var encData=FileUtil.encode(contents);
//remove the newlines to produce valid Base64
var index = encData.indexOf("\r\n");
    while(index != -1){
        encData = encData.replace("\r\n","");
        index = encData.indexOf("\r\n");
    }
var resp=encData;
responseMap.put('pdf resp',  ResponseFactory.getSuccessResponse(resp));
return;
Obviouslly I've a destination channel who create a pdf.
In this way, calling http://myserver:8083/?testType=httpTestMirth&value=56
I can see the text data of my pdf on my browser. The returned page generated is a text/html page not pdf.
Reply With Quote
  #6  
Old 01-08-2010, 09:20 AM
dans dans is offline
Mirth Employee
 
Join Date: Apr 2007
Location: Irvine, CA
Posts: 590
dans is an unknown quantity at this point
Default

supertoms: yes, the returned data is text since it is base64 encoded. Decode the data and you have your pdf document.
__________________
Daniel Svanstedt
Software Engineer
Mirth Corporation

Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!
Reply With Quote
  #7  
Old 01-14-2010, 10:07 AM
csmith csmith is offline
OBX.2 Kenobi
 
Join Date: Mar 2009
Posts: 57
csmith is an unknown quantity at this point
Default

Hi,

I've been trying to develop a test channel which listens for an http request and returns a pdf to the client's browser.

Here's what I have as a postprocessor script:
************************************************** **************************
var contents = FileUtil.readBytes('/var/www/test.pdf');
var encData=FileUtil.encode(contents);
var index = encData.indexOf("\r\n");
while(index != -1){
encData = encData.replace("\r\n","");
index = encData.indexOf("\r\n");
}
var resp=FileUtil.decode(encData);
resp = 'application/pdf,' + resp;
responseMap.put('pdf resp', ResponseFactory.getSuccessResponse(resp));
return;
************************************************** ***********************************
When I prompt the channel thusly http://xxxxxx:8111 (the port being configured
in the Source), the expected pdf isn't returned, but, rather, a bunch of characters.
No errors are logged by the server.

I'm using MirthConnect version 1.8.1.4211

Any insights would be hugely appreciated (as always)!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:58 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation