42. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/25/2019 8:58:03 AM Central 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.

42.1 Files compared

# Location File Last Modified
1 C:\AraxisMergeCompare\Pri_un\IMAG_Source\VISA\Java\ImagingExchangeBaseWebProxy\main\src\java\gov\va\med\imaging\proxy\rest AbstractRestClient.java Mon Mar 18 20:39:09 2019 UTC
2 C:\AraxisMergeCompare\Pri_re\IMAG_Source\VISA\Java\ImagingExchangeBaseWebProxy\main\src\java\gov\va\med\imaging\proxy\rest AbstractRestClient.java Tue Mar 19 12:03:50 2019 UTC

42.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 670
Changed 2 4
Inserted 0 0
Removed 0 0

42.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

42.4 Active regular expressions

No regular expressions were active.

42.5 Comparison detail

  1   /**
  2    * 
  3     Package:  MAG - Vis tA Imaging
  4     WARNING:  Per VHA D irective 2 004-038, t his routin e should n ot be modi fied.
  5     Date Cre ated: Jun  28, 2010
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:     DNS     werfej
  8     Descript ion: 
  9  
  10           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  11           ;;  Property  of the US  Government .
  12           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  13           ;;  Use of un released v ersions of  this soft ware requi res the us er
  14           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  15           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  16           ;;   telephon e (301) 73 4-0100.
  17           ;;
  18           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  19           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  20           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  21           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  22           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  23           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  24  
  25    */
  26   package go v.va.med.i maging.pro xy.rest;
  27  
  28   import gov .va.med.Pa tientIdent ifier;
  29   import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on;
  30   import gov .va.med.im aging.core .interface s.exceptio ns.Insuffi cientPatie ntSensitiv ityExcepti on;
  31   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  32   import gov .va.med.im aging.core .interface s.exceptio ns.Patient NotFoundEx ception;
  33   import gov .va.med.im aging.core .interface s.exceptio ns.Securit yCredentia lsExpiredE xception;
  34   import gov .va.med.im aging.exch ange.busin ess.Patien tSensitive Value;
  35   import gov .va.med.im aging.exch ange.enums .PatientSe nsitivityL evel;
  36   import gov .va.med.im aging.rest .exception s.RestExce ptionCodes ;
  37   import gov .va.med.im aging.rest .exception s.RestExce ptionMessa ge;
  38   import gov .va.med.im aging.rest .exception s.RestInsu fficientPa tientSensi tivityExce ptionMessa ge;
  39   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ;
  40   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extHttpHea ders;
  41  
  42   import jav a.io.Buffe redReader;
  43   import jav a.io.IOExc eption;
  44   import jav a.io.Input Stream;
  45   import jav a.io.Input StreamRead er;
  46   import jav a.util.Has hMap;
  47   import jav a.util.Map ;
  48  
  49   import jav ax.ws.rs.c ore.MediaT ype;
  50  
  51   import org .apache.lo gging.log4 j.LogManag er;
  52   import org .apache.lo gging.log4 j.Logger;
  53  
  54   import com .sun.jerse y.api.clie nt.Client;
  55   import com .sun.jerse y.api.clie nt.ClientH andlerExce ption;
  56   import com .sun.jerse y.api.clie nt.ClientR esponse;
  57   import com .sun.jerse y.api.clie nt.ClientR esponse.St atus;
  58   import com .sun.jerse y.api.clie nt.Uniform InterfaceE xception;
  59   import com .sun.jerse y.api.clie nt.WebReso urce;
  60   import com .sun.jerse y.api.clie nt.config. ClientConf ig;
  61   import com .sun.jerse y.api.clie nt.config. DefaultCli entConfig;
  62   import com .sun.jerse y.client.a pache.Apac heHttpClie nt;
  63  
  64   /**
  65    * @author   DNS     werfej
  66    *
  67    */
  68   public abs tract clas s Abstract RestClient
  69   {
  70           pr ivate fina l static L ogger logg er = LogMa nager.getL ogger(Abst ractRestCl ient.class );
  71           pr otected fi nal WebRes ource.Buil der reques t;    
  72           pr ivate fina l int meta dataTimeou tMs;
  73           
  74           //  ok to hav e one sing le client  for the en tire appli cation, it  is thread  safe (see  comment b elow)
  75           // private st atic Clien t client =  null;
  76           pr ivate stat ic Map<Int eger, Clie nt> client Pool = new  HashMap<I nteger, Cl ient>();
  77           
  78           /* *
  79            *  According  to https: //jersey.d ev.java.ne t/nonav/do cumentatio n/latest/u ser-guide. html#d4e60 4
  80            *  Clients a re expensi ve, and th read safe,  so only c reate them  once
  81            *  
  82            *  @param fe derationCo nfiguratio n
  83            *  @return
  84            * /
  85           pr ivate stat ic synchro nized Clie nt getClie nt(int met adataTimeo utMs)
  86           {
  87                    // u se a map t o pool con nections b ased on th e timeout
  88                    Clie nt client  = clientPo ol.get(met adataTimeo utMs);
  89                    if(c lient == n ull)
  90                    {
  91                             Defaul tClientCon fig client Config = n ew Default ClientConf ig();
  92                             
  93                             client Config.get Properties ().put(
  94                                      ClientCo nfig.PROPE RTY_CONNEC T_TIMEOUT,  30000);
  95                             client Config.get Properties ().put(
  96                                      ClientCo nfig.PROPE RTY_READ_T IMEOUT, me tadataTime outMs);
  97                             // Acc ording to  http://jer sey.java.n et/nonav/a pidocs/1.2 /contribs/ jersey-apa che-client /com/sun/j ersey/clie nt/apache/ ApacheHttp Client.htm l
  98                             // som e properti es must be  provided  in constru ctor of Ap acheHttpCl ient           
  99                             client  = ApacheH ttpClient. create(cli entConfig) ;
  100                             
  101                             ((Apac heHttpClie nt)client) .getClient Handler(). getHttpCli ent().getP arams().se tConnectio nManagerTi meout(meta dataTimeou tMs);
  102                             ((Apac heHttpClie nt)client) .getClient Handler(). getHttpCli ent().getH ttpConnect ionManager ().getPara ms().setDe faultMaxCo nnectionsP erHost(50) ;
  103                             ((Apac heHttpClie nt)client) .getClient Handler(). getHttpCli ent().getH ttpConnect ionManager ().getPara ms().setMa xTotalConn ections(20 0);
  104                             
  105                             int de faultMaxCo nnectionsP erHost = ( (ApacheHtt pClient)cl ient).getC lientHandl er().getHt tpClient() .getHttpCo nnectionMa nager().ge tParams(). getDefault MaxConnect ionsPerHos t();
  106                             int ma xTotalConn ections =  ((ApacheHt tpClient)c lient).get ClientHand ler().getH ttpClient( ).getHttpC onnectionM anager().g etParams() .getMaxTot alConnecti ons();
  107                             
  108                             logger .info("Cre ating new  ApacheHttp Client wit h maxConne ctionsPerH ost: " + d efaultMaxC onnections PerHost +  ", and max TotalConne ctions: "  + maxTotal Connection s);
  109                             
  110                             // usi ng HTTP Co mmons Clie nt in orde r to take  advantage  of configu ration for  certifica te
  111                             //clie nt = Apach eHttpClien t.create() ;
  112                             
  113                             client Pool.put(m etadataTim eoutMs, cl ient);
  114                    }
  115                    retu rn client;
  116           }        
  117           
  118           pu blic Abstr actRestCli ent(String  url, Stri ng mediaTy pe, int me tadataTime outMs)
  119           {
  120                    this .metadataT imeoutMs =  metadataT imeoutMs;
  121                    WebR esource we bResource  = createWe bResource( url);
  122                    getL ogger().in fo("Creati ng web req uest to UR L '" + url  + "'.");
  123                    gov. va.med.ima ging.trans actioncont ext.Transa ctionConte xt transac tionContex t = Transa ctionConte xtFactory. get();
  124                    tran sactionCon text.addDe bugInforma tion("REST  request t o '" + url  + "'.");
  125                    requ est = webR esource.ac cept(media Type);
  126                    addT ransaction Headers();
  127           }
  128           
  129           pu blic Abstr actRestCli ent(String  url, Medi aType medi aType, int  metadataT imeoutMs)
  130           {
  131                    this (url, medi aType.toSt ring(), me tadataTime outMs);
  132           }
  133           
  134           pr otected Lo gger getLo gger()
  135           {
  136                    retu rn logger;
  137           }
  138           
  139           pr ivate WebR esource cr eateWebRes ource(Stri ng url)
  140           {
  141                    Clie nt client  = getClien t(this.met adataTimeo utMs);               
  142                    retu rn client. resource(u rl);
  143           }
  144           
  145           /* *
  146            *  Execute t he actual  method wit h the spec ified retu rn type
  147            *  @param <T >
  148            *  @param c
  149            *  @return
  150            * /
  151           // protected  abstract < T extends  Object> T  executeMet hodInterna l(Class<T>  c);
  152           pr otected ab stract <T  extends Ob ject> Clie ntResponse  executeMe thodIntern al(Class<T > c);
  153           
  154           pr otected ab stract voi d addTrans actionHead ers();
  155           
  156           /* *
  157            *  Execute t he request , handles  exceptions  from the  web servic e and conv erts 
  158            *  them to i nternal VI X exceptio ns
  159            *  @param <T >
  160            *  @param c
  161            *  @return
  162            *  @throws M ethodExcep tion
  163            *  @throws C onnectionE xception
  164            * /
  165           pu blic <T ex tends Obje ct> T exec uteRequest (Class<T>  c)
  166           th rows Metho dException , Connecti onExceptio n
  167           {
  168                    Clie ntResponse  clientRes ponse = nu ll;
  169                    try
  170                    {
  171                             try
  172                             {
  173                                      clientRe sponse = e xecuteMeth odInternal (c);
  174                                      if(clien tResponse. getStatus( ) == Statu s.OK.getSt atusCode() )
  175                                      {
  176                                               getLogger( ).debug("W eb Service  Response  return OK. ");
  177                                               // not sur e if this  should be  here - thi s maybe on ly applies  to Federa tion
  178                                               String mac hineName =  
  179                                                       cl ientRespon se.getHead ers().getF irst(Trans actionCont extHttpHea ders.httpH eaderMachi neName);
  180                                                       // clientResp onse.getHe aders().ge tFirst("wl -proxy-cli ent-ip");
  181                    
  182                                               if(machine Name != nu ll)
  183                                                       Tr ansactionC ontextFact ory.get(). setDataSou rceRespons eServer(ma chineName) ;
  184                                               getLogger( ).info("Re ceived res ponse from  machine ' " + machin eName + "' .");
  185                                              
  186                                               if (c == S tring.clas s)
  187                                               {
  188                                                       re turn (T) i nputStream ToString(c lientRespo nse.getEnt ityInputSt ream());
  189                                               }
  190                                               else
  191                                               {
  192                                                       re turn clien tResponse. getEntity( c);
  193                                               }
  194                                      }
  195                                      else{
  196                                               getLogger( ).debug("W eb Service  returned  an error:  " + client Response.g etStatus() );
  197                                      }
  198                             }
  199                             catch( UniformInt erfaceExce ption uiX)
  200                             {                         
  201                                      // this  probably w on't ever  happen any more since  the respo nses from  the Federa tionWebApp  are 
  202                                      // now a ll wrapped  in Respon se objects , but keep ing this h ere just i n case
  203                                      //client Response =  uiX.getRe sponse();
  204                                      getLogge r().warn(" UniformInt erfaceExce ption exec uting GET  request, "  + uiX.get Message()) ;
  205                                      throw ne w Connecti onExceptio n(uiX);
  206                             }
  207                             catch( ClientHand lerExcepti on chX)
  208                             {                         
  209                                      // this  probably w on't ever  happen any more since  the respo nses from  the Federa tionWebApp  are 
  210                                      // now a ll wrapped  in Respon se objects , but keep ing this h ere just i n case
  211                                      //client Response =  clX.getRe sponse();
  212                                      getLogge r().warn(" ClientHand lerExcepti on executi ng GET req uest, " +  chX.getMes sage());
  213                                      throw ne w Connecti onExceptio n(chX);
  214                             }
  215                             catch( Exception  eX)
  216                             {
  217                                      // somet hing went  very wrong  - this sh ould not h appen
  218                                      getLogge r().warn(" Exception  executing  GET reques t, " + eX. getMessage ());
  219                                      throw ne w Connecti onExceptio n(eX);
  220                             }
  221                             if(cli entRespons e != null)
  222                                      handleEx ception(cl ientRespon se);
  223                             throw  new Connec tionExcept ion("Did n ot properl y handle r esponse fr om client  - THIS SHO ULD NEVER  HAPPEN!");
  224                    }
  225                    fina lly
  226                    {
  227                             // acc ording to  http://jer sey.java.n et/nonav/a pidocs/1.2 /contribs/ jersey-apa che-client /com/sun/j ersey/clie nt/apache/ ApacheHttp Client.htm l
  228                             // sho uld call c lose on th e response
  229                             if(cli entRespons e != null)
  230                             {
  231                                      try 
  232                                      { client Response.c lose(); } 
  233                                      catch(Ex ception ex
  234                                      {
  235                                               logger.deb ug("Except ion closin g clientRe sponse, "  + ex.getMe ssage());
  236                                      }
  237                             }
  238                    }
  239           }
  240           
  241           //  convert I nputStream  to String
  242           pr ivate Stri ng inputSt reamToStri ng(InputSt ream is) {
  243  
  244                    Buff eredReader  br = null ;
  245                    Stri ngBuilder  sb = new S tringBuild er();
  246  
  247                    Stri ng line;
  248                    try  {
  249  
  250                             br = n ew Buffere dReader(ne w InputStr eamReader( is));
  251                             while  ((line = b r.readLine ()) != nul l) {
  252                                      sb.appen d(line);
  253                                      sb.appen d("\r\n");
  254                             }
  255  
  256                    } ca tch (IOExc eption e)  {
  257                             getLog ger().erro r("InputSt ream to St ring error . " + e.ge tMessage() );
  258                             return  null;
  259                    } fi nally {
  260                             if (br  != null)  {
  261                                      try {
  262                                               br.close() ;
  263                                      } catch  (IOExcepti on e) {
  264                                               getLogger( ).error("I nputStream  to String  error. "  + e.getMes sage());
  265                                               return nul l;
  266                                      }
  267                             }
  268                    }
  269  
  270  
  271                    retu rn sb.toSt ring();
  272  
  273           }
  274  
  275           pr ivate void  handleExc eption(Cli entRespons e response )
  276           th rows Conne ctionExcep tion, Meth odExceptio n
  277           {
  278                    int  responseSt atus = res ponse.getS tatus();
  279                    getL ogger().wa rn("Receiv ed excepti on with er ror code ' " + respon seStatus +  "'.");
  280                    Stri ng machine Name = 
  281                             respon se.getHead ers().getF irst(Trans actionCont extHttpHea ders.httpH eaderMachi neName);
  282                    if(m achineName  != null)
  283                             Transa ctionConte xtFactory. get().setD ataSourceR esponseSer ver(machin eName);
  284                    getL ogger().in fo("Receiv ed excepti on respons e from mac hine '" +  machineNam e + "'.");
  285                    if(r esponseSta tus >= 600 )
  286                    {                                  
  287                             switch (response. getStatus( ))
  288                             {
  289                                      case Res tException Codes.rest InvalidSec urityCrede ntialsExce ptionCode:
  290                                               throw new  SecurityCr edentialsE xpiredExce ption(getE xceptionMe ssageFromR esponse(re sponse));
  291                                      case Res tException Codes.rest MethodExce ptionCode:
  292                                               throw new  MethodExce ption(getE xceptionMe ssageFromR esponse(re sponse));
  293                                      case Res tException Codes.rest PatientNot FoundExcep tionCode:
  294                                               throw new  PatientNot FoundExcep tion(getEx ceptionMes sageFromRe sponse(res ponse));
  295                                      case Res tException Codes.rest Insufficie ntPatientS ensitivity Code:
  296                                               RestInsuff icientPati entSensiti vityExcept ionMessage  insuffici entPatient Sensitivit yException Message =
  297                                                       re sponse.get Entity(Res tInsuffici entPatient Sensitivit yException Message.cl ass);
  298                                               PatientSen sitivityLe vel sensit iveLevel =  PatientSe nsitivityL evel.getPa tientSensi tivityLeve l(insuffic ientPatien tSensitivi tyExceptio nMessage.g etSensitiv eErrorCode ());
  299                                               PatientSen sitivityLe vel allowe dLevel = P atientSens itivityLev el.getPati entSensiti vityLevel( insufficie ntPatientS ensitivity ExceptionM essage.get AllowedLev elCode());
  300                                               PatientSen sitiveValu e sensitiv eValue = n ew Patient SensitiveV alue(sensi tiveLevel,  insuffici entPatient Sensitivit yException Message.ge tMessage() );
  301                                               Insufficie ntPatientS ensitivity Exception  ipsX = 
  302                                                       In sufficient PatientSen sitivityEx ception.cr eateInsuff icientPati entSensiti vityExcept ion(sensit iveValue, 
  303                                                                         Patien tIdentifie r.icnPatie ntIdentifi er(insuffi cientPatie ntSensitiv ityExcepti onMessage. getPatient Icn()), 
  304                                                                         allowe dLevel);
  305                                               throw ipsX ;
  306                                      default:
  307                                               throw new  Connection Exception( getExcepti onMessageF romRespons e(response ));
  308                             }
  309                    }
  310                    else
  311                    {
  312                             // not  a VIX err or, might  be 404 or  500
  313                             throw  new Connec tionExcept ion("Recie ved except ion of sta tus '" + r esponseSta tus + "'." );
  314                    }
  315           }
  316           
  317           pr ivate Stri ng getExce ptionMessa geFromResp onse(Clien tResponse  response)
  318           {
  319                    Rest ExceptionM essage exc eptionMess age = resp onse.getEn tity(RestE xceptionMe ssage.clas s);
  320                    Stri ng message  = "";
  321                    if(e xceptionMe ssage == n ull)
  322                    {
  323                             // thi s shouldn' t happen,  but if it  does!
  324                             messag e = "Excep tion did n ot contain  message,  this shoul d not happ en.  Error  code was  '" + respo nse.getSta tus() + "' .";
  325                    }
  326                    else
  327                    {
  328                             messag e = except ionMessage .getMessag e();
  329                    }
  330                    retu rn message ;
  331           }
  332  
  333           pr otected We bResource. Builder ge tRequest()  
  334           {
  335                    retu rn request ;
  336           }
  337   }