从Java调用AS400 RPG程序



我正在尝试在Java的AS400系统上调用RPG登录程序。问题是,每当我提供错误的参数时,我都会得到响应,例如用户ID不正确,密码不正确。当我为程序提供不正确的途径时,我确实会得到响应,说"对象不存在"。但是,当所有参数都是正确的时,我没有得到任何响应,而Java程序则在不结束的情况下继续运行。怎么了?下面的代码:

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.ErrorCompletingRequestException;
import com.ibm.as400.access.ObjectDoesNotExistException;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;
import java.beans.PropertyVetoException;
import java.io.IOException;
/**
 * Test program to test the RPG call from Java.
 */
public class CallingAS400PGM {
    private static final String HOST = "xxxxxx";
    private static final String UID = "yyyyyyy";
    private static final String PWD = "zzzzzzz";
    public static void main(String[] args) {
        String input = "testuser";
        String fullProgramName = "/QSYS.lib/SEOBJP10.lib/LOGON.pgm";
        AS400 as400 = null;
        byte[] inputData;
        byte[] outputData;
        ProgramParameter[] parmList;
        ProgramCall programCall;
        try {
            // Create an AS400 object
            as400 = new AS400(HOST, UID, PWD);
            // Create a parameter list
            // The list must have both input and output parameters
            parmList = new ProgramParameter[2];
            // Convert the Strings to IBM format
            inputData = input.getBytes("IBM285");
            // Create the input parameter  
            parmList[0] = new ProgramParameter(inputData);
            // Create the output parameter
            //Prarameterised Constructor is for the OUTPUT LENGTH. here it is 10
            parmList[1] = new ProgramParameter(10);
            /**
             * Create a program object specifying the name of the program and
             * the parameter list.
             */
            programCall = new ProgramCall(as400);
            programCall.setProgram(fullProgramName, parmList);
            // Run the program.  
            if (!programCall.run()) {
                /**
                 * If the AS/400 is not run then look at the message list to
                 * find out why it didn't run.
                 */
                AS400Message[] messageList = programCall.getMessageList();
                for (AS400Message message : messageList) {
                    System.out.println(message.getID() + " - " + message.getText());
                }
            } else {
                /**
                 * Else the program is successfull. Process the output, which
                 * contains the returned data.
                 */
                System.out.println("CONNECTION IS SUCCESSFUL");
                outputData = parmList[1].getOutputData();
                String output = new String(outputData, "IBM285").trim();
                System.out.println("Output is " + output);
            }
        } catch (PropertyVetoException | AS400SecurityException | ErrorCompletingRequestException | IOException | InterruptedException | ObjectDoesNotExistException e) {
            System.err.println(":: Exception ::" + e.toString());
        } finally {
            try {
                // Make sure to disconnect 
                if (as400 != null) {
                    as400.disconnectAllServices();
                }
            } catch (Exception e) {
                System.err.println(":: Exception ::" + e.toString());
            }
        }
    }
}

仔细考虑哪种参数类型,参数数量正在接受AS400 RPG程序,并仅使用Communication userId。

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;
public class CallingAS400PGM {
private static final String HOST = "192.168.1.1";//AS400 IP
private static final String UID = "UNAME"; //userid
private static final String PWD = "PWORD"; //password
public static void main(String[] args) {
//AS400 RPG progam path
String fullProgramName = "/QSYS.LIB/PBFORM12.LIB/PBFORM12CL.PGM";
AS400 as400 = null;
ProgramParameter[] parmList;//parameter list witch is accepting AS400 RPG program
ProgramCall programCall;
try {
    // Create an AS400 object
    as400 = new AS400(HOST, UID, PWD);
    // Create a parameter list
    // The list must have both input and output parameters
    parmList = new ProgramParameter[2];
    // Convert the Strings to IBM format
    AS400Text nametext1 = new AS400Text(2);
    AS400Text nametext2 = new AS400Text(200);
    // Create the input parameter // get the exact patameter type and 
    length, if not this not be working  
    parmList[0] = new ProgramParameter(nametext1.toBytes("1"),2);
    parmList[1] = new ProgramParameter(nametext2.toBytes("Ravinath 
    Fernando"),200);
    // Create the output parameter
    programCall = new ProgramCall(as400);
    programCall.setProgram(fullProgramName, parmList);
    if (!programCall.run()) {
        /**
         * If the AS/400 is not run then look at the message list to
         * find out why it didn't run.
         */
        AS400Message[] messageList = programCall.getMessageList();
        for (AS400Message message : messageList) {
            System.out.println(message.getID() + " - " + message.getText());
        }
    } else {
        System.out.println("success");
        /**
         * Else the program is successfull. Process the output, which
         * contains the returned data.
         */
        //use same parameter type which will be return from AS400 program
        AS400Text text1 = new AS400Text(2);
        System.out.println(text1.toObject(parmList[0].getOutputData()));
        AS400Text text2 = new AS400Text(200);
        System.out.println(text2.toObject(parmList[1].getOutputData()));
    }
    as400.disconnectService(AS400.COMMAND);
    //-----------------------
} catch (Exception e) {
    e.printStackTrace();
    System.err.println(":: Exception ::" + e.toString());
} finally {
    try {
        // Make sure to disconnect 
        if (as400 != null) {
            as400.disconnectAllServices();
        }
    } catch (Exception e) {
        System.err.println(":: Exception ::" + e.toString());
    }
}
}
}

相关内容

  • 没有找到相关文章

最新更新