Custom
There may be cases where neither Model-based nor MDL processing is suitable for processing a certain type of message. In this case, you can provide a Custom processor that does all of the work of handling the inbound data.
In this case, the inbound interface format is purely informational and can be omitted if desired.
To implement your custom interface, you need to create a java class that extends AbstractInboundProcessor (or directly implements com.onenetwork.platform.integ.msg.InboundProcessor). A sample is provided below.
import
java.io.*;
import
com.onenetwork.platform.common.usercontext.PlatformUserContext;
import
com.onenetwork.platform.grid.GridTaskContext;
import
com.onenetwork.platform.integ.msg.AbstractInboundProcessor;
import
com.onenetwork.platform.integ.msg.Message;
import
com.onenetwork.platform.tools.io.Streams;
import
com.onenetwork.platform.tools.log.PlatformLogger;
public
class
SampleCustomInboundProcessor
extends
AbstractInboundProcessor {
private
static
PlatformLogger LOG = PlatformLogger.get(SampleCustomInboundProcessor.
class
);
@Override
public
void
processMessage(Message msg, GridTaskContext gridCtx, File fileForErrors, PlatformUserContext ctx)
throws
Exception {
InputStream in =
null
;
OutputStream out =
null
;
try
{
in = msg.readPayload();
LOG.info(
"Will process message "
+ msg.getId());
String contents = Streams.readFully(
new
InputStreamReader(in));
// Here you would do something with the contents, e.g. parse XML
// and write to database.
// Capture any errors during process in a fileForErrors
String errors =
"These are the processing errors I captured"
;
out =
new
FileOutputStream(fileForErrors);
Streams.transfer(
new
ByteArrayInputStream(errors.getBytes()), out);
}
finally
{
Streams.close(in, out);
}
}
}