use of com.ibm.as400.access.ProgramCall in project camel by apache.
the class Jt400PgmProducer method process.
public void process(Exchange exchange) throws Exception {
String commandStr = getISeriesEndpoint().getObjectPath();
ProgramParameter[] parameterList = getParameterList(exchange);
ProgramCall pgmCall = new ProgramCall(iSeries);
pgmCall.setProgram(commandStr);
pgmCall.setParameterList(parameterList);
if (LOG.isDebugEnabled()) {
LOG.trace("Starting to call PGM '{}' in host '{}' authentication with the user '{}'", new Object[] { commandStr, iSeries.getSystemName(), iSeries.getUserId() });
}
boolean result = pgmCall.run();
if (LOG.isTraceEnabled()) {
LOG.trace("Executed PGM '{}' in host '{}'. Success? {}", new Object[] { commandStr, iSeries.getSystemName(), result });
}
if (result) {
handlePGMOutput(exchange, pgmCall, parameterList);
} else {
throw new Jt400PgmCallException(getOutputMessages(pgmCall));
}
}
use of com.ibm.as400.access.ProgramCall in project camel by apache.
the class Jt400PgmProducer method handlePGMOutput.
private void handlePGMOutput(Exchange exchange, ProgramCall pgmCall, ProgramParameter[] inputs) throws InvalidPayloadException {
Object body = exchange.getIn().getMandatoryBody();
Object[] params = (Object[]) body;
List<Object> results = new ArrayList<Object>();
int i = 1;
for (ProgramParameter pgmParam : pgmCall.getParameterList()) {
byte[] output = pgmParam.getOutputData();
Object javaValue = params[i - 1];
if (output != null) {
int length = pgmParam.getOutputDataLength();
AS400DataType typeConverter;
if (getISeriesEndpoint().getFormat() == Jt400Configuration.Format.binary) {
typeConverter = new AS400ByteArray(length);
} else {
typeConverter = new AS400Text(length, iSeries);
}
javaValue = typeConverter.toObject(output);
}
results.add(javaValue);
i++;
}
Object[] bodyOUT = new Object[results.size()];
bodyOUT = results.toArray(bodyOUT);
exchange.getOut().setBody(bodyOUT);
}
Aggregations