Example - public registry

The following code segment demonstrates how to share certificates among a group of queue managers:

/*SIMPLE MQePublicRegistry shareCertificate FRAGMENT */
  MQePublicRegistryHndl pubreg;
  MQePrivateRegistryHndl preg;
  MQERETURN rc;
  MQeExceptBlock exceptBlock;
  MQeStringHndl hEntityName;
  MQeFieldsHndl hCert;
  MQEINT32 i;

  /*instantiate and activate PublicReg */
  rc = mqePublicRegistry_new(&exceptBlock, 
                    &pubreg);
  rc = mqePublicRegistry_activate(pubreg, 
                  &exceptBlock, 
                          MQeString("MQeNode_PublicRegistry"),
                  MQeString(".\\"));
  /* auto-register Bruce1,Bruce2...Bruce8 */
  /* ... note that the mini-certificate 
    issuance service must */
  /* have been configured to 
    allow the auto-registration */
  for (i = 1; i < 9; i++)
  {
    rc = MQeString_new(&exceptBlock, 
                  &hEntityName, 
                  strcat("Bruce" + itoa(i)));
    rc = mqePrivateRegistry_new(&exceptBlock, 
                        &preg);
    /* activate() will initiate auto-registration */
    rc = mqePrivateRegistry_activate(
      preg,
      &exceptBlock,
      hEntityName,
      MQeString(".\\MQeNode_PrivateRegistry"),
       MQeString("12345678"),
      MQeString("It_is_a_secret"),
      MQeString("12345678"),
      MQeString("9.20.X.YYY:8082")
         );
    /* save MiniCert from PrivReg in PubReg*/
    rc = mqePrivateRegistry_getCertificate(preg, &exceptBlock, 
                              &hCert, hEntityName);
    rc = mqePublicRegistry_putCertificate(pubreg, &exceptBlock, 
                                hEntityName, hCert);
    /* before share of MiniCert */
    rc = mqePublicRegistry_shareCertificate(pubreg, 
                                &exceptBlock, 
                                  hEntityName,
       hCert, MQeString("9.20.X.YYY:8082"));
    rc = mqePrivateRegistry_close(preg, &exceptBlock);
    (void)mqePrivateRegistry_free(preg, NULL);
    (void)mqeString_free(hEntityName, NULL);
    (void)mqeFields_free(hCert, NULL);
  }
  rc = mqePublicRegistry_close(pubreg, &exceptBlock);
  (void)mqePublicRegistry_close(pubreg, NULL);
/*SIMPLE MQePublicRegistry shareCertificate FRAGMENT */
   try {
   String EntityName = "Bruce";
   String EntityPIN = "12345678";
   Object KeyRingPassword = "It_is_a_secret";
   Object CertReqPIN = "12345678";
   Object CAIPAddrPort = "9.20.X.YYY:8082";
/*instantiate and activate PublicReg */
   MQePublicRegistry pubreg = new MQePublicRegistry();
   pubreg.activate("MQeNode_PublicRegistry",".\\");
/* auto-register Bruce1,Bruce2...Bruce8 */
/* ... note that the mini-certificate issuance service must */
/* have been configured to allow the auto-registration    */
   for (int i = 1; i < 9; i++)
   {
   EntityName = "Bruce"+(new Integer(i)).toString();
   MQePrivateRegistry preg = new MQePrivateRegistry();
/* activate() will initiate auto-registration */
   preg.activate(EntityName, ".\\MQeNode_PrivateRegistry",
     EntityPIN, KeyRingPassword, CertReqPIN, CAIPAddrPort);
/* save MiniCert from PrivReg in PubReg*/
    pubreg.putCertificate(EntityName, 
       preg.getCertificate(EntityName ));
/*before share of MiniCert */
   pubreg.shareCertificate(EntityName,
     preg.getCertificate(EntityName ),"9.20.X.YYY:8082");
   preg.close();
   }
   pubreg.close();
   }
   catch (Exception e)
   {
   e.printStackTrace();
   }
   
Note:
  1. It is not possible to activate a registry instance more than once, hence the example above demonstrates the recommended practice of accessing a private registry by creating a new instance of MQePrivateRegistry, activating the instance, performing the required operations and closing the instance.
  2. If you want to share certificates using a public registry on the home-server, the public registry must be called MQeNode_PublicRegistry.

Terms of use | WebSphere software

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