Guest User

Untitled

a guest
Feb 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <apex:page id="MyVisualforcePage" standardController="Document_102__c" extensions="checkingAccessToken" action="{!accessToken}" showHeader="false"> <apex:iframe src="{!imageUrl}" width="100%" height="1000px"/> <script> setTimeout(function(){alert("your response time is exited, If you want to see the Page, Please the Click the again"); window.close();},60000); </script>
  2.  
  3. public class checkingAccessToken {
  4. public Id pageId;
  5. public String objName;
  6. public String claimId;
  7. public String documentId;
  8. public String access_token;
  9. public blob image {get;set;}
  10.  
  11. public checkingAccessToken(ApexPages.StandardController controller){
  12. pageId = ApexPages.currentPage().getParameters().get('id');
  13. objName = pageId.getSObjectType().getDescribe().getName();
  14. List<sObject> objs= Database.query('Select Id,ICA_Claim_Number__c,DocumentId__c from '+objName+' where id =:pageId Limit 1');
  15. Sobject obj = objs.get(0);
  16. claimId = String.valueOf(obj.get('ICA_Claim_Number__c'));
  17. documentId = String.valueOf(obj.get('DocumentId__c'));
  18. }
  19.  
  20. public void accessToken()
  21. {
  22. HttpRequest req = new HttpRequest();
  23. req.setEndpoint('https://{ThridPartyWebsite}/external/access_token_short?grant_type=client_credentials');
  24. req.setMethod('GET');
  25.  
  26. List<Access_Token__mdt> accessTokenList = [Select Username__c, Password__c from Access_Token__mdt where MasterLabel= 'CloudHub'];
  27. if(accessTokenList.size() != 0) {
  28. Access_Token__mdt accessToken = accessTokenList.get(0);
  29. String username = accessToken.Username__c;
  30. String password = accessToken.Password__c;
  31.  
  32. Blob headerValue = Blob.valueOf(username + ':' + password);
  33. String authorizationHeader = 'Basic ' +
  34. EncodingUtil.base64Encode(headerValue);
  35. req.setHeader('Authorization', authorizationHeader);
  36.  
  37. Http http = new Http();
  38. HTTPResponse res = http.send(req);
  39. System.debug(res.getBody());
  40.  
  41. if (res.getStatusCode() == 200) {
  42. Map<String, Object> results = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
  43. access_token = (String)results.get('access_token');
  44.  
  45. imageUrl = 'https://{ThridPartyWebsite}/api/document'+'?claimId='+claimId+'&documentId='+documentId+'&access_token='+access_token;
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment