コード例 #1
0
var sm = require ('service-metadata');

// Make the MPGW act as a loopback through the dotted notation
sm.mpgw.skipBackside = true;

// Set the service variables using the URL notation
sm.setVar('var://service/mpgw/skip-backside', true);

// Read the protocol method as a string using dotted notation
var method = sm.protocolMethod;  

// Read the protocol method as a string using the URL notation
method = sm.getVar ('var://service/protocol-method');

// Read the entire list of descriptors of variables using the list() method
var list = sm.list();
var descSkipBackside = list.filter(function(elm) {
    return elm.name === 'var://service/mpgw/skip-backside';
})[0];

session.output.write({
    method: method,
    descSkipBackSide: descSkipBackside
});
コード例 #2
0
// First, gather whatever information seems useful here. For instance,
// following gathers the information from protocol headers. You can also
// use session.input.readAsXXXX() methods to get the information from
// payload content.
var contentType = sm.getVar('var://service/original-content-type');
var protocol = sm.getVar('var://service/protocol');
var path = sm.getVar('var://service/URI');

// Then make a decision on the message type and trading partner IDs. If
// the variable var://service/b2b-doc-type is not set at document routing
// preprocessor stage, the document type will be autodetected from content
// payload and content-type header as appropriate (xml, x12, edifact,
// binary) to extract the b2b-partner-from and b2b-partner-to. For *binary*
// type message, this script must set partner variables, there is no way
// otherwise to determine their values.
if (protocol == 'dpmq') {
    // Messages received via MQ are binary, with fixed partner IDs
    sm.setVar('var://service/b2b-partner-from', '123456789');
    sm.setVar('var://service/b2b-partner-to', '987654321');
    sm.setVar('var://service/b2b-doc-type', 'binary');
} else if (protocol == 'http') {
    // Messages received via HTTP can derive partner IDs from headers
    sm.setVar('var://service/b2b-partner-from', hm.current.get ('X-Partner-From'));
    sm.setVar('var://service/b2b-partner-to', hm.current.get ('X-Partner-To'));
    sm.setVar('var://service/b2b-doc-type', 'binary');
} else {
    // By default, do nothing.  The B2B process will autodetect the
    // document type.
}