Search in sources :

Example 1 with ProgramCall

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));
    }
}
Also used : ProgramParameter(com.ibm.as400.access.ProgramParameter) ProgramCall(com.ibm.as400.access.ProgramCall)

Example 2 with ProgramCall

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);
}
Also used : ProgramParameter(com.ibm.as400.access.ProgramParameter) AS400Text(com.ibm.as400.access.AS400Text) ArrayList(java.util.ArrayList) AS400DataType(com.ibm.as400.access.AS400DataType) AS400ByteArray(com.ibm.as400.access.AS400ByteArray)

Aggregations

ProgramParameter (com.ibm.as400.access.ProgramParameter)2 AS400ByteArray (com.ibm.as400.access.AS400ByteArray)1 AS400DataType (com.ibm.as400.access.AS400DataType)1 AS400Text (com.ibm.as400.access.AS400Text)1 ProgramCall (com.ibm.as400.access.ProgramCall)1 ArrayList (java.util.ArrayList)1