Exemple : Appel inséré basé sur les données

Cette approche nécessite de personnaliser le modèle de solution de la façon suivante, de manière à ce que l’application de création de correspondance puisse accepter ces paramètres lors d’une demande POST :
  1. Modifiez le modèle JSP de création de correspondance. Le fichier JSP de création de correspondance (@ CorrespondenceManagementSolutionTemplate/CreateCorrespondence/html-template/ccr.jsp) peut être modifié de manière à accepter ces paramètres et les coder en variables Flash qui peuvent être lues à partir de l’application de création de correspondance. Par exemple :
    // used from InvokeParams.as 
    String _PREFIX = "cm"; 
    String URLPARAM_LETTERID = _PREFIX + "LetterId"; 
    String URLPARAM_LETTERNAME = _PREFIX + "LetterName"; 
    String URLPARAM_LETTERVERSION = _PREFIX + "LetterVersion"; 
    String URLPARAM_USELATEST = _PREFIX + "UseLatest"; 
    String URLPARAM_USETESTDATA = _PREFIX + "UseTestData"; 
    String URLPARAM_DATA = _PREFIX + "Data"; 
    String URLPARAM_DATAURL = _PREFIX + "DataUrl"; 
    String URLPARAM_PREVIEW = _PREFIX + "Preview"; 
    // used from InvokeParams.as 
     
    String encodedFlashVars = "localeChain=" + localeChain; 
     
    String letterId = (String) request.getParameter(URLPARAM_LETTERID); 
    if (letterId != null && !"".equals(letterId)) 
        encodedFlashVars += "&" + URLPARAM_LETTERID + "=" + URLEncoder.encode(letterId); 
     
    String letterName = (String) request.getParameter(URLPARAM_LETTERNAME); 
    if (letterName != null && !"".equals(letterName)) 
        encodedFlashVars += "&" + URLPARAM_LETTERNAME + "=" + letterName; 
     
    String letterVersion = (String) request.getParameter(URLPARAM_LETTERVERSION); 
    if (letterVersion != null && !"".equals(letterVersion)) 
        encodedFlashVars += "&" + URLPARAM_LETTERVERSION + "=" + letterVersion; 
     
    String useLatest = (String) request.getParameter(URLPARAM_USELATEST); 
    if (useLatest != null && !"".equals(useLatest)) 
        encodedFlashVars += "&" + URLPARAM_USELATEST + "=" + useLatest; 
     
    String useTestData = (String) request.getParameter(URLPARAM_USETESTDATA); 
    if (useTestData != null && !"".equals(useTestData)) 
        encodedFlashVars += "&" + URLPARAM_USETESTDATA + "=" + useTestData; 
     
    String data = (String) request.getParameter(URLPARAM_DATA); 
    if (data != null && !"".equals(data)) 
        encodedFlashVars += "&" + URLPARAM_DATA + "=" + URLEncoder.encode(data); 
     
    String dataUrl = (String) request.getParameter(URLPARAM_DATAURL); 
    if (dataUrl != null && !"".equals(dataUrl)) 
        encodedFlashVars += "&" + URLPARAM_DATAURL + "=" + URLEncoder.encode(dataUrl); 
     
    String preview = (String) request.getParameter(URLPARAM_PREVIEW); 
    if (preview != null && !"".equals(preview)) 
        encodedFlashVars += "&" + URLPARAM_PREVIEW + "=" + preview;
  2. Vous pouvez ensuite saisir les variables flash codées ci-dessus (chaîne) dans une variable JavaScript dans le fichier ccr.jsp et les transmettre en variables flash à votre application (fichier SWF) :
    • JavaScript
      <script language="JavaScript" type="text/javascript"> 
      .... 
       
      var flashVarsStr = "<%= encodedFlashVars %>"; 
       
      ....
    • SWF Loader
      .... 
          AC_FL_RunContent( 
                  "id",                     "ccrSwf", 
                  "name",                 "ccrSwf", 
                  "src",                     "${swf}", 
                  "flashVars",                             flashVarsStr, 
                  "width",                 "${width}", 
                  "height",                 "${height}", 
                  "align",                 "middle", 
                  "quality",                 "high", 
                  "bgcolor",                 "${bgcolor}", 
                  "wmode",                 dcWMode, 
                  "allowScriptAccess",    "sameDomain", 
                  "type",                 "application/x-shockwave-flash", 
                  "pluginspage",             "http://www.adobe.com/go/getflashplayer" 
          );
    • Fichier ccr.jsp :
      <!-- saved from url=(0014)about:internet --> 
      <%@page import="java.util.*"%> 
      <%@page import="java.net.*"%> 
      <html lang="en"> 
      <!-- 
       * ADOBE SYSTEMS INCORPORATED 
       * ___________________________ 
       * 
       *  Copyright 2010 Adobe Systems Incorporated 
       *  All Rights Reserved. 
       * 
       * NOTICE:  All information contained herein is, and remains the property of Adobe Systems 
       * Incorporated and its suppliers, if any. The intellectual and technical concepts contained 
       * herein are proprietary to Adobe Systems Incorporated and its suppliers and may be covered 
       * by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright 
       * law. Dissemination of this information or reproduction of this material is strictly forbidden 
       * unless prior written permission is obtained from Adobe Systems Incorporated. 
       // --> 
       
      <!-- 
      Smart developers always View Source. 
       
      This application was built using Adobe Flex, an open source framework 
      for building rich Internet applications that get delivered via the 
      Flash Player or to desktops via Adobe AIR. 
       
      Learn more about Flex at http://flex.org 
      // --> 
       
      <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
       
      <!--  BEGIN Browser History required section --> 
      <link rel="stylesheet" type="text/css" href="${history_css}" /> 
      <!--  END Browser History required section --> 
       
      <title>Create Correspondence</title> 
      <script src="/apps/solutions/cm/ccr/AC_OETags.js" language="javascript"></script> 
      <script src="/apps/solutions/cm/ccr/dcScript.js"  language="javascript"></script> 
      <!--  BEGIN Browser History required section --> 
      <script src="/apps/solutions/cm/ccr/history/history.js" language="javascript"></script> 
      <!--  END Browser History required section --> 
       
      <style> 
      body { 
          margin: 0px; 
          overflow: hidden 
      } 
      </style> 
      <script language="JavaScript" type="text/javascript"> 
       
      //CM specific params 
      var helpUrl="http://www.adobe.com/go/learn_dep_correspondence_management_11"; 
      var reconnectWaitDuration = "20"; 
       
      <!-- 
      // ----------------------------------------------------------------------------- 
      // Globals 
      // Major version of Flash required 
      var requiredMajorVersion = 10; 
      // Minor version of Flash required 
      var requiredMinorVersion = 2; 
      // Minor version of Flash required 
      var requiredRevision = 0; 
      // ----------------------------------------------------------------------------- 
      // --> 
       
      </script> 
      </head> 
       
      <body scroll="no" onresize="doOnResize()"> 
      <% 
          String acceptLang = request.getHeader("accept-language"); 
          if(acceptLang == null || "".equals(acceptLang.trim())) 
              acceptLang = "en-US"; 
          acceptLang = acceptLang.trim(); 
       
          String[] locales = acceptLang.split(","); 
          List localeChainList = new ArrayList(); 
          for(int i=0; i<locales.length; i++) 
          { 
              String locale =locales[i]; 
              if(locale.trim().startsWith("en") && !localeChainList.contains("en_US")) 
                  localeChainList.add("en_US"); 
              if(locale.trim().startsWith("de") && !localeChainList.contains("de_DE")) 
                  localeChainList.add("de_DE"); 
              if(locale.trim().startsWith("ja") && !localeChainList.contains("ja_JP")) 
                  localeChainList.add("ja_JP"); 
              if(locale.trim().startsWith("fr") && !localeChainList.contains("fr_FR")) 
                  localeChainList.add("fr_FR"); 
          } 
       
          String localeChain = ""; 
          if (localeChainList.isEmpty()) 
              localeChain = "en_US"; 
          else 
          { 
              StringBuilder sb = new StringBuilder(); 
              String delimiter =","; 
              for (int j=0; j<localeChainList.size(); j++) 
              { 
                  String x = (String)localeChainList.get(j); 
                  sb.append(x + delimiter); 
              } 
              sb.delete(sb.length()-delimiter.length(), sb.length()); 
           
              localeChain = sb.toString(); 
          } 
           
           
           // used from InvokeParams.as 
              String _PREFIX = "cm"; 
              String URLPARAM_LETTERID = _PREFIX + "LetterId"; 
              String URLPARAM_LETTERNAME = _PREFIX + "LetterName"; 
              String URLPARAM_LETTERVERSION = _PREFIX + "LetterVersion"; 
              String URLPARAM_USELATEST = _PREFIX + "UseLatest"; 
              String URLPARAM_USETESTDATA = _PREFIX + "UseTestData"; 
              String URLPARAM_DATA = _PREFIX + "Data"; 
              String URLPARAM_DATAURL = _PREFIX + "DataUrl"; 
              String URLPARAM_PREVIEW = _PREFIX + "Preview"; 
              // used from InvokeParams.as 
               
              String encodedFlashVars = "localeChain=" + localeChain; 
               
              String letterId = (String) request.getParameter(URLPARAM_LETTERID); 
              if (letterId != null && !"".equals(letterId)) 
                  encodedFlashVars += "&" + URLPARAM_LETTERID + "=" + URLEncoder.encode(letterId); 
               
              String letterName = (String) request.getParameter(URLPARAM_LETTERNAME); 
              if (letterName != null && !"".equals(letterName)) 
                  encodedFlashVars += "&" + URLPARAM_LETTERNAME + "=" + letterName; 
                   
              String letterVersion = (String) request.getParameter(URLPARAM_LETTERVERSION); 
              if (letterVersion != null && !"".equals(letterVersion)) 
                  encodedFlashVars += "&" + URLPARAM_LETTERVERSION + "=" + letterVersion; 
                   
              String useLatest = (String) request.getParameter(URLPARAM_USELATEST); 
              if (useLatest != null && !"".equals(useLatest)) 
                  encodedFlashVars += "&" + URLPARAM_USELATEST + "=" + useLatest; 
                   
              String useTestData = (String) request.getParameter(URLPARAM_USETESTDATA); 
              if (useTestData != null && !"".equals(useTestData)) 
                  encodedFlashVars += "&" + URLPARAM_USETESTDATA + "=" + useTestData; 
                   
              String data = (String) request.getParameter(URLPARAM_DATA); 
              if (data != null && !"".equals(data)) 
                  encodedFlashVars += "&" + URLPARAM_DATA + "=" + URLEncoder.encode(data); 
                   
              String dataUrl = (String) request.getParameter(URLPARAM_DATAURL); 
              if (dataUrl != null && !"".equals(dataUrl)) 
                  encodedFlashVars += "&" + URLPARAM_DATAURL + "=" + URLEncoder.encode(dataUrl); 
                   
              String preview = (String) request.getParameter(URLPARAM_PREVIEW); 
              if (preview != null && !"".equals(preview)) 
              encodedFlashVars += "&" + URLPARAM_PREVIEW + "=" + preview; 
           
           
           
           
      %> 
       
      <script language="JavaScript" type="text/javascript"> 
      <!-- 
      var flashVarsStr = "<%= encodedFlashVars %>"; 
       
       
      // the windowPreExitHandler() function, defined in dcScript.js, is called when the Browser window is closed 
      window.onbeforeunload = windowPreExitHandler; 
       
      // fix-up for Safari PDF display that still allows accessibility under IE 
      var dcWMode = "window"; 
      if (navigator.userAgent.indexOf("IE") >= 0 || 
          navigator.userAgent.indexOf("Safari")  >= 0) 
          dcWMode = "transparent"; 
       
       
       
      // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65) 
      var hasProductInstall = DetectFlashVer(6, 0, 65); 
       
      // Version check based upon the values defined in globals 
      var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); 
       
       
      if ( hasProductInstall && !hasRequestedVersion ) 
      { 
          // DO NOT MODIFY THE FOLLOWING FOUR LINES 
          // Location visited after installation is complete if installation is required 
          var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn"; 
          var MMredirectURL = window.location; 
          document.title = document.title.slice(0, 47) + " - Flash Player Installation"; 
          var MMdoctitle = document.title; 
       
          AC_FL_RunContent( 
              "id",                     "ccrSwf", 
              "name",                 "ccrSwf", 
              "src",                     "playerProductInstall", 
              "FlashVars",             "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"", 
              "width",                 "100%", 
              "height",                 "100%", 
              "align",                 "middle", 
              "quality",                 "high", 
              "bgcolor",                 "#869ca7", 
              "wmode",                 dcWMode, 
              "allowScriptAccess",    "sameDomain", 
              "type",                 "application/x-shockwave-flash", 
              "pluginspage",             "http://www.adobe.com/go/getflashplayer" 
          ); 
      } 
      else if (hasRequestedVersion) 
      { 
          AC_FL_RunContent( 
                  "id",                     "ccrSwf", 
                  "name",                 "ccrSwf", 
                  "src",                     "/apps/solutions/cm/ccr/index", 
                  "flashVars",                 flashVarsStr, 
                  "width",                 "100%", 
                  "height",                 "100%", 
                  "align",                 "middle", 
                  "quality",                 "high", 
                  "bgcolor",                 "#869ca7", 
                  "wmode",                 dcWMode, 
                  "allowScriptAccess",    "sameDomain", 
                  "type",                 "application/x-shockwave-flash", 
                  "pluginspage",             "http://www.adobe.com/go/getflashplayer" 
          ); 
      } 
      else        // Flash Player version is too old or we can't detect the plug-in 
      { 
          var alternateContent = '' 
                + 'This content requires the Adobe Flash Player. ' 
                 + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>'; 
          document.write(alternateContent);  // insert non-Flash content 
      } 
       
      <!-- Add the division that will contain the PDF --> 
      document.write("<div id='divContainingIFrame' style='position: absolute; border: 2px; visibility: visible;'><object width='1' height='1' type='application/pdf' data='/apps/solutions/cm/ccr.pdf' /></div>"); 
      // --> 
      </script> 
       
      <noscript> 
          <br/><br/><br/><br/> 
          <p>This web page requires that your browser have scripting enabled.</p> 
          <p>Please enable scripting, and/or contact your system administrator.</p> 
      </noscript> 
       
      </body> 
      </html>
  3. Modifiez l’ActionScript de l’application principale de création de correspondance. Modifiez la classe ActionScript de l’application principale de création de correspondance (@ CorrespondenceManagementSolutionTemplate/CreateCorrespondence/src/main/flex/com/adobe/solutions/cmg/ccr/presentation/CCRApplication.as) de manière à ce qu’elle accepte les variables Flash et peuple ou initialise les paramètres InvokeParams pour l’application de création de correspondance. Après l’instanciation des paramètres InvokeParams, vous pouvez charger ou remplacer les paramètres à partir de ce qui est transmis dans les variables Flash.
    .... 
    invocationParams = new InvokeParams(htmlUrl); // load the params from what's in the URL 
                 
    // now load the params from what's been POSTed - perference is given to the POST data (if present), so as to reject anything that the user tries to override from the URL  
    buildInvocationParamsFromRequest(invocationParams); 
    ....             
     
    } 
     
    private function _buildInvocationParamsFromRequest(invocationParams:InvokeParams):void 
            { 
                var letterId:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_LETTERID]; 
                if (letterId && letterId.length > 0) 
                    invocationParams.letterId = letterId; 
                 
                var letterName:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_LETTERNAME]; 
                if (letterName && letterName.length > 0) 
                    invocationParams.letterName = letterName; 
                 
                var letterVersion:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_LETTERVERSION]; 
                if (letterVersion && letterVersion.length > 0) 
                    invocationParams.letterVersion = parseInt(letterVersion); 
                 
                var useLatest:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_USELATEST]; 
                if (useLatest && useLatest.length > 0) 
                    invocationParams.useLatest = (parseInt(useLatest) != 0); 
                 
                var useTestData:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_USETESTDATA]; 
                if (useTestData && useTestData.length > 0) 
                    invocationParams.useTestData = (parseInt(useTestData) != 0); 
                 
                var data:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_DATA]; 
                if (data && data.length > 0) 
                    invocationParams.xmlData = XML(data); 
                 
                var dataUrl:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_DATAURL]; 
                if (dataUrl && dataUrl.length > 0) 
                    invocationParams.dataUrl = dataUrl; 
                 
                var preview:String = FlexGlobals.topLevelApplication.parameters[InvokeParams.URLPARAM_PREVIEW]; 
                if (preview && preview.length > 0) 
                    invocationParams.preview = (parseInt(preview) != 0); 
                 
            }
  4. Copiez le fichier ccr.jsp sous le nom ccr.POST.jsp. Pour permettre la résolution de l’URL fondée sur la méthode POST, créez une copie du fichier CorrespondenceManagementSolutionTemplate\CreateCorrespondence\html-template\ccr.jsp sous le nom ccr.POST.jsp au même emplacement.

  5. Régénérez et redéployez le modèle de solution pour afficher les changements. Pour plus d’informations sur la régénération et le redéploiement, voir Génération et déploiement du modèle de solution.

A la suite de ces changements, votre application est en mesure de traiter les envois de données basés sur la méthode POST.

Remarque : pour un envoi de données basé sur la méthode POST, authentifiez la session avec CRX avant de lancer la demande d’appel POST. Pour ce faire, déployez/créez la page de portail personnalisée dans CRX et refusez l’autorisation jcr:read aux utilisateurs anonymes pour ce nœud.