Not sure if this is the right forum for this question, but if not, I'm
sure someone will tell me.


I'm trying to interface an RPGIV program to a Java class to talk to a MQ
Series MQ Manager.  
I've done RPG to Java beore, but I've always used pretty simple
paramaters and such. This one is a bit trickier so I'm seeking help.


Here's what I have:
 
  
Within my MQJBIND class, I have a method called "MQJBIND" that accepts
two java string objects as parms.


A second method in the class called "mGetOutput" that returns a java
string object and accepts as a parm, the reference to MQJBIND.

Here's the relevant java code:

class MQJBIND
{

public void init()
{
// Set up MQSeries environment
    MQEnvironment.channel = channel;

} // end of init  
  /**
   * CONSTURCTER
   * @param qManager the MQSeriss Queue Manager name
   * @parm qname the MQSeries Queue Name
   */
  
  public  MQJBIND(String qManager, String qName)
  { // begin MQJBIND
    // Set up MQ environment
   
    try 
    { // begin TRY MQJBIND
        // Create a connection to the queue manager
        qMgr = new MQQueueManager(qManager,MQC.MQCNO_STANDARD_BINDING);
        int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |
                          MQC.MQOO_INQUIRE |
                          MQC.MQOO_SET |
                          MQC.MQOO_OUTPUT ;

        // Note. MQOO_INQUIRE & MQOO_SET are always included by default.

        // Now specify the queue that we wish to open, and the open
options...

        local_queue =  qMgr.accessQueue(
                                qName,
                                openOptions,
                                null,           // default q manager
                                null,           // no dynamic q name
                                null);          // no alternate user id

    } // end TRY MQJBIND
   
    // If an error has occured in the above, try to identify what went
wrong.
    // Was it an MQ error?
   
    catch (MQException ex)
    {  // begin CATCH MQJBIND
        if(ex.reasonCode == 2033 || ex.reasonCode == 2002)
        { 
            error_out = "EMPTY QUEUE";
            out_text = "";      
        }
        else
        {
            error_out = "An MQ error occurred : Completion code " +
ex.completionCode +
                          " Reason code " + ex.reasonCode;
            out_text = "";      
        }
    }  // end CATCH MQJBIND

  } // end MQJBIND

/**
    * Method getOutput reads the message from the appropriate queue and
    * returns it in a String format.
    * MQ Queue.
    * @param MQJBIND class
    */
  public static String getOutput(MQJBIND mqg)
  { // begin getOutput
        mqg.out_text = "";
        try
        {  // begin try getOutput
            //check if queue is empty
            if ((mqg.qDepth = mqg.local_queue.getCurrentDepth()) > 0)   
            {
                //System.out.println ("In MQJBind current depth is >
0");
                MQMessage retrievedMessage = new MQMessage();
                // Set the get message options.. accept the defaults
                MQGetMessageOptions gmo = new MQGetMessageOptions();  
    
                // wait for a message to arrive
                gmo.options = MQC.MQGMO_WAIT;

                // unlimited wait for a message
                gmo.waitInterval = MQC.MQWI_UNLIMITED; 

                // get the message off the queue..
                mqg.local_queue.get(retrievedMessage,gmo);
            
                // And prove we have the message by displaying the UTF
message text
                String msgText = retrievedMessage.readUTF();
              mqg.out_text = msgText;
                System.out.println("The message is: " + msgText);
            }
            else
            {
                //System.out.println ("In MQJBind current depth is <=
0");
                mqg.error_out = "EMPTY QUEUE";
                mqg.out_text = "";
            }
        } // end try getOutput
        catch (MQException ex)
        { // begin catch MQException getOutput
            if(ex.reasonCode == 2033 || ex.reasonCode == 2002)
            { 
                mqg.error_out = "EMPTY QUEUE";
                mqg.out_text = "";      
            }
            else
            { 
                mqg.error_out = "An MQ error occurred : Completion code
" + ex.completionCode +
                              " Reason code " + ex.reasonCode;
                mqg.out_text = "";      
            }
        }  // end catch MQException getOutput

        catch (java.io.IOException ex)
        { // begin catch java.io.IOException getOutput
            mqg.error_out = "An error occurred whilst writing to the
message buffer: " + ex;
            mqg.out_text = "";  
        } // end catch java.io.IOException getOutput
        return (mqg.out_text);

  } // end getOutput


Now...my question is....how do I prototype the MQJBIND method in my RPG
program to receive the reference to MQJBIND?

Here's what I did, but it doesn't like my prototype when I compile,
because I can't figure out what to use as the return data type on the
prototype:

     D obj_ref         S               O   CLASS(*JAVA:'MQJBIND')
     D mqjbind         S               O   CLASS(*JAVA:'MQJBIND')
     D qManager        S               O
CLASS(*JAVA:'java.lang.String')
     D qChannel        S               O
CLASS(*JAVA:'java.lang.String')
     D qName           S               O
CLASS(*JAVA:'java.lang.String')
     D bytes           S               O
CLASS(*JAVA:'java.lang.String')

      * Prototype procedure to instantiate 'MQJBIND' class
     D MQJBIND         PR              O
     D                                     EXTPROC(*JAVA:
     D                                             'MQJBIND':
     D                                             *CONSTRUCTOR)

      * Prototype procedure to connect to QManager
     D MQJBINDM        PR            10i 0
<<<<-----this return value is incorrect, but I don't know how to fix!
     D                                     EXTPROC(*JAVA:
     D                                             'MQJBIND':
     D                                             'MQJBIND')
     D ManagerQ                            LIKE(qManager) CONST
     D NameQ                               LIKE(qName)    CONST

      * Prototype procedure to accept the DCN INFO FROM ISP
     D MQGetOutput     PR          1000a
     D                                     EXTPROC(*JAVA:
     D                                             'MQJBIND':
     D                                             'getOutput')
     D MqJBindObj                          LIKE(MQJBIND)
    

         // Instantiate the 'MQMJBind' class via the *CONSTRUCTOR
         obj_ref = MQJBIND();

        // Call the MQMJBIND Method to connect to the MQ Manager on
remote host
         mqjbind = MQJBINDM(obj_ref:qManager:qName);

        //  Call the 'MQGetOutput' method in class 'MQMJBind'
        Response = MQGetOutput(obj_ref:mqjbind);


Any help/suggestions appreciated. 

Shannon O'Donnell



 



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.