ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Help with test Java class

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with test Java class

    Hi all

    i'm try to write my first java program and i would try to use the ProgramCallDocument to call an RPG program, with rdpower wizard i created the following java source ; now how can i run and test this java source ? i have to write a htlm/jsp page or i have other ways ?

    Thanks in advance
    PHP Code:
    package test_rpg.pck;

    import iseries.programcall.base.AbstractProgramCallBean;
    import com.ibm.as400.access.AS400Message;
    import com.ibm.as400.access.AS400;
    import com.ibm.as400.access.ProgramCall;
    import com.ibm.as400.access.ProgramParameter;
    import com.ibm.as400.access.Trace;
    import iseries.programcall.base.RuntimeContext;
    import iseries.programcall.base.Constants;
    import iseries.programcall.base.Messages;
    import com.ibm.as400.access.AS400Text;
    import com.ibm.as400.access.BidiStringType;

    /*
     * <!-- begin-system-doc -->
     * plugin: com.ibm.etools.iseries.javatools
     * version: 8.0.4
     * timestamp: 12:12:11 PM 2012/08/13
     * pcml: test_rpg.pck.test_rpg.pcml
     * <!-- end-system-doc -->
     *
     * Program call bean for invoking program /QSYS.LIB/mylib.LIB/sr_tst.PGM
     */
    public class Test_rpg extends AbstractProgramCallBean
    {
        private static final 
    long serialVersionUID 2235650327682925376L;

        
    // Program parameter: art.
        
    private String art "";

        
    // Program parameter: des.
        
    private String des "";

        
    // The runtime context
        
    private static RuntimeContext rtContext null;
        static {
            
    rtContext RuntimeContext.getContext("/defaultPCW.config");
        }

        public 
    Test_rpg()
        {
            
    super(rtContext);
            
    programPath "/QSYS.LIB/mylib.LIB/sr_tst.PGM";
        }

        
    /*
         * Set the value of the program parameter: art.
         *
         * @value The value of the parameter.
         */
        
    public void setArt(String value)
        {
            
    art value;
        }

        
    /*
         * Get the value of the program parameter: art.
         *
         * @return The value of the parameter.
         */
        
    public String getArt()
        {
            return 
    art;
        }

        
    /*
         * Set the value of the program parameter: des.
         *
         * @value The value of the parameter.
         */
        
    public void setDes(String value)
        {
            
    des value;
        }

        
    /*
         * Get the value of the program parameter: des.
         *
         * @return The value of the parameter.
         */
        
    public String getDes()
        {
            return 
    des;
        }

        
    /*
         * Invoke the program and return the status parameter.
         * If the invoke fails, you can use the retrieveProgramCallException()
         * method to determine why the invoke failed.
         *
         * @return  The value of the status parameter (if specified) is returned if the
         * invoke was successful. Constants.FAILURE otherwise.
         */
        
    public String invokeReturnStatus()
        {
            if (!
    invoke()) {
                return 
    Constants.FAILURE;
            }
            return 
    Constants.SUCCESS;
        }

        
    /*
         * Invoke the program. If the invoke fails, you can use the retrieveProgramCallException()
         *  method to determine why the invoke failed. If the invoke is successful, the
         * output paramters will be updated.
         *
         * @return True if the program is invoked successfully. False otherwise.
         */
        
    public boolean invoke()
        {
            
    AS400 as400 null;
            try {
                if (
    connection == null) {
                    throw new 
    Exception(Messages.getMsgText("NoConnection"));
                }

                
    connection.setThreadSafe(false);
                
    as400 connection.getAS400();
                
    ProgramCall thePgm = new ProgramCall(as400);
                
    ProgramParameter[] parmList = new ProgramParameter[2];

                
    // Declare converters
                
    AS400Text as400text2 = new AS400Text(30as400);
                
    AS400Text as400text1 = new AS400Text(15as400);

                
    // Process input parameter art
                
    parmList[0] =  new ProgramParameter();
                
    parmList[0].setParameterType(ProgramParameter.PASS_BY_REFERENCE);
                
    int artOutputsize 15;
                
    int artSize 15;
                
    byte [] artInputBuf = new byte[artSize];
                
    int artInputBufOffset 0;
                if (
    getArt() == null) {
                    
    setArt("");
                }
                
    as400text1.toBytes(getArt(), artInputBufartInputBufOffsetBidiStringType.DEFAULT);
                
    artInputBufOffset += 15;

                
    parmList[0].setInputData(artInputBuf);
                
    parmList[0].setOutputDataLength(artOutputsize);

                
    // Process input parameter des
                
    parmList[1] =  new ProgramParameter();
                
    parmList[1].setParameterType(ProgramParameter.PASS_BY_REFERENCE);
                
    int desOutputsize 30;
                
    int desSize 30;
                
    byte [] desInputBuf = new byte[desSize];
                
    int desInputBufOffset 0;
                if (
    getDes() == null) {
                    
    setDes("");
                }
                
    as400text2.toBytes(getDes(), desInputBufdesInputBufOffsetBidiStringType.DEFAULT);
                
    desInputBufOffset += 30;

                
    parmList[1].setInputData(desInputBuf);
                
    parmList[1].setOutputDataLength(desOutputsize);

                
    // Invoke the program.
                
    programException null;
                
    AS400Message[] myProgramMessages null;
                
    thePgm.setProgram(programPathparmList);
                
    thePgm.setThreadSafe(false);
                if (!
    thePgm.run()) {
                    
    myProgramMessages thePgm.getMessageList();
                    
    connection.releaseAS400();
                    
    StringBuffer pgmMsgs = new StringBuffer();
                    
    String NEW_LINE System.getProperty("line.separator");
                    
    pgmMsgs.append(Messages.getMsgText("InvocationFail") + NEW_LINE);
                    for (
    int msg 0myProgramMessages != null && msg myProgramMessages.lengthmsg++) {
                        
    pgmMsgs.append(myProgramMessages[msg].toString() + NEW_LINE);
                    }
                    throw new 
    java.lang.RuntimeException(pgmMsgs.toString());
                }

                
    int skipBytes 0;
                
    int offset 0;
                
    // Process output parameter art
                
    byte [] artOutputBuf parmList[0].getOutputData();
                
    int artOutputBufOffset 0;
                
    offset 0;
                
    skipBytes 0;
                
    offset offset skipBytes;
                
    artOutputBufOffsetoffset;
                if(
    offset 15 artOutputBuf.length) {
                    throw new 
    java.lang.RuntimeException(Messages.getMsgText("InsufficientInputData"));
                }
                
    setArt((String)as400text1.toObject(artOutputBuf,artOutputBufOffsetBidiStringType.DEFAULT));
                
    artOutputBufOffset += 15;
                
    offset artOutputBufOffset;

                
    // Process output parameter des
                
    byte [] desOutputBuf parmList[1].getOutputData();
                
    int desOutputBufOffset 0;
                
    offset 0;
                
    skipBytes 0;
                
    offset offset skipBytes;
                
    desOutputBufOffsetoffset;
                if(
    offset 30 desOutputBuf.length) {
                    throw new 
    java.lang.RuntimeException(Messages.getMsgText("InsufficientInputData"));
                }
                
    setDes((String)as400text2.toObject(desOutputBuf,desOutputBufOffsetBidiStringType.DEFAULT));
                
    desOutputBufOffset += 30;
                
    offset desOutputBufOffset;

                return 
    true;

            } catch (
    Exception e) {
                
    programException e;
                
    Trace.log(Trace.ERRORe);
                if (
    rtContext != null && rtContext.throwExceptionOnError()) {
                    throw new 
    java.lang.RuntimeException(e);
                }
            }
            finally {
                if (
    connection != null) {
                    try { 
    connection.releaseAS400(); } catch (Exception e) { Trace.log(Trace.ERRORe); }
                }
            }
            return 
    false;
        }

        
    /*
         * Get the RuntimeContext for this program call bean.
         *
         * @return The runtime context.
         */
        
    public static RuntimeContext getRuntimeContext()
        {
            return 
    rtContext;
        }


Working...
X