290. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/11/2019 10:54:16 AM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

290.1 Files compared

# Location File Last Modified
1 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\fw\service\jms AsynchronousMessageProducerServiceImpl.java Wed May 29 15:26:02 2019 UTC
2 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\fw\service\jms AsynchronousMessageProducerServiceImpl.java Mon Jun 10 19:30:05 2019 UTC

290.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 850
Changed 1 2
Inserted 0 0
Removed 0 0

290.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

290.4 Active regular expressions

No regular expressions were active.

290.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** *********
  2    * Copyrii ght 2004 V HA. All ri ghts reser ved
  3    ********* ********** ********** ********** ********** ********** *********/
  4   // Package
  5   package go v.va.med.f w.service. jms;
  6  
  7   // Java cl asses
  8   import jav a.io.Seria lizable;
  9   import jav a.util.Dat e;
  10   import jav a.util.Has hMap;
  11   import jav a.util.Lis t;
  12   import jav a.util.Map ;
  13   import jav a.util.Pro perties;
  14  
  15   import jav ax.jms.JMS Exception;
  16   import jav ax.jms.Mes sage;
  17  
  18   import org .apache.co mmons.lang .Validate;
  19   import org .springfra mework.jms .JmsExcept ion;
  20   import org .springfra mework.jms .core.JmsT emplate;
  21   import org .springfra mework.jms .core.Mess agePostPro cessor;
  22  
  23   import gov .va.med.fw .security. SecurityCo ntextHelpe r;
  24   import gov .va.med.fw .service.A bstractCom ponent;
  25   import gov .va.med.fw .service.C onfigurati onConstant s;
  26   import gov .va.med.fw .util.Stop WatchLogge r;
  27  
  28   /**
  29    * Generic  JMS Messa ge Produce r that can  be wired  for a Queu e or Topic
  30    * destina tion. Hand les wrappi ng message  payload i nto the ap propriate  type of
  31    * JMS Mes age.
  32    * 
  33    * <p>
  34    * Support s configur able fallb ack target s.
  35    * </p>
  36    * 
  37    * <p>
  38    * Relies  on JEE con tainer to  pool JMS C onnectionF actory's.
  39    * </p>
  40    * 
  41    * Created  Jun 18, 2 007 3:50:1 1 PM
  42    * 
  43    * @author   DNS     DN S
  44    */
  45   public cla ss Asynchr onousMessa geProducer ServiceImp l extends  AbstractCo mponent
  46                    impl ements Mes sageProduc erService  {
  47           /* *
  48            *  An instan ce of seri alVersionU ID
  49            * /
  50           pr ivate stat ic final l ong serial VersionUID  = 2808696 4068333322 75L;
  51  
  52           /* *
  53            *  this is n ot real-ti me as it i ndicates t he longest  period of  time in
  54            *  between t wo request s (lazily  checked)
  55            * /
  56           pr ivate int  checkInter valSecsAft erFallback  = 120;
  57  
  58           pr ivate bool ean suppor tsFailover  = true;
  59           pr ivate JmsT emplate jm sTemplateP rimary;
  60           pr ivate List <JmsTempla te> jmsTem platesFall back;
  61  
  62           //  state tra cking
  63           pr ivate JmsT emplate jm sTemplateA ctive;
  64           pr ivate Date  switchedT oFallbackA tThisTime;
  65  
  66           pr ivate bool ean suppor tsDistribu tedTransac tions;
  67  
  68           pu blic boole an isSuppo rtsDistrib utedTransa ctions() {
  69                    retu rn support sDistribut edTransact ions;
  70           }
  71  
  72           pu blic void  setSupport sDistribut edTransact ions(
  73                             boolea n supports Distribute dTransacti ons) {
  74                    this .supportsD istributed Transactio ns = suppo rtsDistrib utedTransa ctions;
  75           }
  76  
  77           @O verride
  78           pu blic void  afterPrope rtiesSet()  throws Ex ception {
  79                    supe r.afterPro pertiesSet ();
  80                    Vali date.notNu ll(jmsTemp latePrimar y, "jmsTem platePrima ry is requ ired");
  81                    if ( this.suppo rtsDistrib utedTransa ctions) {
  82                             jmsTem platePrima ry.setSess ionTransac ted(false) ;
  83  
  84                             // set  also on f allbacks
  85                             if (jm sTemplates Fallback ! = null) {
  86                                      for (Jms Template t arget : jm sTemplates Fallback)  {
  87                                               target.set SessionTra nsacted(fa lse);
  88                                      }
  89                             }
  90                    }
  91           }
  92  
  93           /* *
  94            *  Sends to  injected D estination  (priority ) or injec ted defaul t Destinat ion.
  95            * /
  96           pu blic void  send(final  Serializa ble payloa d)
  97                             throws  MessagePr oducerExce ption {
  98                    send (payload,  (Propertie s) null);
  99           }
  100  
  101           pu blic void  sendToAll( final Seri alizable p ayload)
  102                             throws  MessagePr oducerExce ption {
  103                    send ToAll(payl oad, (Prop erties) nu ll);
  104           }
  105  
  106           pu blic void  send(Messa gePayload  payload) t hrows Mess ageProduce rException  {
  107                    Map< String, Se rializable > props =  new HashMa p<String,  Serializab le>();
  108                    prop s.put(Conf igurationC onstants.D EFAULT_MES SAGE_TYPE,  payload
  109                                      .getTarg etServiceD escriptor( ));
  110                    prop s.put(Conf igurationC onstants.D EFAULT_MES SAGE_INITI ATER,
  111                                      Security ContextHel per.getUse rName());
  112                    prop s.put(Conf igurationC onstants.D EFAULT_MES SAGE_ORIGI NATING_TIM EZONE,
  113                                      Security ContextHel per.getUse rTimeZone( ));
  114  
  115                    // T ODO: make  this condi tional bas ed on depl oyed envir onment so  not to
  116                    // e xpose pote ntial PII
  117                    if ( logger.isD ebugEnable d()) {
  118                             props. put("paylo adSummary" , payload. getPayload ().toStrin g());
  119                    }
  120  
  121                    send (payload.g etPayload( ), props);
  122           }
  123  
  124           pu blic void  sendToAll( MessagePay load paylo ad)
  125                             throws  MessagePr oducerExce ption {
  126                    Map< String, Se rializable > props =  new HashMa p<String,  Serializab le>();
  127                    prop s.put(Conf igurationC onstants.D EFAULT_MES SAGE_TYPE,  payload
  128                                      .getTarg etServiceD escriptor( ));
  129                    prop s.put(Conf igurationC onstants.D EFAULT_MES SAGE_INITI ATER,
  130                                      Security ContextHel per.getUse rName());
  131                    prop s.put(Conf igurationC onstants.D EFAULT_MES SAGE_ORIGI NATING_TIM EZONE,
  132                                      Security ContextHel per.getUse rTimeZone( ));
  133  
  134                    // T ODO: make  this condi tional bas ed on depl oyed envir onment so  not to
  135                    // e xpose pote ntial PII
  136                    if ( logger.isD ebugEnable d()) {
  137                             props. put("paylo adSummary" , payload. getPayload ().toStrin g());
  138                    }
  139  
  140                    send ToAll(payl oad.getPay load(), pr ops);
  141           }
  142  
  143           pu blic void  send(Seria lizable pa yload,
  144                             final  Map<String , Serializ able> head erProperti es)
  145                             throws  MessagePr oducerExce ption {
  146                    Stop WatchLogge r watch =  new StopWa tchLogger( "send JMS" );
  147                    watc h.start();
  148                    bool ean attemp tedFallbac k = false;
  149  
  150                    JmsT emplate ta rgetJmsTem plate = ge tActiveJms Template() ;
  151                    try  {
  152                             target JmsTemplat e.convertA ndSend(pay load,
  153                                               new Messag ePostProce ssor() {
  154                                                       pu blic Messa ge postPro cessMessag e(Message  message)
  155                                                                         throws  JMSExcept ion {
  156                                                                retu rn copyJMS Properties (message,  headerProp erties);
  157                                                       }
  158                                               });
  159                    } ca tch (Excep tion e) {
  160                             attemp tedFallbac k = true;
  161                             attemp tFallbackC onnections (e, target JmsTemplat e, payload ,
  162                                               headerProp erties);
  163                    } fi nally {
  164                             watch. stopAndLog ("attempte dFallback= " + attemp tedFallbac k);
  165                    }
  166           }
  167  
  168           pu blic void  sendToAll( Serializab le payload ,
  169                             final  Map<String , Serializ able> head erProperti es)
  170                             throws  MessagePr oducerExce ption {
  171                    Stop WatchLogge r watch =  new StopWa tchLogger( "send JMS" );
  172                    watc h.start();
  173                    bool ean attemp tedFallbac k = false;
  174  
  175                    JmsT emplate ta rgetJmsTem plate = ge tActiveJms Template() ;
  176                    try  {
  177                             target JmsTemplat e.convertA ndSend(pay load,
  178                                               new Messag ePostProce ssor() {
  179                                                       pu blic Messa ge postPro cessMessag e(Message  message)
  180                                                                         throws  JMSExcept ion {
  181                                                                retu rn copyJMS Properties (message,  headerProp erties);
  182                                                       }
  183                                               });
  184                    } ca tch (Excep tion e) {
  185                             getLog ger().erro r(e);
  186                    }
  187                    for  (JmsTempla te jmsTemp late : jms TemplatesF allback) {
  188                             try {
  189                                      jmsTempl ate.conver tAndSend(p ayload, ne w MessageP ostProcess or() {
  190                                               public Mes sage postP rocessMess age(Messag e message)
  191                                                                thro ws JMSExce ption {
  192                                                       re turn copyJ MSProperti es(message , headerPr operties);
  193                                               }
  194                                      });
  195                             } catc h (Excepti on e) {
  196                                      getLogge r().error( e);
  197                             }
  198                    }
  199                    watc h.stopAndL og("");
  200           }
  201  
  202           pu blic void  send(Seria lizable pa yload, fin al Propert ies header Properties )
  203                             throws  MessagePr oducerExce ption {
  204                    Stop WatchLogge r watch =  new StopWa tchLogger( "send JMS" );
  205                    watc h.start();
  206                    bool ean attemp tedFallbac k = false;
  207  
  208                    JmsT emplate ta rgetJmsTem plate = ge tActiveJms Template() ;
  209                    try  {
  210                             target JmsTemplat e.convertA ndSend(pay load,
  211                                               new Messag ePostProce ssor() {
  212                                                       pu blic Messa ge postPro cessMessag e(Message  message)
  213                                                                         throws  JMSExcept ion {
  214                                                                retu rn copyJMS Properties (message,  headerProp erties);
  215                                                       }
  216                                               });
  217                    } ca tch (Excep tion e) {
  218                             attemp tFallbackC onnections (e, target JmsTemplat e, payload ,
  219                                               headerProp erties);
  220                    } fi nally {
  221                             watch. stopAndLog ("attempte dFallback= " + attemp tedFallbac k);
  222                    }
  223           }
  224  
  225           pu blic void  sendToAll( Serializab le payload ,
  226                             final  Properties  headerPro perties) t hrows Mess ageProduce rException  {
  227                    Stop WatchLogge r watch =  new StopWa tchLogger( "send JMS" );
  228                    watc h.start();
  229                    bool ean attemp tedFallbac k = false;
  230  
  231                    JmsT emplate ta rgetJmsTem plate = ge tActiveJms Template() ;
  232                    try  {
  233                             target JmsTemplat e.convertA ndSend(pay load,
  234                                               new Messag ePostProce ssor() {
  235                                                       pu blic Messa ge postPro cessMessag e(Message  message)
  236                                                                         throws  JMSExcept ion {
  237                                                                retu rn copyJMS Properties (message,  headerProp erties);
  238                                                       }
  239                                               });
  240                    } ca tch (Excep tion e) {
  241                             getLog ger().erro r(e);
  242                    }
  243                    for  (JmsTempla te jmsTemp late : jms TemplatesF allback) {
  244                             try {
  245                                      jmsTempl ate.conver tAndSend(p ayload, ne w MessageP ostProcess or() {
  246                                               public Mes sage postP rocessMess age(Messag e message)
  247                                                                thro ws JMSExce ption {
  248                                                       re turn copyJ MSProperti es(message , headerPr operties);
  249                                               }
  250                                      });
  251                             } catc h (Excepti on e) {
  252                                      getLogge r().error( e);
  253                             }
  254                    }
  255                    watc h.stopAndL og("");
  256           }
  257  
  258           pr ivate JmsT emplate ge tActiveJms Template()  {
  259                    if ( jmsTemplat eActive ==  null) {
  260                             jmsTem plateActiv e = jmsTem platePrima ry;
  261                             switch edToFallba ckAtThisTi me = null;
  262                    } el se if (swi tchedToFal lbackAtThi sTime == n ull) {
  263                             jmsTem plateActiv e = jmsTem platePrima ry;
  264                    } el se if (swi tchedToFal lbackAtThi sTime != n ull) {
  265                             if ((( System.cur rentTimeMi llis() - s witchedToF allbackAtT hisTime
  266                                               .getTime() ) / 1000)  >= checkIn tervalSecs AfterFallb ack) {
  267                                      if (logg er.isInfoE nabled())  {
  268                                               logger
  269                                                                .inf o(getBeanN ame()
  270                                                                                  + " had  previously  falled ba ck to a fa llback Jms Template.. ..checkInt erval of "
  271                                                                                  + checkI ntervalSec sAfterFall back
  272                                                                                  + " has  expired... ..trying p rimary aga in");
  273                                      }
  274                                      jmsTempl ateActive  = jmsTempl atePrimary ;
  275                                      switched ToFallback AtThisTime  = null;
  276                             }
  277                    }
  278  
  279                    retu rn jmsTemp lateActive ;
  280           }
  281  
  282           pr ivate bool ean isConf iguredForF allback()  {
  283                    retu rn support sFailover  && jmsTemp latesFallb ack != nul l
  284                                      && !jmsT emplatesFa llback.isE mpty();
  285           }
  286  
  287           pr ivate void  attemptFa llbackConn ections(Ex ception e,
  288                             JmsTem plate jmsT emplateFai lure, Seri alizable p ayload,
  289                             final  Map header Properties ) throws J MSServiceE xception {
  290                    if ( !isConfigu redForFall back())
  291                             throw  new JMSSer viceExcept ion(
  292                                               "Unable to  send JMS  Message an d not conf igured for  failover  to fallbac k JmsTempl ates - exc eption:",
  293                                               e);
  294  
  295                    if ( logger.isW arnEnabled ()) {
  296                             logger
  297                                               .warn(
  298                                                                "Una ble to sen d JMS Mess age, attem pting fail over to fa llback Jms Templates  due to exc eption:",
  299                                                                e);
  300                    }
  301  
  302                    // f allback
  303                    swit chedToFall backAtThis Time = new  Date();
  304                    int  i = -1;
  305                    bool ean fallba ckResult =  false;
  306                    for  (JmsTempla te target  : jmsTempl atesFallba ck) {
  307                             i++;
  308                             if (ta rget == jm sTemplateF ailure) //  don't ret ry
  309                                      continue ;
  310  
  311                             jmsTem plateActiv e = target ;
  312  
  313                             fallba ckResult =  attemptFa llbackConn ection(jms TemplateAc tive,
  314                                               payload, h eaderPrope rties, "in dex: " + i );
  315                             break;
  316                    }
  317  
  318                    // o ne last ch eck....if  tried all  fallbacks,  also try  primary if  not
  319                    // o riginal fa ilure (in  case a fal lback fail ed)
  320                    if ( !fallbackR esult && j msTemplate Failure !=  jmsTempla tePrimary)  {
  321                             if (at temptFallb ackConnect ion(jmsTem platePrima ry, payloa d,
  322                                               headerProp erties, "l ooped back  to primar y")) {
  323                                      // reset
  324                                      jmsTempl ateActive  = jmsTempl atePrimary ;
  325                                      switched ToFallback AtThisTime  = null;
  326                             }
  327                    }
  328           }
  329  
  330           pr ivate bool ean attemp tFallbackC onnection( JmsTemplat e target,
  331                             Serial izable pay load, fina l Map head erProperti es, String  logMessag e) {
  332                    try  {
  333                             target .convertAn dSend(payl oad, new M essagePost Processor( ) {
  334                                      public M essage pos tProcessMe ssage(Mess age messag e)
  335                                                       th rows JMSEx ception {
  336                                               return cop yJMSProper ties(messa ge, header Properties );
  337                                      }
  338                             });
  339  
  340                             if (lo gger.isInf oEnabled() ) {
  341                                      logger.i nfo("[SUCC ESS JMS FA LLBACK]: "  + logMess age);
  342                             }
  343  
  344                             return  true;
  345                    } ca tch (JmsEx ception e)  {
  346                             if (lo gger.isErr orEnabled( )) {
  347                                      logger.e rror("[FAI LURE JMS F ALLBACK]:  " + logMes sage, e);
  348                             }
  349                    }
  350                    retu rn false;
  351           }
  352  
  353           pr otected Me ssage copy JMSPropert ies(Messag e message,  Map heade rPropertie s)
  354                             throws  JMSExcept ion {
  355                    if ( headerProp erties !=  null) {
  356                             // put  all prope rties in a  message's  propertie s
  357                             for (O bject key  : headerPr operties.k eySet()) {
  358                                      message. setStringP roperty(ke y.toString (), header Properties .get(
  359                                                       ke y).toStrin g());
  360                             }
  361                    }
  362                    retu rn message ;
  363           }
  364  
  365           /* *
  366            *  @return t he jmsTemp latePrimar y
  367            * /
  368           pu blic JmsTe mplate get JmsTemplat ePrimary()  {
  369                    retu rn jmsTemp latePrimar y;
  370           }
  371  
  372           /* *
  373            *  @param jm sTemplateP rimary
  374            *              the jmsT emplatePri mary to se t
  375            * /
  376           pu blic void  setJmsTemp latePrimar y(JmsTempl ate jmsTem platePrima ry) {
  377                    this .jmsTempla tePrimary  = jmsTempl atePrimary ;
  378           }
  379  
  380           /* *
  381            *  @return t he jmsTemp latesFallb ack
  382            * /
  383           pu blic List< JmsTemplat e> getJmsT emplatesFa llback() {
  384                    retu rn jmsTemp latesFallb ack;
  385           }
  386  
  387           /* *
  388            *  @param jm sTemplates Fallback
  389            *              the jmsT emplatesFa llback to  set
  390            * /
  391           pu blic void  setJmsTemp latesFallb ack(List<J msTemplate > jmsTempl atesFallba ck) {
  392                    this .jmsTempla tesFallbac k = jmsTem platesFall back;
  393           }
  394  
  395           /* *
  396            *  @return t he support sFailover
  397            * /
  398           pu blic boole an isSuppo rtsFailove r() {
  399                    retu rn support sFailover;
  400           }
  401  
  402           /* *
  403            *  @param su pportsFail over
  404            *              the supp ortsFailov er to set
  405            * /
  406           pu blic void  setSupport sFailover( boolean su pportsFail over) {
  407                    this .supportsF ailover =  supportsFa ilover;
  408           }
  409  
  410           /* *
  411            *  @return t he checkIn tervalSecs AfterFallb ack
  412            * /
  413           pu blic int g etCheckInt ervalSecsA fterFallba ck() {
  414                    retu rn checkIn tervalSecs AfterFallb ack;
  415           }
  416  
  417           /* *
  418            *  @param ch eckInterva lSecsAfter Fallback
  419            *              the chec kIntervalS ecsAfterFa llback to  set
  420            * /
  421           pu blic void  setCheckIn tervalSecs AfterFallb ack(
  422                             int ch eckInterva lSecsAfter Fallback)  {
  423                    this .checkInte rvalSecsAf terFallbac k = checkI ntervalSec sAfterFall back;
  424           }
  425  
  426   }