42. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/10/2017 1:01:43 PM 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\IV-ehmp_cif\ImagingBaseWebFacade\main\src\java\gov\va\med\imaging\wado AbstractBaseImageServlet.java Thu Jun 29 17:23:05 2017 UTC
2 C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\ImagingBaseWebFacade\main\src\java\gov\va\med\imaging\wado AbstractBaseImageServlet.java Thu Jul 6 15:02:15 2017 UTC

42.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 2046
Changed 3 6
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   package go v.va.med.i maging.wad o;
  2  
  3   import gov .va.med.Gl obalArtifa ctIdentifi er;
  4   import gov .va.med.Pa tientArtif actIdentif ierImpl;
  5   import gov .va.med.Pa tientIdent ifier;
  6   import gov .va.med.Ro utingToken ;
  7   import gov .va.med.Ro utingToken Impl;
  8   import gov .va.med.SE RIALIZATIO N_FORMAT;
  9   import gov .va.med.ex ceptions.R outingToke nFormatExc eption;
  10   import gov .va.med.im aging.Imag eURN;
  11   import gov .va.med.im aging.Imag ingBaseWeb FacadeRout er;
  12   import gov .va.med.im aging.Inst anceChecks umNotifica tion;
  13   import gov .va.med.im aging.chan nels.Abstr actBytePum p.TRANSFER _TYPE;
  14   import gov .va.med.im aging.chan nels.ByteS treamPump;
  15   import gov .va.med.im aging.core .FacadeRou terUtility ;
  16   import gov .va.med.im aging.core .interface s.ImageMet adataNotif ication;
  17   import gov .va.med.im aging.core .interface s.PhotoIDI nformation Notificati on;
  18   import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on;
  19   import gov .va.med.im aging.core .interface s.exceptio ns.ImageCo nversionEx ception;
  20   import gov .va.med.im aging.core .interface s.exceptio ns.ImageNe arLineExce ption;
  21   import gov .va.med.im aging.core .interface s.exceptio ns.ImageNo tCachedExc eption;
  22   import gov .va.med.im aging.core .interface s.exceptio ns.ImageNo tFoundExce ption;
  23   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  24   import gov .va.med.im aging.core .interface s.exceptio ns.Securit yCredentia lsExpiredE xception;
  25   import gov .va.med.im aging.exch ange.Image AccessLogE vent;
  26   import gov .va.med.im aging.exch ange.Image AccessLogE vent.Image AccessLogE ventType;
  27   import gov .va.med.im aging.exch ange.busin ess.Abstra ctBaseServ let;
  28   import gov .va.med.im aging.exch ange.busin ess.ImageF ormatQuali tyList;
  29   import gov .va.med.im aging.exch ange.busin ess.ImageM etadata;
  30   import gov .va.med.im aging.exch ange.busin ess.docume nts.Docume ntRetrieve Result;
  31   import gov .va.med.im aging.exch ange.busin ess.util.E xchangeUti l;
  32   import gov .va.med.im aging.exch ange.enums .ImageForm at;
  33   import gov .va.med.im aging.exch ange.enums .ImageQual ity;
  34   import gov .va.med.im aging.tran sactioncon text.Trans actionCont ext;
  35   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ;
  36   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extHttpHea ders;
  37   import gov .va.med.im aging.wado .query.Wad oRequest;
  38   import gov .va.med.im aging.webs ervices.co mmon.Webse rvicesComm on;
  39  
  40   import jav a.io.IOExc eption;
  41   import jav a.io.Input Stream;
  42   import jav a.io.Outpu tStream;
  43   import jav a.util.Lis t;
  44  
  45   import jav ax.servlet .ServletEx ception;
  46   import jav ax.servlet .http.Http ServletReq uest;
  47   import jav ax.servlet .http.Http ServletRes ponse;
  48  
  49   import org .apache.lo g4j.Logger ;
  50  
  51   /**
  52    * The abs tract root  of Image  providing  servlets i n the VIX  architectu re.
  53    * 
  54    * @author         
BECKEC
  55    */
  56   public abs tract clas s Abstract BaseImageS ervlet 
  57   extends Ab stractBase Servlet
  58   {
  59           pr ivate stat ic final l ong serial VersionUID  = 1L;
  60           pr ivate fina l static L ogger logg er = Logge r.getLogge r(Abstract BaseImageS ervlet.cla ss);
  61           
  62           pr otected Lo gger getLo gger()
  63           {
  64                    retu rn logger;
  65           }
  66  
  67           /* *
  68            *  Construct or of the  object.
  69            * /
  70           pu blic Abstr actBaseIma geServlet( )
  71           {
  72                    supe r();
  73           }
  74           
  75           /* *
  76            *  Method to  get the u sers site  number, mu st be impl emented by  extending  class
  77            *  @return
  78            * /
  79           pu blic abstr act String  getUserSi teNumber() ;
  80  
  81           /* *
  82            *  Returns i nformation  about the  servlet,  such as 
  83            *  author, v ersion, an d copyrigh t. 
  84            *
  85            *  @return S tring info rmation ab out this s ervlet
  86            * /
  87           pu blic Strin g getServl etInfo()
  88           {
  89                    retu rn "The ab stract roo t of Image  providing  servlets  in the VIX  architect ure.";
  90           }
  91  
  92           /* *
  93            *  Derived s ervlets mu st impleme nt a doGet  method
  94            *  @see java x.servlet. http.HttpS ervlet#doG et(javax.s ervlet.htt p.HttpServ letRequest , javax.se rvlet.http .HttpServl etResponse )
  95            * /
  96           @O verride
  97       protec ted abstra ct void do Get(HttpSe rvletReque st req, Ht tpServletR esponse re sp) 
  98           th rows Servl etExceptio n, IOExcep tion;
  99           
  100           /* *
  101            *  
  102            *  @param re sp
  103            *  @param im ageUrn
  104            *  @param co ntentType
  105            *  @return
  106            *  @throws I OException
  107            * /     
  108           pr otected lo ng streamI mageInstan ceByUrn(
  109                             ImageU RN imageUr n, 
  110                             ImageQ uality req uestedImag eQuality,
  111                             List<I mageFormat > acceptab leResponse Content, 
  112                             Output Stream out Stream,
  113                             ImageM etadataNot ification  checksumNo tification )
  114           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  115           {
  116                    retu rn streamI mageInstan ceByUrn(im ageUrn, re questedIma geQuality,  
  117                             accept ableRespon seContent,  outStream , checksum Notificati on, true);
  118           }
  119           
  120           /* *
  121            *  
  122            *  @param im ageUrn
  123            *  @param re questedIma geQuality
  124            *  @param ac ceptableRe sponseCont ent
  125            *  @param ou tStream
  126            *  @param ch ecksumNoti fication
  127            *  @param lo gImageAcce ss
  128            *  @return
  129            *  @throws I OException
  130            *  @throws I mageServle tException
  131            * /
  132           pr otected lo ng streamI mageInstan ceByUrn(
  133                             ImageU RN imageUr n, 
  134                             ImageQ uality req uestedImag eQuality,
  135                             List<I mageFormat > acceptab leResponse Content, 
  136                             Output Stream out Stream,
  137                             ImageM etadataNot ification  checksumNo tification ,
  138                             boolea n logImage Access)
  139           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  140           {
  141                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  142                    Imag eFormatQua lityList q ualityList  = new Ima geFormatQu alityList( );
  143                    qual ityList.ad dAll(accep tableRespo nseContent , requeste dImageQual ity);
  144                    
  145                    getL ogger().in fo("Gettin g image in stance by  URN [" + i mageUrn.to String() +  "] with r equest for mat: " + q ualityList .getAccept String(tru e, true));
  146                    long  bytesTran sferred =  0;
  147                    try 
  148                    {
  149                             bytesT ransferred  = (Long)g etRouter() .getInstan ceByImageU RN(
  150                                                       im ageUrn, 
  151                                                       qu alityList,  
  152                                                       ou tStream, 
  153                                                       ch ecksumNoti fication);
  154                             getLog ger().debu g("Wrote [ " + bytesT ransferred  + "] byte s to outpu t stream f or image [ " + imageU rn.toStrin g() + "]") ;
  155                             
  156                             
  157                             if(log ImageAcces s)
  158                             {
  159                                      if(reque stedImageQ uality !=  ImageQuali ty.THUMBNA IL)
  160                                      {
  161                                              
  162                                               try
  163                                               {
  164                                                       Im ageAccessL ogEvent lo gEvent = c reateImage AccessLogE vent(image Urn);
  165                                                       ge tLogger(). info("Got  image, log ging image  access ("  + logEven t.getEvent Type().toS tring() +  ") for " +
  166                                                                         "image  [" + imag eUrn.toStr ing() + "]  by ["
  167                                                                         //+ Tr ansactionC ontextFact ory.get(). getTransac tionId() +  "].");
  168                                                                         //+ th is.transac tionId + " ].");                           
  169                                                                         + tran sactionCon text.getTr ansactionI d() + "]." );
  170                                                       ge tRouter(). logImageAc cessEventR etryable(l ogEvent);
  171                                               }
  172                                               catch(Serv letExcepti on sX)
  173                                               {
  174                                                       ge tLogger(). error("Err or logging  image acc ess event,  " + sX.ge tMessage() , sX);
  175                                               }
  176                                      }
  177                             }
  178                    } 
  179                    catc h (ImageNe arLineExce ption inle )
  180                    {
  181                             String  message =  "Image ["  + imageUr n.toString () + "] fo und only i n off-line  storage.\ n" +
  182                                      "Please  resubmit i mage acces s request  later, ope rator has  been notif ied to loa d media.";
  183                             getLog ger().debu g(message) ;
  184                             transa ctionConte xt.setExce ptionClass Name(inle. getClass() .getSimple Name());
  185                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_C ONFLICT, m essage);
  186                    }
  187                    catc h (ImageCo nversionEx ception ic e) 
  188                    {
  189                             String  message =  
  190                                      "Image [ " + imageU rn.toStrin g() + 
  191                                      "] found  in a diff erent form at and con version to  the reque sted type  failed.\n"  + 
  192                                      ice.getM essage();
  193                             getLog ger().debu g(message) ;
  194                             transa ctionConte xt.setExce ptionClass Name(ice.g etClass(). getSimpleN ame());
  195                             // JMW  6/23/08 -  if there  is an imag e conversi on error,  it will co me out as  an interna l server e rror (500)
  196                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  197                    }
  198                    catc h(ImageNot FoundExcep tion infX)
  199                    {
  200                             String  message =  "Image ["  + imageUr n.toString () + "] no t found.\n " + infX.g etMessage( );
  201                             //Tran sactionCon textFactor y.get().se tErrorMess age(messag e); // not  needed he re                   
  202                             getLog ger().debu g(message) ;
  203                             transa ctionConte xt.setExce ptionClass Name(infX. getClass() .getSimple Name());
  204                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);
  205                    }
  206                    catc h(MethodEx ception mX )
  207                    {
  208                             String  message =  
  209                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  210                                      mX.getMe ssage();
  211                             getLog ger().erro r(message,  mX);
  212                             handle MethodExce ption(mX);
  213                             // the  MethodExc eption is  not a Secu rityCreden tialsExpir edExceptio n and must  still be  handled.
  214                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());                          
  215                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  216                    }
  217                    catc h(Exceptio n x) 
  218                    {
  219                             String  message =  
  220                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  221                                      x.getMes sage();
  222                             getLog ger().erro r(message,  x);
  223                             transa ctionConte xt.setExce ptionClass Name(x.get Class().ge tSimpleNam e());
  224                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  225                    }
  226                    retu rn bytesTr ansferred;
  227           }
  228  
  229           /* *
  230            *  This meth od will at tempt to c onvert the  MethodExc eption int o a Securi tyCredenti alsExcepti on
  231            *  and then  throw the  appropriat e ImageSer vletExcept ion which  contains a n appropri ate error  code
  232            *  indicatin g the cred entials ex ception.
  233            *  
  234            *  If the Me thodExcept ion cannot  be conver ted into a  SecurityC redentials Exception  then this  method
  235            *  does noth ing and th e MethodEx ception mu st be hand led.
  236            *  
  237            *  @param mX
  238            *  @throws I mageServle tException
  239            * /
  240           pr otected vo id handleM ethodExcep tion(Metho dException  mX)
  241           th rows Secur ityCredent ialsExpire dException   
  242           {
  243                    Webs ervicesCom mon.throwS ecurityCre dentialsEx ceptionFro mMethodExc eption(mX) ;
  244                    /*
  245                    try
  246                    {
  247                             Webser vicesCommo n.throwSec urityCrede ntialsExce ptionFromM ethodExcep tion(mX);
  248                    }
  249                    catc h(Security Credential sExpiredEx ception sc eX)
  250                    {
  251                             Transa ctionConte xtFactory. get().setE xceptionCl assName(sc eX.getClas s().getSim pleName()) ;
  252                             // pre condition  failed (41 2) error
  253                             throw  new Securi tyCredenti alsExpired Exception( HttpServle tResponse. SC_PRECOND ITION_FAIL ED, sceX.g etMessage( ));
  254                    }*/
  255           }
  256           
  257           pr otected Se curityCred entialsExp iredExcept ion findSe curityCred entialsExc eption(Met hodExcepti on mX)
  258           {
  259                    try
  260                    {
  261                             Webser vicesCommo n.throwSec urityCrede ntialsExce ptionFromM ethodExcep tion(mX);
  262                    }
  263                    catc h(Security Credential sExpiredEx ception sc eX)
  264                    {
  265                             return  sceX;
  266                    }
  267                    retu rn null;
  268           }
  269           
  270           pr ivate Imag eAccessLog Event crea teImageAcc essLogEven t(ImageURN  imageUrn)
  271           {
  272                    getL ogger().in fo("Router Impl.logIm ageAccess( " + imageU rn.toStrin g() + ") b y [" + Tra nsactionCo ntextFacto ry.get().g etTransact ionId() +  "].");
  273                    Stri ng imageId  = imageUr n.getImage Id();
  274                    Stri ng siteNum ber = imag eUrn.getOr iginatingS iteId();
  275                    
  276                    bool ean dodIma ge = false ;                
  277                    if(E xchangeUti l.isSiteDO D(siteNumb er))
  278                             dodIma ge = true;
  279  
  280                    Stri ng userSit eNumber =  getUserSit eNumber();
  281  
  282                    // J MW 12/27/2 012 - this  is only u sed for Ex change/XCA  requests,  not for i nternal VA  (Clin Dis p, VRad, e tc) reques ts. As a r esult the  patient ID  should al ways be an  ICN
  283                    Imag eAccessLog Event logE vent = new  ImageAcce ssLogEvent (imageId,  "",
  284                                      imageUrn .getPatien tId(), ima geUrn.getO riginating SiteId(),  System.cur rentTimeMi llis(), 
  285                                      "", "",  ImageAcces sLogEventT ype.IMAGE_ ACCESS, do dImage, us erSiteNumb er);
  286                    retu rn logEven t;
  287           }
  288           
  289           pr otected in t streamTx tFileInsta nceByUrn(
  290                             ImageU RN imageUr n,                        
  291                             Output Stream out Stream,
  292                             ImageM etadataNot ification  metadataNo tification )
  293           th rows IOExc eption, Im ageServlet Exception,  SecurityC redentials ExpiredExc eption
  294           {
  295                    getL ogger().de bug("Getti ng TXT fil e instance  by URN ["  + imageUr n.toString () + "]");
  296                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  297                    try 
  298                    {                         
  299                             int by tesReturne d = 
  300                                      getRoute r().getTxt FileByImag eURN(image Urn, 
  301                                               outStream,  metadataN otificatio n);
  302                             getLog ger().debu g("Pushing  TXT file  instance b y URN [" +  imageUrn. toString()  + "]..");
  303                             return  bytesRetu rned;
  304                    }        
  305                    catc h(ImageNot FoundExcep tion infX)
  306                    {                                                    
  307                             getLog ger().erro r("Error g etting TXT  file for  URN [" + i mageUrn.to String() +  "]", infX );                                   
  308                             String  message =  "Error ge tting TXT  file for U RN [" + im ageUrn.toS tring() +  "].\n" + i nfX.getMes sage();
  309                             transa ctionConte xt.setErro rMessage(m essage);
  310                             transa ctionConte xt.setExce ptionClass Name(infX. getClass() .getSimple Name());
  311                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);                                                  
  312                    } 
  313                    catc h (ImageNe arLineExce ption inle )
  314                    {
  315                             String  message =  "TXT file  [" + imag eUrn.toStr ing() + "]  found onl y in off-l ine storag e.\n" +
  316                                      "Please  resubmit i mage acces s request  later, ope rator has  been notif ied to loa d media.";
  317                             getLog ger().debu g(message) ;
  318                             transa ctionConte xt.setExce ptionClass Name(inle. getClass() .getSimple Name());
  319                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_C ONFLICT, m essage);
  320                    }
  321                    catc h(MethodEx ception mX
  322                    {
  323                             String  message =  
  324                                      "Interna l server e rror in ac cessing TX T file ["  + imageUrn .toString( ) + "] \n"  + 
  325                                      mX.getMe ssage();
  326                             getLog ger().debu g(message) ;
  327                             handle MethodExce ption(mX);
  328                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());
  329                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  330                    }
  331                    catc h(Connecti onExceptio n mX) 
  332                    {
  333                             String  message =  
  334                                      "Interna l server e rror in ac cessing TX T file ["  + imageUrn .toString( ) + "] \n"  + 
  335                                      mX.getMe ssage();
  336                             getLog ger().debu g(message) ;
  337                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());
  338                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  339                    }
  340                    catc h(ServletE xception s X) 
  341                    {
  342                             String  message =  
  343                                      "Interna l server e rror in ac cessing TX T file ["  + imageUrn .toString( ) + "] \n"  + 
  344                                      sX.getMe ssage();
  345                             getLog ger().debu g(message) ;
  346                             transa ctionConte xt.setExce ptionClass Name(sX.ge tClass().g etSimpleNa me());
  347                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  348                    }
  349                    catc h(Exceptio n x) 
  350                    {
  351                             String  message =  
  352                                      "Interna l server e rror in ac cessing TX T file ["  + imageUrn .toString( ) + "] \n"  + 
  353                                      x.getMes sage();
  354                             getLog ger().erro r(message,  x);
  355                             transa ctionConte xt.setExce ptionClass Name(x.get Class().ge tSimpleNam e());
  356                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  357                    }
  358           }
  359           
  360           /* *
  361            *  This meth od actuall y streams  the image  to the res ult
  362            *  @param do cumentIden tifier
  363            *  @return
  364            *  @throws I OException
  365            *  @throws I mageServle tException
  366            * /
  367           pr otected lo ng streamD ocument(Gl obalArtifa ctIdentifi er documen tIdentifie r, OutputS tream outS tream,
  368                             ImageM etadataNot ification  checksumNo tification )
  369           th rows IOExc eption, Im ageServlet Exception
  370           {
  371                    Docu mentRetrie veResult d ocumentRet rieveResul t = retrie veDocument (documentI dentifier,  
  372                                      checksum Notificati on);
  373                    Byte StreamPump  pump = By teStreamPu mp.getByte StreamPump ();
  374                    Inpu tStream in put = docu mentRetrie veResult.g etDocument Stream();
  375                    long  bytes = 0 L;
  376                    
  377                    try
  378                    {
  379                             bytes  = pump.xfe r(input, o utStream);
  380                    }
  381                    fina lly
  382                    {
  383                             // mus t close in put stream  or causes  problems  in the cac he
  384                             try
  385                             {
  386                                      if(input  != null)
  387                                               input.clos e();
  388                             }
  389                             catch( IOExceptio n ioX)
  390                             {
  391                                      getLogge r().warn(" IOExceptio n caught w hen closin g document  stream '"  + documen tIdentifie r.toString () + ", "  + ioX.getM essage());
  392                             }
  393                    }
  394                    //TO DO: use ch ecksumNoti fication -  need to a dd to use  in command
  395                    retu rn bytes;
  396           }
  397           
  398           /* *
  399            *  
  400            *  @deprecat ed Prefer  to use ret rieveDocum ent(Global ArtifactId entifier d ocumentIde ntifier,
  401                             ImageM etadataNot ification  checksumNo tification )
  402            *  @param do cumentIden tifier
  403            *  @return
  404            *  @throws I OException
  405            *  @throws I mageServle tException  
  406            * /
  407           @D eprecated
  408           pr otected Do cumentRetr ieveResult  retrieveD ocument(Gl obalArtifa ctIdentifi er documen tIdentifie r)
  409           th rows IOExc eption, Im ageServlet Exception
  410           {
  411                    retu rn retriev eDocument( documentId entifier,  null);
  412           }
  413           
  414           /* *
  415            *  
  416            *  @param do cumentIden tifier
  417            *  @return
  418            *  @throws I OException
  419            *  @throws I mageServle tException
  420            * /
  421           pr otected Do cumentRetr ieveResult  retrieveD ocument(Gl obalArtifa ctIdentifi er documen tIdentifie r,
  422                             ImageM etadataNot ification  checksumNo tification )
  423           th rows IOExc eption, Im ageServlet Exception
  424           {
  425                    getL ogger().de bug("Getti ng Documen t instance  by identi fier [" +  documentId entifier.t oString()  + "]");
  426                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  427                    try 
  428                    {                         
  429                             if(che cksumNotif ication ==  null)
  430                                      return g etRouter() .getDocume nt(documen tIdentifie r);
  431                             else
  432                                      return g etRouter() .getDocume nt(documen tIdentifie r, checksu mNotificat ion);                         
  433                    }        
  434                    catc h(ImageNot FoundExcep tion infX)
  435                    {                                                    
  436                             getLog ger().erro r("Error g etting Doc ument inst ance for U RN [" + do cumentIden tifier.toS tring() +  "]", infX) ;                               
  437                             String  message =  "Error ge tting Docu ment insta nce for UR N [" + doc umentIdent ifier.toSt ring() + " ].\n" + in fX.getMess age();
  438                             transa ctionConte xt.setErro rMessage(m essage);
  439                             transa ctionConte xt.setExce ptionClass Name(infX. getClass() .getSimple Name());
  440                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);                                                  
  441                    } 
  442                    catc h(MethodEx ception mX
  443                    {
  444                             String  message =  
  445                                      "Interna l server e rror in ac cessing Do cument ins tance [" +  documentI dentifier. toString()  + "] \n" 
  446                                      mX.getMe ssage();
  447                             getLog ger().debu g(message) ;
  448                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());
  449                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  450                    }
  451                    catc h(Connecti onExceptio n mX) 
  452                    {
  453                             String  message =  
  454                                      "Interna l server e rror in ac cessing Do cument ins tance [" +  documentI dentifier. toString()  + "] \n" 
  455                                      mX.getMe ssage();
  456                             getLog ger().debu g(message) ;
  457                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());
  458                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  459                    }
  460                    catc h(ServletE xception s X) 
  461                    {
  462                             String  message =  
  463                                      "Interna l server e rror in ac cessing Do cument ins tance [" +  documentI dentifier. toString()  + "] \n" 
  464                                      sX.getMe ssage();
  465                             getLog ger().debu g(message) ;
  466                             transa ctionConte xt.setExce ptionClass Name(sX.ge tClass().g etSimpleNa me());
  467                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  468                    }
  469           }
  470           
  471           /* *
  472            *  Given a s ite number  and a pat ient ICN,  get a phot o ID of th e patient  and
  473            *  stream it  to the gi ven output  stream.
  474            *  
  475            *  @param si teNumber
  476            *  @param pa tientIcn
  477            *  @param ou tStream
  478            *  @throws I OException
  479            *  @throws I mageServle tException
  480            * /
  481           pr otected lo ng streamP atientIdIm ageByPatie ntIcn(
  482                             String  siteNumbe r, 
  483                             Patien tIdentifie r patientI dentifier,
  484                             PhotoI DInformati onNotifica tion photo IdInformat ionNotific ation,
  485                             Output Stream out Stream)
  486           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  487           {
  488                    getL ogger().de bug("Getti ng patient  ID file i nstance by  patient I CN [" + pa tientIdent ifier + "] ");
  489                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  490                    long  bytesTran sferred =  0;
  491                    try 
  492                    {
  493                             InputS tream pati entIdInStr eam = null ;
  494                             if(pho toIdInform ationNotif ication ==  null)
  495                             {
  496                                      patientI dInStream  = getRoute r().getPat ientIdenti ficationIm age(patien tIdentifie r,                                            
  497                                               RoutingTok enImpl.cre ateVADocum entSite(si teNumber)) ;
  498                             }
  499                             else
  500                             {
  501                                      patientI dInStream  = getRoute r().getPat ientIdenti ficationIm age(patien tIdentifie r,                                            
  502                                               RoutingTok enImpl.cre ateVADocum entSite(si teNumber),
  503                                               photoIdInf ormationNo tification );
  504                             }
  505                             
  506                             if (pa tientIdInS tream == n ull) 
  507                             {
  508                                      String m essage = " No patient  photo ID  available  for [" + p atientIden tifier + " ].";
  509                                      Transact ionContext Factory.ge t().setErr orMessage( message);
  510                                      getLogge r().debug( message);
  511                                      throw ne w ImageSer vletExcept ion(HttpSe rvletRespo nse.SC_NOT _FOUND, me ssage);
  512                             }
  513                             else     // SUCCE SS (SC_OK)  -- 200
  514                             {
  515                                      String m essage = " Pushing pa tient phot o ID for [ " + patien tIdentifie r + "].";
  516                                      getLogge r().debug( message);
  517                                      
  518                                      ByteStre amPump pum p = ByteSt reamPump.g etByteStre amPump(TRA NSFER_TYPE .FileToNet work);
  519                                      
  520                                      bytesTra nsferred =  pump.xfer (patientId InStream,  outStream) ;
  521                                      patientI dInStream. close();
  522                             }
  523                    } 
  524                    catc h (ImageNe arLineExce ption inle )
  525                    {
  526                             String  message =  "Patient  ID photo f or [" + pa tientIdent ifier + "]  found onl y in off-l ine storag e.\n" +
  527                                      "Please  resubmit i mage acces s request  later, ope rator has  been notif ied to loa d media.";
  528                             getLog ger().debu g(message) ;
  529                             transa ctionConte xt.setExce ptionClass Name(inle. getClass() .getSimple Name());
  530                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_C ONFLICT, m essage);
  531                    }
  532                    catc h (ImageNo tFoundExce ption inle )
  533                    {
  534                             String  message =  "Patient  ID photo f or [" + pa tientIdent ifier + "]  from site  [" + site Number + " ] not foun d.";
  535                             getLog ger().debu g(message) ;
  536                             transa ctionConte xt.setExce ptionClass Name(inle. getClass() .getSimple Name());
  537                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);
  538                    }
  539                    catc h(MethodEx ception mX
  540                    {
  541                             String  message =  
  542                                      "Interna l server e rror in ge tting pati ent ID pho to [" + pa tientIdent ifier + "]  \n" + 
  543                                      mX.getMe ssage();
  544                             getLog ger().debu g(message) ;
  545                             handle MethodExce ption(mX);
  546                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());
  547                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  548                    }
  549                    catc h(Connecti onExceptio n mX) 
  550                    {
  551                             String  message =  
  552                                      "Interna l server e rror in ge tting pati ent ID pho to [" + pa tientIdent ifier + "]  \n" + 
  553                                      mX.getMe ssage();
  554                             getLog ger().debu g(message) ;
  555                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());
  556                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_B AD_GATEWAY , message) ;
  557                    }
  558                    catc h(ServletE xception s X) 
  559                    {
  560                             String  message =  
  561                                      "Interna l server e rror in ge tting pati ent ID pho to [" + pa tientIdent ifier + "]  \n" + 
  562                                      sX.getMe ssage();
  563                             getLog ger().debu g(message) ;
  564                             transa ctionConte xt.setExce ptionClass Name(sX.ge tClass().g etSimpleNa me());
  565                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  566                    }
  567                    catc h (Routing TokenForma tException  rtfX)
  568                    {
  569                             String  message =  
  570                                      "Interna l server e rror in ge tting pati ent ID pho to [" + pa tientIdent ifier + "]  \n" + 
  571                                      rtfX.get Message();
  572                             getLog ger().debu g(message) ;
  573                             transa ctionConte xt.setExce ptionClass Name(rtfX. getClass() .getSimple Name());
  574                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  575                    }                 
  576                    retu rn bytesTr ansferred;
  577           }
  578           
  579           pr otected lo ng streamP atientIdIm ageByPatie ntIcn(
  580                    Stri ng siteNum ber, 
  581                    Pati entIdentif ier patien tIdentifie r,
  582                    Outp utStream o utStream)
  583           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  584           {
  585                    retu rn streamP atientIdIm ageByPatie ntIcn(site Number, pa tientIdent ifier, nul l, outStre am);
  586           }
  587           
  588           /* *
  589            *  Initializ e the thre ad local t ransaction  context f rom the Wa doRequest
  590            *  @param wa doRequest
  591            *  @throws R outingToke nFormatExc eption 
  592            * /
  593           pr otected vo id initTra nsactionCo ntext(Wado Request wa doRequest)  
  594           th rows Routi ngTokenFor matExcepti on
  595           {
  596                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  597                    tran sactionCon text.setQu eryFilter( "n/a");
  598                    Imag eQuality i mageQualit y = ImageQ uality.get ImageQuali ty( wadoRe quest.getW adoQuery() .getImageQ ualityValu e() );
  599                    Imag eURN image URN = wado Request ==  null ? nu ll : wadoR equest.get WadoQuery( ).getInsta nceUrn();
  600                    Glob alArtifact Identifier  gai = wad oRequest = = null ? n ull : wado Request.ge tWadoQuery ().getGlob alArtifact Identifier ();
  601                    tran sactionCon text.setQu ality(imag eQuality = = null ? I mageQualit y.THUMBNAI L.toString () : image Quality.na me());
  602                    tran sactionCon text.setQu eryFilter( "n/a");
  603                    
  604                    // i f the prot ocolOverri de and tar getSite we re passed  in the que ry string  then
  605                    // s tuff them  onto the t ransaction  context.
  606                    // T hese are f or testing , NOT prod uction.
  607                    Stri ng targetS ite = wado Request.ge tParsedHtt pHeader(). getMiscReq uestHeader ("targetSi te");
  608                    Stri ng protoco lOverride  = wadoRequ est.getPar sedHttpHea der().getM iscRequest Header("pr otocolOver ride");
  609                    if(t argetSite  != null &&  targetSit e.length()  > 0 && pr otocolOver ride != nu ll && prot ocolOverri de.length( ) > 0)
  610                    {
  611                             Routin gToken rou tingToken  = RoutingT okenImpl.c reateVARad iologySite (targetSit e);
  612                             transa ctionConte xt.setOver rideProtoc ol(protoco lOverride) ;
  613                             transa ctionConte xt.setOver rideRoutin gToken(rou tingToken) ;
  614                             getLog ger().warn ("Protocol  override  and target  server ar e specifie d in the q uery strin g.  This a ctivates t est code a nd should  never be s een in pro duction.") ;
  615                    }
  616                    
  617                    if ( imageURN ! = null)
  618                    {
  619                             String  patientIc n = "";
  620                             String  imageUrnA sString =  "";
  621                             // ori ginating s ite id mea ns locatio n where th e image is  coming fr om 
  622                             //TODO : look at  this logic  more clos ely to mak e more gen eric for c ommon prov iders
  623                             patien tIcn = ima geURN.getP atientId() ; // no lo nger encod e the pati ent ICN
  624                             imageU rnAsString  = Transac tionContex tFactory.d ecodeUrnFo rLogging(i mageURN);/ /  decodeD odUrnForLo gging(imag eURN.toStr ing());
  625  
  626                             
  627                             transa ctionConte xt.setPati entID(pati entIcn);
  628                             transa ctionConte xt.setUrn( imageUrnAs String);
  629                             transa ctionConte xt.setModa lity(image URN.getIma geModality ());
  630                    }
  631                    else  if(gai !=  null)
  632                    {
  633                             transa ctionConte xt.setUrn( gai.toStri ng(SERIALI ZATION_FOR MAT.RAW));
  634                             if(gai  instanceo f PatientA rtifactIde ntifierImp l)
  635                             {
  636                                      PatientA rtifactIde ntifierImp l pai = (P atientArti factIdenti fierImpl)g ai;
  637                                      transact ionContext .setPatien tID(pai.ge tPatientId entifier() );
  638                             }
  639                    }
  640                    tran sactionCon text.setRe questType( "image tra nsfer");
  641           }
  642           
  643           /* *
  644            *  Destructi on of the  servlet. < br>
  645            * /
  646           pu blic void  destroy()
  647           {
  648                    supe r.destroy( ); 
  649           }        
  650  
  651           /* *
  652            *  An except ion class  that is us ed by this  class and  its deriv ations
  653            *  to notify  of error  conditions .
  654            *  
  655              * @author        
BECKEC
  656            *
  657            * /
  658           pu blic class  ImageServ letExcepti on
  659           ex tends Exce ption
  660           {
  661                    priv ate static  final lon g serialVe rsionUID =  1L;
  662                    priv ate final  int respon seCode;
  663                    
  664                    Imag eServletEx ception(in t response Code, Stri ng message )
  665           {
  666                    supe r(message) ;
  667                    this .responseC ode = resp onseCode;
  668           }
  669  
  670                    publ ic int get ResponseCo de()
  671           {
  672                    retu rn respons eCode;
  673           }
  674           }
  675           
  676           pr otected lo ng streamE xamImageIn stanceFrom CacheByUrn (ImageURN  imageUrn, 
  677                    Imag eQuality r equestedIm ageQuality ,
  678                    List <ImageForm at> accept ableRespon seContent,  
  679                    Outp utStream o utStream,
  680                    Imag eMetadataN otificatio n checksum Notificati on)
  681           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  682           {
  683                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  684                    Imag eFormatQua lityList q ualityList  = new Ima geFormatQu alityList( );
  685                    qual ityList.ad dAll(accep tableRespo nseContent , requeste dImageQual ity);
  686                    
  687                    getL ogger().in fo("Gettin g exam ima ge instanc e from cac he by URN  [" + image Urn.toStri ng() + "]  with reque st format:  " + quali tyList.get AcceptStri ng(true, t rue));
  688                    long  bytesTran sferred =  0;
  689                    try 
  690                    {
  691                             bytesT ransferred  = (Long)g etRouter() .getExamIn stanceFrom CacheByIma geUrn(
  692                                                       im ageUrn, 
  693                                                       ch ecksumNoti fication,
  694                                                       ou tStream,
  695                                                       qu alityList) ;
  696                             getLog ger().debu g("Wrote [ " + bytesT ransferred  + "] byte s to outpu t stream f or exam im age [" + i mageUrn.to String() +  "]");                                          
  697                    } 
  698                    // n ot doing i mage conve rsion for  this call,  only poss ible excep tion is im age not ca ched or me thod excep tion
  699                    catc h(ImageNot CachedExce ption incX )
  700                    {
  701                             String  message =  "Image ["  + imageUr n.toString () + "] no t found in  cache.\n"  + incX.ge tMessage() ;                         
  702                             getLog ger().debu g(message) ;
  703                             transa ctionConte xt.setExce ptionClass Name(incX. getClass() .getSimple Name());
  704                             // sen ding a 404  error whe n image no t in the c ache
  705                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);
  706                    }
  707                    catc h(MethodEx ception mX )
  708                    {
  709                             String  message =  
  710                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  711                                      mX.getMe ssage();
  712                             getLog ger().erro r(message,  mX);
  713                             handle MethodExce ption(mX);
  714                             // the  MethodExc eption is  not a Secu rityCreden tialsExpir edExceptio n and must  still be  handled.
  715                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());                          
  716                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  717                    }
  718                    catc h(Exceptio n x) 
  719                    {
  720                             String  message =  
  721                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  722                                      x.getMes sage();
  723                             getLog ger().debu g(message) ;
  724                             transa ctionConte xt.setExce ptionClass Name(x.get Class().ge tSimpleNam e());
  725                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  726                    }
  727                    retu rn bytesTr ansferred;
  728           }        
  729           
  730           /* *
  731            *  
  732            *  @param im ageUrn
  733            *  @param re questedIma geQuality
  734            *  @param ac ceptableRe sponseCont ent
  735            *  @param ou tStream
  736            *  @param ch ecksumNoti fication
  737            *  @param al lowedFromC ache
  738            *  @return
  739            *  @throws I OException
  740            *  @throws S ecurityCre dentialsEx piredExcep tion
  741            *  @throws I mageServle tException
  742            * /
  743           pr otected lo ng streamE xamImageIn stanceByUr n(
  744                    Imag eURN image Urn, 
  745                    Imag eQuality r equestedIm ageQuality ,
  746                    List <ImageForm at> accept ableRespon seContent,  
  747                    Outp utStream o utStream,
  748                    Imag eMetadataN otificatio n checksum Notificati on,
  749                    bool ean allowe dFromCache )
  750           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  751           {
  752                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  753                    Imag eFormatQua lityList q ualityList  = new Ima geFormatQu alityList( );
  754                    qual ityList.ad dAll(accep tableRespo nseContent , requeste dImageQual ity);
  755                    
  756                    getL ogger().in fo("Gettin g exam ima ge instanc e by URN [ " + imageU rn.toStrin g() + "] w ith reques t format:  " + qualit yList.getA cceptStrin g(true, tr ue));
  757                    long  bytesTran sferred =  0;
  758                    try 
  759                    {
  760                             if(all owedFromCa che)
  761                             {
  762                                      bytesTra nsferred =  (Long)get Router().g etExamInst anceByImag eUrn(
  763                                                                imag eUrn, 
  764                                                                chec ksumNotifi cation,
  765                                                                outS tream,
  766                                                                qual ityList);
  767                             }
  768                             else
  769                             {
  770                                      bytesTra nsferred =  (Long)get Router().g etExamInst anceByImag eUrnNotFro mCache(
  771                                                       im ageUrn, 
  772                                                       ch ecksumNoti fication,
  773                                                       ou tStream,
  774                                                       qu alityList) ;
  775                             }
  776                             getLog ger().debu g("Wrote [ " + bytesT ransferred  + "] byte s to outpu t stream f or exam im age [" + i mageUrn.to String() +  "]");                                          
  777                    } 
  778                    catc h (ImageNe arLineExce ption inle )
  779                    {
  780                             String  message =  "Image ["  + imageUr n.toString () + "] fo und only i n off-line  storage.\ n" +
  781                                      "Please  resubmit i mage acces s request  later, ope rator has  been notif ied to loa d media.";
  782                             getLog ger().debu g(message) ;
  783                             transa ctionConte xt.setExce ptionClass Name(inle. getClass() .getSimple Name());
  784                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_C ONFLICT, m essage);
  785                    }
  786                    catc h (ImageCo nversionEx ception ic e) 
  787                    {
  788                             String  message =  
  789                                      "Image [ " + imageU rn.toStrin g() + 
  790                                      "] found  in a diff erent form at and con version to  the reque sted type  failed.\n"  + 
  791                                      ice.getM essage();
  792                             getLog ger().debu g(message) ;
  793                             transa ctionConte xt.setExce ptionClass Name(ice.g etClass(). getSimpleN ame());
  794                             // JMW  6/23/08 -  if there  is an imag e conversi on error,  it will co me out as  an interna l server e rror (500)
  795                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  796                    }
  797                    catc h(ImageNot FoundExcep tion infX)
  798                    {
  799                             String  message =  "Image ["  + imageUr n.toString () + "] no t found.\n " + infX.g etMessage( );
  800                             //Tran sactionCon textFactor y.get().se tErrorMess age(messag e); // not  needed he re                   
  801                             getLog ger().debu g(message) ;
  802                             transa ctionConte xt.setExce ptionClass Name(infX. getClass() .getSimple Name());
  803                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);
  804                    }
  805                    catc h(MethodEx ception mX )
  806                    {
  807                             String  message =  
  808                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  809                                      mX.getMe ssage();
  810                             getLog ger().erro r(message,  mX);
  811                             handle MethodExce ption(mX);
  812                             // the  MethodExc eption is  not a Secu rityCreden tialsExpir edExceptio n and must  still be  handled.
  813                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());                          
  814                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  815                    }
  816                    catc h(Exceptio n x) 
  817                    {
  818                             String  message =  
  819                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  820                                      x.getMes sage();
  821                             getLog ger().debu g(message) ;
  822                             transa ctionConte xt.setExce ptionClass Name(x.get Class().ge tSimpleNam e());
  823                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  824                    }
  825                    retu rn bytesTr ansferred;
  826           }
  827           
  828           /* *
  829            *  Get the i mage metad ata (to sa tisfy an H TTP HEAD r equest).
  830            *  
  831            *  @param im ageUrn
  832            *  @param re questedIma geQuality
  833            *  @param ac ceptableRe sponseCont ent
  834            *  @param al lowedFromC ache
  835            *  @return
  836            * /
  837           pr otected Im ageMetadat a getImage MetadataBy URN(
  838                    Imag eURN image Urn, 
  839                    Imag eQuality r equestedIm ageQuality ,
  840                    List <ImageForm at> accept ableRespon seContent,  
  841                    bool ean requir eFromCache ,
  842                    bool ean allowe dFromCache )
  843           th rows IOExc eption, Se curityCred entialsExp iredExcept ion, Image ServletExc eption
  844           {
  845                    Imag eMetadata  result = n ull;
  846                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  847                    Imag eFormatQua lityList r equestedFo rmatQualit y = new Im ageFormatQ ualityList ();
  848                    requ estedForma tQuality.a ddAll(acce ptableResp onseConten t, request edImageQua lity);
  849                    
  850                    getL ogger().in fo("Gettin g exam ima ge instanc e by URN [ " + imageU rn.toStrin g() + "] w ith reques t format:  " + reques tedFormatQ uality.get AcceptStri ng(true, t rue));
  851                    
  852                    try  {
  853                             result  = getRout er().headI nstanceByI mageUrnVer bose(image Urn, reque stedFormat Quality, n ull, false , false, t rue);
  854                    } 
  855                    catc h (ImageNe arLineExce ption inle )
  856                    {
  857                             String  message =  "Image ["  + imageUr n.toString () + "] fo und only i n off-line  storage.\ n" +
  858                                      "Please  resubmit i mage acces s request  later, ope rator has  been notif ied to loa d media.";
  859                             getLog ger().debu g(message) ;
  860                             transa ctionConte xt.setExce ptionClass Name(inle. getClass() .getSimple Name());
  861                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_C ONFLICT, m essage);
  862                    }
  863                    catc h (ImageCo nversionEx ception ic e) 
  864                    {
  865                             String  message =  
  866                                      "Image [ " + imageU rn.toStrin g() + 
  867                                      "] found  in a diff erent form at and con version to  the reque sted type  failed.\n"  + 
  868                                      ice.getM essage();
  869                             getLog ger().debu g(message) ;
  870                             transa ctionConte xt.setExce ptionClass Name(ice.g etClass(). getSimpleN ame());
  871                             // JMW  6/23/08 -  if there  is an imag e conversi on error,  it will co me out as  an interna l server e rror (500)
  872                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  873                    }
  874                    catc h(ImageNot FoundExcep tion infX)
  875                    {
  876                             String  message =  "Image ["  + imageUr n.toString () + "] no t found.\n " + infX.g etMessage( );
  877                             //Tran sactionCon textFactor y.get().se tErrorMess age(messag e); // not  needed he re                   
  878                             getLog ger().debu g(message) ;
  879                             transa ctionConte xt.setExce ptionClass Name(infX. getClass() .getSimple Name());
  880                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_N OT_FOUND,  message);
  881                    }
  882                    catc h(MethodEx ception mX )
  883                    {
  884                             String  message =  
  885                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  886                                      mX.getMe ssage();
  887                             getLog ger().erro r(message,  mX);
  888                             handle MethodExce ption(mX);
  889                             // the  MethodExc eption is  not a Secu rityCreden tialsExpir edExceptio n and must  still be  handled.
  890                             transa ctionConte xt.setExce ptionClass Name(mX.ge tClass().g etSimpleNa me());                          
  891                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  892                    }
  893                    catc h(Exceptio n x) 
  894                    {
  895                             String  message =  
  896                                      "Interna l server e rror in ac cessing im age [" + i mageUrn.to String() +  "] \n" + 
  897                                      x.getMes sage();
  898                             getLog ger().debu g(message) ;
  899                             transa ctionConte xt.setExce ptionClass Name(x.get Class().ge tSimpleNam e());
  900                             throw  new ImageS ervletExce ption(Http ServletRes ponse.SC_I NTERNAL_SE RVER_ERROR , message) ;
  901                    }
  902                    
  903                    retu rn result;
  904           }
  905           
  906           pr otected sy nchronized  ImagingBa seWebFacad eRouter ge tRouter()
  907           th rows Servl etExceptio n
  908           {
  909                    Imag ingBaseWeb FacadeRout er router;
  910                    try
  911                    {
  912                             router  = FacadeR outerUtili ty.getFaca deRouter(I magingBase WebFacadeR outer.clas s);
  913                    } 
  914                    catc h (Excepti on x)
  915                    {
  916                             logger .error("Ex ception ge tting the  facade rou ter implem entation." , x);
  917                             return  null;
  918                    }
  919                    
  920                    retu rn router;
  921           }
  922           
  923           /* *
  924            *  @deprecat ed This is  no longer  used, use  MetadataN otificatio n instead
  925            * /
  926           @D eprecated
  927           pu blic class  ChecksumN otificatio
  928           im plements I nstanceChe cksumNotif ication
  929           {
  930                    priv ate HttpSe rvletRespo nse resp;
  931                    
  932                    publ ic Checksu mNotificat ion(HttpSe rvletRespo nse resp)
  933                    {
  934                             this.r esp = resp ;
  935                    }
  936                    
  937                    publ ic void in stanceChec ksum(Strin g checksum Value)
  938                    {
  939                             if(che cksumValue  != null)
  940                                      resp.add Header(Tra nsactionCo ntextHttpH eaders.htt pHeaderChe cksum, che cksumValue );
  941                    }
  942                    
  943           }
  944           
  945           /* *
  946            *  Metadata  notificati on to set  properties  of the HT TP respons e that ind icate
  947            *  key field s of the r esponded i mage. This  includes  setting th e checksum
  948            *  image con tent type,  content l ength and  optionally  the image  quality a nd the ful l type 
  949            *  of the im age (appli cable if D ICOM to in clude the  sub type)
  950              * @author        
WERFEJ
  951            *
  952            * /
  953           pu blic class  MetadataN otificatio n
  954           im plements I mageMetada taNotifica tion
  955           {
  956                    priv ate final  HttpServle tResponse  resp;
  957                    priv ate final  boolean in cludeCusto mHeaders;
  958                    
  959                    publ ic Metadat aNotificat ion(HttpSe rvletRespo nse resp,  boolean in cludeCusto mHeaders)
  960                    {
  961                             this.r esp = resp ;
  962                             this.i ncludeCust omHeaders  = includeC ustomHeade rs;
  963                    }
  964                    
  965                    /**
  966                     * C onstructor  that does  not inclu de custom  headers in  the respo nse
  967                     * @ param resp
  968                     */
  969                    publ ic Metadat aNotificat ion(HttpSe rvletRespo nse resp)
  970                    {
  971                             this.r esp = resp ;
  972                             this.i ncludeCust omHeaders  = false;
  973                    }
  974                    
  975                    @Ove rride
  976                    publ ic void im ageMetadat a(String c hecksumVal ue,
  977                                      ImageFor mat imageF ormat, int  fileSize,  ImageQual ity imageQ uality) 
  978                    {
  979                             Transa ctionConte xt transac tionContex t = Transa ctionConte xtFactory. get();
  980                             if(che cksumValue  != null)
  981                             {
  982                                      // in so me cases t his was ge tting call ed twice o n a single  image res ponse, che ck for an  existing
  983                                      // check sum value  and update  it if it  exists
  984                                      if(resp. containsHe ader(Trans actionCont extHttpHea ders.httpH eaderCheck sum))
  985                                      {
  986                                               logger.war n("Header  '" + Trans actionCont extHttpHea ders.httpH eaderCheck sum + "' a lready has  value, up dating to  new value  '" + check sumValue +  "'.");
  987                                               resp.setHe ader(Trans actionCont extHttpHea ders.httpH eaderCheck sum, check sumValue);
  988                                      }
  989                                      else
  990                                      {                                  
  991                                               resp.addHe ader(Trans actionCont extHttpHea ders.httpH eaderCheck sum, check sumValue);
  992                                      }
  993                             }
  994                             if(ima geFormat ! = null)
  995                             {
  996                                      resp.set ContentTyp e(imageFor mat.getMim e());
  997                                      if(inclu deCustomHe aders)
  998                                      {
  999                                               resp.addHe ader(Trans actionCont extHttpHea ders.httpH eaderVista ImageForma t, 
  1000                                                       im ageFormat. getMimeWit hEnclosedM ime());
  1001                                      }
  1002                                      transact ionContext .setFacade ImageForma tSent(imag eFormat.to String());
  1003                             }        
  1004                             if(ima geQuality  != null)
  1005                             {
  1006                                      if(inclu deCustomHe aders)
  1007                                      {
  1008                                               resp.addHe ader(Trans actionCont extHttpHea ders.httpH eaderImage Quality, 
  1009                                                       im ageQuality .getCanoni cal() + "" );
  1010                                      }
  1011                                      transact ionContext .setFacade ImageQuali tySent(ima geQuality. toString() );
  1012                             }                                  
  1013                             if(inc ludeCustom Headers)
  1014                             {
  1015                                      String m achineName  = transac tionContex t.getMachi neName();
  1016                                      if(machi neName ==  null)
  1017                                               machineNam e = "<unkn own>";
  1018                                      resp.add Header(Tra nsactionCo ntextHttpH eaders.htt pHeaderMac hineName,  machineNam e);
  1019  
  1020                                      String c acheFilena me = trans actionCont ext.getCac heFilename ();
  1021                                      if (cach eFilename  != null)
  1022                                               resp.addHe ader(Trans actionCont extHttpHea ders.httpH eaderCache Filename,  cacheFilen ame);
  1023                             }
  1024                    }                 
  1025           }        
  1026   }