/** * @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; }
/** * @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; }
public AuthorizationInfoBean mapXMLToBean(Document doc) throws Exception { AuthorizationInfoBean infoBean = new AuthorizationInfoBean(); Element authInfoNode = doc.getRootElement(); if (DEBUG) System.out.println("ROOT----------"); // map root node attributes List rootAttributes = authInfoNode.getAttributes(); if (rootAttributes != null) { for (int i = 0; i < rootAttributes.size(); i++) { Attribute rootAtt = (Attribute) (rootAttributes.get(i)); if (DEBUG) System.out.println("mapping:" + rootAtt.getName() + " " + rootAtt.getValue()); BeanUtils.setProperty( infoBean, rootAtt.getName().substring(0, 1).toLowerCase() + rootAtt.getName().substring(1, rootAtt.getName().length()), rootAtt.getValue()); } } if (DEBUG) System.out.println("Content----------"); // map all content node's attributes Element contentNode = authInfoNode.getChild("Content"); List contentAttributes = contentNode.getAttributes(); ContentBean contentBean = new ContentBean(); if (contentAttributes != null) { for (int i = 0; i < contentAttributes.size(); i++) { Attribute contentAtt = (Attribute) (contentAttributes.get(i)); if (DEBUG) System.out.println("mapping:" + contentAtt.getName() + " " + contentAtt.getValue()); // BeanUtils.setProperty(contentBean, contentAtt.getName(), // contentAtt.getValue()); BeanUtils.setProperty( contentBean, contentAtt.getName().substring(0, 1).toLowerCase() + contentAtt.getName().substring(1, contentAtt.getName().length()), contentAtt.getValue()); } } infoBean.setContent(contentBean); if (DEBUG) System.out.println("Subpolicy----------"); // map all subpolicy node's attribtues Element subPolicyNode = authInfoNode.getChild("SubPolicy"); List subpolicyAttributes = subPolicyNode.getAttributes(); SubPolicyBean subPolicyBean = new SubPolicyBean(); if (subpolicyAttributes != null) { for (int i = 0; i < subpolicyAttributes.size(); i++) { Attribute subpolicyAtt = (Attribute) (subpolicyAttributes.get(i)); if (DEBUG) System.out.println("mapping:" + subpolicyAtt.getName() + " " + subpolicyAtt.getValue()); // BeanUtils.setProperty(subPolicyBean, subpolicyAtt.getName(), // subpolicyAtt.getValue()); BeanUtils.setProperty( subPolicyBean, subpolicyAtt.getName().substring(0, 1).toLowerCase() + subpolicyAtt.getName().substring(1, subpolicyAtt.getName().length()), subpolicyAtt.getValue()); } } infoBean.setSubpolicy(subPolicyBean); if (DEBUG) System.out.println("all mapped"); return infoBean; }