public boolean checkEntitlement(String manItemID, String userId) throws Exception {
    boolean hasEntitlement = false;

    String url = "/services/UserData?UserId=" + userId;

    ManResponseBean responseBean = handleGetRequest(url, null);

    // An XML is returned. To check entitlement you need to parse the XML.
    // A workaround instead to lower the server load is to search the string
    // and
    // see if there is a match with ItemId="manItemID"

    String result = responseBean.getBody();

    if (manItemID != null && result != null && result.length() > 0) {
      result = result.toLowerCase();

      manItemID = manItemID.toLowerCase();

      if (result.indexOf("itemid=\"" + manItemID + "\"") > -1) {
        hasEntitlement = true;
      }
    }

    return hasEntitlement;
  }
 /**
  * @param crmId
  * @param userId
  * @param accountID
  * @param channelID
  * @param manItemID
  * @return @throws Exception
  */
 public AuthorizationInfoBean authorizeByUserId(
     String userID, String accountID, String channelID, String manItemID) throws Exception {
   if (checkEntitlement(manItemID, userID)) {
     AuthorizationInfoBean ai = new AuthorizationInfoBean();
     ai.setAuthorized("True");
     ai.setErrorCode(ManResponseCodes.RC_ALREADY_AUTHORIZED);
     ai.setErrorMessage("has already purchased");
     return ai;
   }
   String url =
       "/services/Authorize?UserId="
           + userID
           + "&ContentAccountId="
           + accountID
           + "&ContentItemId="
           + manItemID;
   if (channelID != null) {
     url += "&ContentChannelId=" + channelID;
   }
   if (DEBUG) System.out.println(url);
   ManResponseBean response = handleGetRequest(url, null);
   AuthorizationInfoBean infoBean = null;
   if (response.getBody() != null && !response.getBody().equalsIgnoreCase("")) {
     Document responseXML = parseXMLString(response.getBody());
     if (DEBUG) printXML(responseXML);
     infoBean = mapXMLToBean(responseXML);
     if (DEBUG) System.out.println(infoBean.getErrorCode());
     SubPolicyBean subPolicyBean = infoBean.getSubpolicy();
     if (subPolicyBean.getInternalPackage().equals("true")) {
       String packageID = subPolicyBean.getInternalPackageId();
       infoBean = authorize(userID, accountID, null, packageID);
     }
   } else {
     if (response.getStatusCode() != null
         && (response.getStatusCode().equalsIgnoreCase(ManResponseCodes.RC_NO_ERROR_200)
             || response.getStatusCode().equalsIgnoreCase(ManResponseCodes.RC_NO_ERROR_0))) {
       infoBean = new AuthorizationInfoBean();
       infoBean.setAuthorized("True");
       infoBean.setErrorCode(response.getMAN_ERROR_CODE());
     }
   }
   return infoBean;
 }
  /**
   * @param sessionID
   * @param accountID
   * @param channelID
   * @param manItemID - can be either a MAN_PACKAGE_ID or a MAN_ITEM_ID. If a MAN_PACKAGE_ID is
   *     specified, a channelID is not required.
   * @return @throws Exception
   */
  public AuthorizationInfoBean authorize(
      String sessionID, String accountID, String channelID, String manItemID) throws Exception {
    String url =
        "/services/QuerySessionAuthorization?SessionId="
            + sessionID
            + "&ContentAccountId="
            + accountID
            + "&ContentItemId="
            + manItemID;

    if (channelID != null) {
      url += "&ContentChannelId=" + channelID;
    }

    if (DEBUG) System.out.println(url);

    ManResponseBean response = handleGetRequest(url, null);

    Document responseXML = parseXMLString(response.getBody());
    // SessionId=1234&ContentAccountId=private&ContentChanneldId=sports&ContentItemId=movie300_scene003

    if (DEBUG) printXML(responseXML);

    AuthorizationInfoBean infoBean = mapXMLToBean(responseXML);

    if (DEBUG) System.out.println(infoBean.getErrorCode());

    SubPolicyBean subPolicyBean = infoBean.getSubpolicy();

    if (subPolicyBean.getInternalPackage().equals("true")) {
      String packageID = subPolicyBean.getInternalPackageId();

      infoBean = authorize(sessionID, accountID, null, packageID);
      // InternalPackage="true" InternalPackageId="sportsworx_01"
    }

    return infoBean;
  }