Examples - using MAttribute for Java™

/*SIMPLE PROTECT FRAGMENT */

      MQeMsgHndl msgObj;
      MQeMAttributeHndl attr = null;
      MQeInt64 confirmId;
    MQERETURN rc;
    MQeExceptBlock exceptBlock;
    MQe3DESCryptorHndl tdes;
    MQeMAttributeHndl attr;
    MQeKeyHndl localkey;
          MQeMsgHndl msgObj;

        /* create the cryptor */
    rc = mqe_uniqueValue(&exceptBlock, &confirmId);
          rc = mqe3DESCryptor_new(&exceptBlock, &tdes);
           /* create an attribute using the cryptor */
          rc = mqeMAttribute_new(&exceptBlock, &attr, 
                        NULL, tdes, NULL );
           /* create a local key */
          rc = mqeKey_new(&exceptBlock,&localkey);
           /* give it the key seed */
          rc = mqeKey_setLocalKey(localkey, new(&exceptBlock, 
                                 MQeString("my secret key"));
           /* set the key in the attribute */
          rc = mqeMAttribute_setKey(attr, &exceptBlock, 
                          localkey );
           /* create the message */
          rc = mqeMsg_new(&exceptBlock, &msObj);
          rc = mqeFields_putAscii(msgObj, &exceptBlock, 
                        MQeString("MsgData"),
                                   MQeString("0123456789abcdef..."));
           /* put the message using the attribute */
          rc = mqeQueueManager_putMessage(newQM, &exceptBlock, 
                              targetQMgrName, targetQName, 
                              msgObj, attr, confirmId );

 
        /*SIMPLE UNPROTECT FRAGMENT */

         MQeMsgHndl msgObj2;
         MQeMAttributeHndl attr2;
         MQeInt64 confirmId2;
    MQeKeyHndl localkey;
    MQERETURN rc;
    MQeExceptBlock exceptBlock;

    rc = mqe_uniqueValue(&exceptBlock, &confirmId2);
        /* create the attribute - we 
          do not have to specify the cryptor, */
          /* the attribute can get this from the message itself  */
         rc = mqeMAttribute_new(&exceptBlock, &attr2, 
                        NULL, NULL, NULL);
          /* create a local key */
         rc = mqeKey_new(&exceptBlock, &localkey);
          /* give it the key seed */
         rc = mqeKey_setLocalKey(localkey,&exceptBlock,
                        MQeString("my secret key"));
          /* set the key in the attribute */
         rc = mqeMAttribute_setKey(attr2, &exceptBlock, localkey );
          /* get the message using the attribute */
         rc = mqeQueueManager_getMessage(newQM, &exceptBlock, 
                          &msgObj2, targetQMgrName, 
                                      targetQName, NULL, attr2, confirmId2 );
    /*SIMPLE PROTECT FRAGMENT */
{     
     MQeMsgObject msgObj = null;
     MQeMAttribute attr = null;
     long confirmId = MQe.uniqueValue();
     try{
        trace(">>>putMessage to target Q using MQeMAttribute"
                +" with 3DES Cryptor and key=my secret key");
         /* create the cryptor */
        MQe3DESCryptor tdes = new MQe3DESCryptor();
         /* create an attribute using the cryptor */
        attr = new MQeMAttribute(null,tdes,null );
         /* create a local key */
        MQeKey localkey = new MQeKey();
         /* give it the key seed */
        localkey.setLocalKey("my secret key");
         /* set the key in the attribute */
        attr.setKey(localkey );
         /* create the message */
        msgObj = new MQeMsgObject();
        msgObj.putAscii("MsgData","0123456789abcdef...");
         /* put the message using the attribute */
        newQM.putMessage(targetQMgrName, targetQName,
            msgObj, attr, confirmId );
        trace(">>>MAttribute protected msg put OK...");
       }
    catch (Exception e)
       {
       trace(">>>on exception try resend exactly once...");
       msgObj.putBoolean(MQe.Msg_Resend, true );
       newQM.putMessage(targetQMgrName, targetQName,
            msgObj, attr, confirmId );
       }
}

    /*SIMPLE UNPROTECT FRAGMENT */
{
       MQeMsgObject msgObj2 = null;
       MQeMAttribute attr2 = null;
       long confirmId2 = MQe.uniqueValue();
    try{
       trace(">>>getMessage from target Q using MQeMAttribute"+
            " with 3DES Cryptor and key=my secret key");
        /* create the attribute - we do not have to specify the cryptor, */
        /* the attribute can get this from the message itself  */
       attr2 = new MQeMAttribute(null,null,null );
        /* create a local key */
       MQeKey localkey = new MQeKey();
        /* give it the key seed */
       localkey.setLocalKey("my secret key");
        /* set the key in the attribute */
       attr2.setKey(localkey );
        /* get the message using the attribute */
       msgObj2 = newQM.getMessage(targetQMgrName, targetQName, 
                                  null, attr2, confirmId2 );
       trace(">>>unprotected MsgData = "
            + msgObj2.getAscii("MsgData"));
       }
    catch (Exception e)
      {          
       /*exception may have left */
      newQM.undo(targetQMgrName,             
    /*message locked on queue */
                targetQName, confirmId2 );  
    /*undo just in case */
      e.printStackTrace();                   
    /*show exception reason */
      }
     …
}

Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.