One way to get XML files into InterFormNG is to let the InterFormNG monitor a message queue for entries. Below it is described how you can set that up:
First you need to tell InterForm400 to start to monitor a message queue. To do that you open the InterFormNG web interface and select Input, Message queue:
Change Active to Yes. Now save the change and restart the processor service.
InterFormNG is now using an embedded MessageMQ. It is possible for other programs to access it on port 61616.
If you are using an external ActiveMQ, you'll have to change the Broker URL.
The default for ActiveMQ is tcp://localhost:61616.
When using an external message queue it might be a good idea to let the InterFormNG Document Processing Service depend on it.
Execute the following command as Administrator
sc config InterFormNGProcessor depend= Spooler/ActiveMQ
Now InterFormNG service is dependent on ActiveMQ
Now starting the InterFormNG processor service, will also start ActiveMQ and stopping ActiveMQ will also stop the InterFormNG processor service.
Using a message queue with InterFormNG is standard JMS.
It doesn't matter if you use plain Java or a framework like Spring or Camel.
For simplicity I'll use Camel.
InterFormNG will use the queue interform.xmlProcessingRequestQueue and the JMS message type javax.jms.BytesMessage.
For InterFormNG an XML-file coming via a message queue is no different form an XML coming from the filesystem.
If workflow is disabled, the default template will be used (System Configurations > General System Settings).
If workflow is enabled, the first rule where the conditions matches will be used (Workflow Configurations > Template Selections).
The simplest possible scenarie is to send the XML-data only.
But you can add headers to control the processing.
All InterFormNG metadata is prefixed with the string "x-interform-metadata-" and to make Camel unescape the "-" I've added jmsKeyFormatStrategry=passthrough to the endpoint.
Pom.xml:
<?xml version="1.0"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.interforn400</groupId>
<artifactId>messagequeue</artifactId>
<version>0.0.1-SNAPSHOT</version>
-<dependencies>
-<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.9.0</version>
</dependency>
</dependencies>
</project>
x-interform-metadata-mediaType archive, email or print
x-interform-metadata-documentType all the usual metadata
for archive, email and
x-interform-metadata-com.interform400.xml.Template which template to use
x-interform-metadata-xmlFromSocket skip final step - only
create artifact, but
don't save, mail or
x-interform-metadata-interform.printjob.processingpriority 0=Immediate, 1=Normal,
2=Batch
x-interform-metadata-interform.plugin.integration.folderName where to store temporary
files
The MQDemo.java source:
package com.interform400.messagequeue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
public class MQDemo {
public static void main(String[] args) throws Exception {
String url = "tcp://localhost:61616";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
CamelContext context = new DefaultCamelContext();
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
ProducerTemplate producer = context.createProducerTemplate();
String endpoint = "jms:queue:interform.xmlProcessingRequestQueue?jmsKeyFormatStrategy=passthrough";
String body = "<xml/>"; // or get input data from an XML-file
Map<String, Object> headers = new HashMap<String, Object>() {
{
put("x-interform-metadata-mediaType", "archive"); // archive, email or print
put("x-interform-metadata-documentType", "postscript"); // all the usual metadata for archive,email and print
put("x-interform-metadata-com.interform400.xml.Template", "Pangrams.itpl"); // which template to use
put("x-interform-metadata-xmlFromSocket", "__XML_FROM_SOCKET__");
// skip final step - only create artifact, but don't save, mail or print
put("x-interform-metadata-interform.printjob.processingpriority", "2");
// 0=Immediate, 1=Normal, 2=Batch
put("x-interform-metadata-interform.plugin.integration.folderName", "C:/ProgramData/InterFormNG/temp2");
// where to store temporary files
}
};
byte[] result = (byte[]) producer.requestBodyAndHeaders(endpoint, body.getBytes(), headers);
// the generated artifact is returned
File pdfFile = File.createTempFile("MQDemo", ".pdf"); // change extension to match MIME-type of the returned artifact
OutputStream os = new FileOutputStream(pdfFile);
os.write(result);
os.close();
Runtime.getRuntime().exec(new String[] { "rundll32", "url.dll,FileProtocolHandler", pdfFile.getAbsolutePath() });
System.exit(0);
}
}