tags:

views:

730

answers:

3

I'm not familiar with ASP, but am helping someone out with their website as a side project. I am trying to call Apache FOP (a java application) from ASP using VB. I have seen simple examples using the GetObject('java:...') constuct, but I don't know how to pass and retrieve binary data from a java object.

Ideally, I would do this all in memory--I would prefer to not have to write my data to disk, call FOP on that file (which will read, and then write a new file), and then re-read the data off of disk. The site isn't that busy so I could do this, but it just doesn't seem efficient.

+1  A: 

I wouldn't worry about efficiency until I had observed a problem and measurements told me that the FOP solution was the culprit.

I'd propose an asynch call to a web service. Sent a message containing the XML input stream and the XSL-T stylesheet. Have the service write the PDF to its local disk. Add a mailbox to your UI to alert users when the PDF was ready to be picked up. Click on the link, and the PDF is streamed to the browser. The user can view or save to their local disk as they wish.

Asynch is good in this case because you don't know how long the transform might take. Why make the user wait? Let them check back later. An AJAX call to check for the new PDF would be elegant.

duffymo
That's a bit more complex than we need for this application. Just need to create a pdf of a work order and email a copy to the requestor. Would like to do this with minimal hardware, etc.No need to kill an ant with a cannon.
molson
A: 

I figured out a workaround. This is for IIS running on a Win 2k3 Server--older versions will be much easier.

First I created a subdirectory off the main site (for security purposes) and attached a new application pool to that directory. The new application pool needs to run as Local System. I couldn't get fop.bat to work, even running as local system, but I could call java, so I put the entire fop commandline into my asp script, similar to this snippet:

Dim shell, foppath, workpath
Set shell = Server.CreateObject("WScript.Shell")

foppath = Server.MapPath("/fop/")
workpath = Server.MapPath("/tmp/")
shell.CurrentDirectory = foppath

Dim commandline
commandline = "java -Denv.windir=C:\WINDOWS   -cp """
'set classpath
commandline = commandline & foppath & "\build\fop.jar;"
commandline = commandline & foppath & "\build\fop-sandbox.jar;"
commandline = commandline & foppath & "\build\fop-hyph.jar;"
commandline = commandline & foppath & "\lib\xml-apis-1.3.04.jar;"
commandline = commandline & foppath & "\lib\xml-apis-ext-1.3.04.jar;"
commandline = commandline & foppath & "\lib\xercesImpl-2.7.1.jar;"
commandline = commandline & foppath & "\lib\xalan-2.7.0.jar;"
commandline = commandline & foppath & "\lib\serializer-2.7.0.jar;"
commandline = commandline & foppath & "\lib\batik-all-1.7.jar;"
commandline = commandline & foppath & "\lib\xmlgraphics-commons-1.3.1.jar;"
commandline = commandline & foppath & "\lib\avalon-framework-4.2.0.jar;"
commandline = commandline & foppath & "\lib\commons-io-1.3.1.jar;"
commandline = commandline & foppath & "\lib\commons-logging-1.0.4.jar;"
commandline = commandline & foppath & "\lib\jai_imageio.jar;"
commandline = commandline & foppath & "\lib\fop-hyph.jar;"
commandline = commandline & """ org.apache.fop.cli.Main "
commandline = commandline & workpath & "/file.fo "
commandline = commandline & workpath & "/file.pdf "

Dim ResultCode
ResultCode = Shell.Run(commandline,,True) ' True = Wait for FOP to finish

Afterwards, I make sure I cleanup my temp files, etc. Perhaps not the most elegant solution, but given the need, I'm sure it will work for a long time.

molson
A: 

how do you add the config file -c conf\fop.xconf or -c C:\fop\conf\fop.xconf to the above excellent piece of work

ta!

Ian