use of com.ibm.as400.access.ProgramParameter in project camel by apache.
the class Jt400PgmProducer method getParameterList.
private ProgramParameter[] getParameterList(Exchange exchange) throws InvalidPayloadException, PropertyVetoException {
Object body = exchange.getIn().getMandatoryBody();
Object[] params = (Object[]) body;
ProgramParameter[] parameterList = new ProgramParameter[params.length];
for (int i = 0; i < params.length; i++) {
Object param = params[i];
boolean input;
boolean output;
if (getISeriesEndpoint().isFieldIdxForOuput(i)) {
output = true;
input = param != null;
} else {
output = false;
input = true;
}
byte[] inputData = null;
// XXX Actually, returns any field length, not just output.
int length = getISeriesEndpoint().getOutputFieldLength(i);
if (input) {
if (param != null) {
AS400DataType typeConverter;
if (getISeriesEndpoint().getFormat() == Jt400Configuration.Format.binary) {
typeConverter = new AS400ByteArray(length);
} else {
typeConverter = new AS400Text(length, iSeries);
}
inputData = typeConverter.toBytes(param);
}
// Else, inputData will remain null.
}
if (input && output) {
LOG.trace("Parameter {} is both input and output.", i);
parameterList[i] = new ProgramParameter(inputData, length);
} else if (input) {
LOG.trace("Parameter {} is input.", i);
if (inputData != null) {
parameterList[i] = new ProgramParameter(inputData);
} else {
parameterList[i] = new ProgramParameter();
parameterList[i].setParameterType(ProgramParameter.PASS_BY_REFERENCE);
// Just for self documentation.
parameterList[i].setNullParameter(true);
}
} else {
// output
LOG.trace("Parameter {} is output.", i);
parameterList[i] = new ProgramParameter(length);
}
}
return parameterList;
}
use of com.ibm.as400.access.ProgramParameter 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.ProgramParameter 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