< Anterior | Siguiente >

Lección 1.4: Crear una clase proxy Java para probar la aplicación

En la lección 1.4 se describe la creación de una clase de prueba Java para probar la aplicación.

antes de empezar, debe completar la Lección 1.3: Crear una clase de almacenamiento intermedio de mensaje. En esta lección realizará las siguientes tareas:
  1. Primero creará una clase de prueba Java: Expanda el proyecto MultiSegOutput, expanda Recursos Java y seleccione el paquete sample.ims.
  2. Pulse con el botón derecho del ratón y seleccione Nuevo. Seleccione la opción de clase Icono de clase Java para crear una clase Java nueva.
  3. En el campo nombre de clase Java, teclee TestMultiSeg. Tenga en cuenta que la clase TestMultiSeg sólo se ofrece como ejemplo; deberá cambiar el código de transacción para sus especificaciones de máquina IMS. Póngase en contacto con su administrador IMS para conocer el código de transacción. Puede localizar la sentencia input.setIn__trcd("SKS6 ") en la clase TestMultiSeg.java y realizar las modificaciones.
  4. Asegúrese de que Carpeta fuente contiene MultiSegOutput/JavaSource y que el Nombre de paquete contiene sample.ims.
  5. Pulse Terminar.
  6. Abra TestMultiSeg.java en el editor de clases Java.
  7. Sustituya todo el código del editor por el siguiente:
    /***********************************************************
     * Licensed Materials - Property of IBM
     *  
     * com.ibm.j2c.cheatsheet.content
     *  
     *Copyright IBM Corporation 2004. Reservados todos los derechos. 
     * 
     * Note to U.S. Government Users Restricted Rights:  Use, 
     * duplication or disclosure restricted by GSA ADP  Schedule 
     * Contract with IBM Corp. 
     ************************************************************/
    package sample.ims;
    
    import com.ibm.etools.marshall.util.MarshallIntegerUtils;
    import sample.ims.data.*;
    
    public class TestMultiSeg
    {
    	public static void main (String[] args)
    	{
    		byte[] segBytes = null;
    		int srcPos = 0;
    		int dstPos = 0;
    		int totalLen = 0;
    		int remainLen = 0;
    		byte[] buff;
    		short LL = 0;
    		short ZZ = 0;
    
    		try
    		{
    			// ---------------------------------------------------			
    			// Populate the IMS transaction input message with
    			// data.  Use the input message format handler method 
    			// getSize() to set the LL field of the input message.
    			// ---------------------------------------------------					
    			InputMsg input = new InputMsg();
    			input.setIn__ll((short) input.getSize());
    			input.setIn__zz((short) 0);
    			//----------------------------------------------
    			// find out the transaction code from your IMS 
    			// administrator
    			//-----------------------------------------------
    			input.setIn__trcd("SKS6 ");
    			input.setIn__data1("M2 SI1");
    			input.setIn__data2("M3 SI1");
    
    			// ---------------------------------------------------			
    			// Run the IMS transaction.  The multi-segment output 
    			// message is returned.
    			// ---------------------------------------------------				
    			MSOImpl proxy = new MSOImpl();
    			
    			sample.ims.CCIBuffer output = proxy.runMultiSegOutput(input);
    
    			// ---------------------------------------------------	
    			// Retrieve the multi-segment output message as a 
    			// byte array using the output message format
    			// handler method getBytes().
    			// ---------------------------------------------------			 			
    			System.out.println(
    				"\nSize of output message is: " + output.getSize());
    			segBytes = output.getBytes();
    
    			srcPos = 0;
    			dstPos = 0;
    			totalLen = segBytes.length;
    			remainLen = totalLen;
    
    			// ---------------------------------------------------	
    			// Populate first segment object from buffer. 
    			// ---------------------------------------			             
    			buff = null;
    			// Get length of segment.
    			LL =
    				MarshallIntegerUtils.unmarshallTwoByteIntegerFromBuffer(
    					segBytes,
    					srcPos,
    					true,
    					MarshallIntegerUtils.SIGN_CODING_TWOS_COMPLEMENT);
    
    			// Put segment in byte array.
    			buff = new byte[LL];
    			System.arraycopy(segBytes, srcPos, buff, dstPos, LL);
    			remainLen -= LL;
    
    			// Create and populate segment object from byte array.
    			OutputSeg1 S1 = new OutputSeg1();
    			S1.setBytes(buff);
    			System.out.println(
    				"\nOutSeg1 LL is:    "
    					+ S1.getOut__ll()
    					+ "\nOutSeg1 ZZ is:    "
    					+ S1.getOut__zz()
    					+ "\nOutSeg1_DATA1 is: "
    					+ S1.getOut__data1());
    
    			// ---------------------------------------------------	
    			// Populate second segment object from buffer. 
    			// ---------------------------------------------------	
    			srcPos += LL;
    			buff = null;
    			// Get length of segment.
    			LL =
    				MarshallIntegerUtils.unmarshallTwoByteIntegerFromBuffer(
    					segBytes,
    					srcPos,
    					true,
    					MarshallIntegerUtils.SIGN_CODING_TWOS_COMPLEMENT);
    
    			// Put segment in byte array.
    			buff = new byte[LL];
    			System.arraycopy(segBytes, srcPos, buff, dstPos, LL);
    			remainLen -= LL;
    
    			// Create and populate segment object from byte array.
    			
    			OutputSeg2 S2 = new OutputSeg2();
    			S2.setBytes(buff);
    			System.out.println(
    				"\nOutSeg2 LL is:    "
    					+ S2.getOut__ll()
    					+ "\nOutSeg2 ZZ is:    "
    					+ S2.getOut__zz()
    					+ "\nOutSeg2_DATA1 is: "
    					+ S2.getOut__data1()
    					+ "\nOutSeg2_DATA2 is: "
    					+ S2.getOut__data2());
    			// ---------------------------------------------------				
    			// Populate third segment object from buffer. 
    			// ---------------------------------------------------	
    			srcPos += LL;
    			buff = null;
    			// Get length of segment.
    			LL =
    				MarshallIntegerUtils.unmarshallTwoByteIntegerFromBuffer(
    					segBytes,
    					srcPos,
    					true,
    					MarshallIntegerUtils.SIGN_CODING_TWOS_COMPLEMENT);
    
    			// Put segment in byte array.
    			buff = new byte[LL];
    			System.arraycopy(segBytes, srcPos, buff, dstPos, LL);
    			remainLen -= LL;
    
    			// Create and populate segment object from byte array.
    			OutputSeg3 S3 = new OutputSeg3();
    			S3.setBytes(buff);
    			System.out.println(
    				"\nOutSeg3 LL is:    "
    					+ S3.getOut__ll()
    					+ "\nOutSeg3 ZZ is:    "
    					+ S3.getOut__zz()
    					+ "\nOutSeg3_DATA1 is: "
    					+ S3.getOut__data1()
    					+ "\nOutSeg3_DATA2 is: "
    					+ S3.getOut__data2()
    					+ "\nOutSeg3_DATA3 is: "
    					+ S3.getOut__data3());
    		}
    		catch (Exception e)
    		{
    			System.out.println("\nCaught exception is: " + e);
    		}
    	}
    }
  8. Ahora probará la aplicación: expanda el proyecto MultiSegOutput y el paquete sample.ims.
  9. Pulse con el botón derecho del ratón en la clase TestMultiSeg.java y seleccione Ejecutar. Seleccione Ejecutar como > Aplicación Java
  10. Deberá ver el siguiente mensaje en la consola:

    salida en consola

  11. Enhorabuena. Ha completado la guía de aprendizaje de salida de varios segmentos.