Tuesday, August 26, 2014

[WebSphere Portal Server] PumaSystemException on allowOperationIfReposDown="true"

When using a federated repository, let's say you're using the following snippet of ode:

try {
 PumaLocator pumaLocator = portalPumaHome.getLocator();
 PumaProfile profile = portalPumaHome.getProfile();
 List<User> users = pumaLocator.findUsersByAttribute(attribute, loginname);

 if (users != null && users.size() > 0)
 {
  // insert happy path here

 } else {
  // insert logic for "Invalid username/password" error message
  System.out.println("Invalud username/password");
 }

} catch (PumaSystemException pse) {
 // insert logic for communication exception with user repository
 System.out.println("We are currently experiencing some technical problems. Please try again later.");
 
} catch (Exception e) {
 // insert logic for other exceptions
 System.out.println("Oops, we screwed something up.");
 
}

As shown in the code snippet, you're expecting that the PumaSystemException is returned when the user repository could not be reached. This is only true when allowOperationIfReposDown is set to false. When the allowOperationIfReposDown="true", the PumaLocator operation would not return a PumaSystemException on CommunicationException with the user repository.

Therefore, your error message for this scenario will not be returned. To work your way around this, you may add an additional logic wherein you try to lookup the bind id when the user your trying to look for could not be found:


try {
 PumaLocator pumaLocator = portalPumaHome.getLocator();
 PumaProfile profile = portalPumaHome.getProfile();
 List<User> users = pumaLocator.findUsersByAttribute(attribute, loginname);

 if (users != null && users.size() > 0)
 {
  // insert happy path here

 } else {
  // adding logic to check if user repository is available
  List<User> bindusers = pumaLocator.findUsersByAttribute(attribute, bindusername);
  if(bindusers != null && bindusers.size() > 0) {
   // Invalid username/password
   System.out.println("Invalid username/password");
  } else {
   // insert logic for communication exception with user repository
   System.out.println("We are currently experiencing some technical problems. Please try again later.");
  }
 }

} catch (Exception e) {
 // insert logic for other exceptions
 System.out.println("Oops, we screwed something up.");
 
}

And that's it, hope this helps.

No comments: