Perl Client Jasper Reports Web Service

0
First off, I'm new to both Jasper Reports and Web services. I'm trying to create a web service that will send back a file to my Perl client. I'm having some issues getting it to work. I was wondering if anyone knew the best way to send a file a Perl client? I'm currently testing with a SOAP java web service that is supposed to send back a byte array. I know byte arrays use alot of memeory so I have been looking into Datahandlers and Servlets but I havn't found anything that will send back the file to my client without an error. Any help would be apperciated. I'm passing in XML data as a string to the service.
 
 
JAVA WEB SERVICE CODE-----------------------------------------------------------------------------------------
 
public byte[] sendBack(String sourceData){
   
   String path = "C:/testing/";
   JasperReport jasperReport;
   JasperPrint jasperPrint;
   JRXmlDataSource xmlDataSource;
   ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
   
   
   try{
         
    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance()
                        .newDocumentBuilder();
 
    Document doc = dBuilder.parse(sourceData);
        
   xmlDataSource = new JRXmlDataSource(doc,"/Foo/Bar");
   
   
   String templateName = path + "foobar.jrxml";  //JRXML template path 
   jasperReport = JasperCompileManager.compileReport(templateName);
   HashMap parameters = new HashMap();
   jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, xmlDataSource);
   JasperExportManager.exportReportToPdfStream(jasperPrint,byteArrayOutputStream);
   byte[] d = byteArrayOutputStream.toByteArray();
 
    return d;
    
    
    }catch(Exception e){  
       System.out.println(e);  
    }
return null; 
}
-----------------------------------------------------------------------------------------------
 
PERL CLIENT CODE
 
use Data::Dumper;
use File::Slurp;
use strict;
use warnings;
use SOAP::Lite;
 
 
print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<title>Print Page</title>\n";
print "</head>\n";
print "<body><h1><b>Printing</b></h1>\n";
 
my $xmlString = read_file('TESTDATASOURCE.xml');
 
my $line = $xmlString;
{
   $line =~ s/\t+//g; #strip all tabs
   $line =~ s/\n+//g; #strip all new lines
    
}
 
my $client = SOAP::Lite->new();
my $result = $client->sendBack($line);
 
my $pdf_data = $result;
open my $ofh, '>:raw', 'output.pdf'
    or die "Could not write: $!";
print {$ofh} $pdf_data;
close $ofh;
 
print "</body></html>";
 
exit(0);  
 

 

benjamin.hester4's picture
Joined: Mar 20 2014 - 6:19am
Last seen: 4 years 8 months ago

0 Answers:

No answers yet
Feedback
randomness