Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Web Services

New Contributor
Posts: 7
Registered: ‎09-04-2012
My Device: Bold
My Carrier: AT&T

401 Unauthorized message from GetUsersRequest.getUsers()



When running TestMain (from Java BWS Sample), I can successfully get as far as initializing credentials, but at the line


GetUsersResponse response = _bws.getUsers(request);


it produces a 401 error.



Starting to intiialize credentials...

Credentials initialized.

Starting to retrieve users...
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode (HttpTransportPipe.java:196)


We use Active Directory, and the username/pw in the java code are my own, which I use to log onto the BAS console.


I'm running the java script locally on my pc.  The encoded username is "8,16,0,1,1,0;amarasnybas.ad.dpw-ama.com00"


Any ideas please?


Thank you.

Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: 401 Unauthorized message from GetUsersRequest.getUsers()

Did you modify the code to use the Active Directory Authenticator? If not it would be trying to authenticate your username and password against a non-existent BAS account which would explain the 401.

Goodbye everybody!
New Contributor
Posts: 7
Registered: ‎09-04-2012
My Device: Bold
My Carrier: AT&T

Re: 401 Unauthorized message from GetUsersRequest.getUsers()

This may not be the best way to do it, but I modified setup() to include a call to GetAuthenticatorsRequest(); and used the authenticator it returned in GetEncodedUsernameRequest(), which seemed to do the trick.


private static boolean setup() {
  String strBASURL=System.getProperty("basurl");
  URL serviceUrl = null;
  URL utilServiceUrl=null;

  //The Metadata object includes information about this application, it is included with every call
  _meta.setOrganizationUid("0"); //Not used currently, set to "0"

  try {
   serviceUrl = new URL("https://" + strBASURL + "/enterprise/admin/ws?wsdl");
   utilServiceUrl = new URL("https://" + strBASURL + "/enterprise/admin/util/ws?wsdl");
  } catch (MalformedURLException e) {
   System.err.println("Cannot initialize the wsdl");
   return false;

  //Initialize our web service stubs that will be used for all calls
  _myBWSService = new BWSService(serviceUrl);
  _bws = _myBWSService.getBWS();
  _myBWSUtilService = new BWSUtilService(utilServiceUrl);
  _bwsUtil = _myBWSUtilService.getBWSUtil();

  String username=System.getProperty("username");
  String password=System.getProperty("password");

GetAuthenticatorsRequest request2 = new GetAuthenticatorsRequest();
GetAuthenticatorsResponse response2 = _bwsUtil.getAuthenticators(request2);
if (response2.getReturnStatus().getCode().compareTo("SUCCESS") != 0)
{       System.out.println("Error occurred: " + response2.getReturnStatus().getMessage());  

else if (response2.getAuthenticators() != null)
{       for (Authenticator itr:response2.getAuthenticators())
    {           System.out.println(itr.getName() + ", " + itr.getUid() + ", " + (itr.getAuthenticatorType().isINTERNAL() ? "internal" : "plugin"));
   authenticator = itr;


  GetEncodedUsernameRequest request=new GetEncodedUsernameRequest();
  String domainName = "ad.dpw-ama.com";
  //set credentialType
  CredentialType credentialType = new CredentialType();
  //"authenticator" was returned from the getAuthenticators() API
  //BlackBerry Administration Service authentication requires only a username and password
  //(identical to the BAS Web Console)
  //PLUGIN authentication, ex. "Active Directory", also requires a "domain" to be set
  //(identical to the BAS Web Console)
  {       request.setDomain(domainName);
GetEncodedUsernameResponse geurResponse= _bwsUtil.getEncodedUsername(request);


  if (geurResponse.getReturnStatus().getCode().compareTo("SUCCESS") != 0){
   System.out.println("Error occurred: " + geurResponse.getReturnStatus().getMessage());
   return false;

  String myEncodeUsername = geurResponse.getEncodedUsername();

  //Set http basic authentication on the web service
  BindingProvider bp = (BindingProvider)_bws;
  bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, myEncodeUsername);
  bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);

  return true;


Thanks very much!