Produced by Araxis Merge on 7/10/2017 1:01:47 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\IV-ehmp_cif\VistaStorage\main\src\java\gov\va\med\imaging\vista\storage | SmbStorageUtility.java | Thu Jun 29 17:22:53 2017 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\VistaStorage\main\src\java\gov\va\med\imaging\vista\storage | SmbStorageUtility.java | Thu Jul 6 15:06:17 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 1458 |
| Changed | 2 | 4 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 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: Feb 6, 2008 | |
| 6 | Site Nam e: Washin gton OI Fi eld Office , Silver S pring, MD | |
| 7 | Developer:
|
|
| 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.vis ta.storage ; | |
| 27 | ||
| 28 | import gov .va.med.im aging.core .interface s.ImageSto rageFacade ; | |
| 29 | import gov .va.med.im aging.core .interface s.StorageC redentials ; | |
| 30 | import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on; | |
| 31 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageNe arLineExce ption; | |
| 32 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageNo tFoundExce ption; | |
| 33 | import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception; | |
| 34 | import gov .va.med.im aging.exch ange.busin ess.ImageF ormatQuali tyList; | |
| 35 | import gov .va.med.im aging.exch ange.busin ess.ImageS treamRespo nse; | |
| 36 | import gov .va.med.im aging.exch ange.enums .StoragePr oximity; | |
| 37 | import gov .va.med.im aging.exch ange.stora ge.Abstrac tBufferedI mageStorag eFacade; | |
| 38 | import gov .va.med.im aging.exch ange.stora ge.ByteBuf ferBackedI mageInputS tream; | |
| 39 | import gov .va.med.im aging.exch ange.stora ge.ByteBuf ferBackedI mageStream Response; | |
| 40 | import gov .va.med.im aging.exch ange.stora ge.ByteBuf ferBackedI nputStream ; | |
| 41 | import gov .va.med.im aging.exch ange.stora ge.DataSou rceImageIn putStream; | |
| 42 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont ext; | |
| 43 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ; | |
| 44 | import gov .va.med.im aging.vist a.storage. configurat ion.VistaS torageConf iguration; | |
| 45 | ||
| 46 | import jav a.io.File; | |
| 47 | import jav a.io.FileI nputStream ; | |
| 48 | import jav a.io.FileO utputStrea m; | |
| 49 | import jav a.io.IOExc eption; | |
| 50 | import jav a.io.Input Stream; | |
| 51 | import jav a.io.Outpu tStream; | |
| 52 | import jav a.io.Outpu tStreamWri ter; | |
| 53 | import jav a.io.Write r; | |
| 54 | import jav a.net.Malf ormedURLEx ception; | |
| 55 | import jav a.net.Unkn ownHostExc eption; | |
| 56 | import jav a.util.Arr ayList; | |
| 57 | import jav a.util.Ite rator; | |
| 58 | import jav a.util.Lis t; | |
| 59 | import jav a.util.Sca nner; | |
| 60 | ||
| 61 | import jci fs.smb.Ntl mPasswordA uthenticat ion; | |
| 62 | import jci fs.smb.Smb Exception; | |
| 63 | import jci fs.smb.Smb File; | |
| 64 | import jci fs.smb.Smb FileInputS tream; | |
| 65 | import jci fs.smb.Smb FileOutput Stream; | |
| 66 | import jci fs.util.tr ansport.Tr ansportExc eption; | |
| 67 | ||
| 68 | import org .apache.lo g4j.Logger ; | |
| 69 | ||
| 70 | /** | |
| 71 | * Utility functions to open i mage share s and retr ieve files | |
| 72 | * | |
| 73 | * @author
|
|
| 74 | * | |
| 75 | */ | |
| 76 | public cla ss SmbStor ageUtility | |
| 77 | extends Ab stractBuff eredImageS torageFaca de | |
| 78 | implements ImageStor ageFacade | |
| 79 | { | |
| 80 | pr ivate fina l static L ogger logg er = Logge r.getLogge r(SmbStora geUtility. class); | |
| 81 | ||
| 82 | pu blic final static in t DEFAULT_ MAX_RETRIE S = 3; | |
| 83 | pu blic final static lo ng DEFAULT _RETRY_DEL AY = 2000L ; | |
| 84 | ||
| 85 | // parameter s that aff ect retry logic for off-line i mages. | |
| 86 | pr ivate int maxNearLin eRetries = DEFAULT_M AX_RETRIES ; | |
| 87 | pr ivate long nearLineR etryDelay = DEFAULT_ RETRY_DELA Y; | |
| 88 | ||
| 89 | // private in t defaultB ufferSize = 1024 * 1 6; // 16K buffer see med to giv e optimal performanc e | |
| 90 | ||
| 91 | pr ivate int getNearLin eRetries() | |
| 92 | { | |
| 93 | return m axNearLine Retries; | |
| 94 | } | |
| 95 | ||
| 96 | pu blic long getNearLin eRetryDela y() | |
| 97 | { | |
| 98 | re turn nearL ineRetryDe lay; | |
| 99 | } | |
| 100 | ||
| 101 | st atic | |
| 102 | { | |
| 103 | log ger.info(" JCIFS Conf iguration - jcifs.ne tbios.cach ePolicy = " + jcifs. Config.get Property(" jcifs.netb ios.cacheP olicy") ); | |
| 104 | l ogger.info ("JCIFS Co nfiguratio n - jcifs. smb.client .soTimeout = " + jci fs.Config. getPropert y("jcifs.s mb.client. soTimeout" ) ); | |
| 105 | l ogger.info ("JCIFS Co nfiguratio n - jcifs. smb.client .responseT imeout = " + jcifs.C onfig.getP roperty("j cifs.smb.c lient.resp onseTimeou t") ); | |
| 106 | } | |
| 107 | ||
| 108 | // st atic { | |
| 109 | // Prop erties pro ps = new P roperties( ); | |
| 110 | // prop s.put("jci fs.netbios .cachePoli cy", "3600 "); // ca che the ne twork name s for 1 ho ur (value in seconds , 0 is no caching, - 1 is forev er) | |
| 111 | // // J MW 1/3/200 8 | |
| 112 | // // S et the tim eout value s, these a re suppose d to be th e default values but for some reason the y were not set by de fault prop erly. | |
| 113 | // // W e should d o some exp erimenting with thes e values t o be sure they are s ufficient to access images acr oss the WA N | |
| 114 | // prop s.put("jci fs.smb.cli ent.soTime out", "350 00"); | |
| 115 | // prop s.put("jci fs.smb.cli ent.respon seTimeout" , "35000") ; | |
| 116 | // jcif s.Config.s etProperti es(props); | |
| 117 | // } | |
| 118 | ||
| 119 | /* * | |
| 120 | * Change th e extensio n of a fil e | |
| 121 | * @param fi lename The filename to change | |
| 122 | * @param ne wExtension The new e xtension f or the fil ename (do not includ e the '.') | |
| 123 | * @return | |
| 124 | * / | |
| 125 | pr ivate Stri ng changeF ileExtensi on(String filename, String new Extension) { | |
| 126 | Stri ng fname = filename; | |
| 127 | int loc = file name.lastI ndexOf("." ); | |
| 128 | if(l oc >= 0) { | |
| 129 | fname = filename .substring (0, loc); | |
| 130 | fname += "." + n ewExtensio n; | |
| 131 | } | |
| 132 | retu rn fname; | |
| 133 | } | |
| 134 | ||
| 135 | pu blic Strin g getFileE xtension(S tring file name) | |
| 136 | { | |
| 137 | int loc = file name.lastI ndexOf("." ); | |
| 138 | if(l oc >= 0) | |
| 139 | { | |
| 140 | return filename. substring( loc + 1); | |
| 141 | } | |
| 142 | retu rn filenam e; | |
| 143 | } | |
| 144 | ||
| 145 | ||
| 146 | pr ivate Byte BufferBack edImageStr eamRespons e openFile Stream(Smb Credential s smbCrede ntials, | |
| 147 | NtlmPa sswordAuth entication ntPassAut h, Storage Proximity imageProxi mity) | |
| 148 | th rows Image NotFoundEx ception, I mageNearLi neExceptio n, SmbExce ption, IOE xception | |
| 149 | { | |
| 150 | SmbS erverShare smbServer Share = sm bCredentia ls.getSmbS erverShare (); | |
| 151 | logg er.info("O pening ima ge with UR L '" + smb ServerShar e.getSmbPa th() + "'. "); | |
| 152 | Byte BufferBack edImageStr eamRespons e response = null; | |
| 153 | for( int nearli neRetry=0; nearlineR etry < get NearLineRe tries(); + +nearlineR etry) | |
| 154 | { | |
| 155 | SmbFil e imageFil e = new Sm bFile(smbS erverShare .getSmbPat h(), ntPas sAuth); | |
| 156 | // log ger.info(" Image open ed"); | |
| 157 | if( im ageFile.ca nRead() ) | |
| 158 | { | |
| 159 | int file Length = ( int)imageF ile.length (); | |
| 160 | if(fileL ength > 0) | |
| 161 | { | |
| 162 | logger.inf o("File '" + smbServ erShare.ge tSmbPath() + "' has fileLength =" + fileL ength + ", reading i mage into buffer."); | |
| 163 | response = new ByteB ufferBacke dImageStre amResponse ( | |
| 164 | new ByteBuffer BackedImag eInputStre am(imageFi le.getInpu tStream(), | |
| 165 | (int)ima geFile.len gth(), tru e)); | |
| 166 | logger.inf o("File '" + smbServ erShare.ge tSmbPath() + "' read into buff er."); | |
| 167 | return res ponse; | |
| 168 | } | |
| 169 | else | |
| 170 | { | |
| 171 | // was thr owing File NotFoundEx ception (e xtends IOE xception) - changed to ImageNo tFoundExce ption and improved e rror messa ge | |
| 172 | throw new ImageNotFo undExcepti on("File [ " + smbSer verShare.g etSmbPath( ) + "] has length of [" + file Length + " ], not gre ated than 0 therefor e no image data"); | |
| 173 | } | |
| 174 | } | |
| 175 | // if we cannot read the f ile and th e problem is not tha t the imag e is | |
| 176 | // pro bably near -line then bug out | |
| 177 | else i f( imagePr oximity == null || i mageProxim ity != Sto rageProxim ity.NEARLI NE ) | |
| 178 | throw ne w ImageNot FoundExcep tion("Cann ot read im age file " + smbServ erShare.ge tSmbPath() + ", indi cates file does not exist on s torage sys tem."); | |
| 179 | } | |
| 180 | // i f we get t o here the n the all nearline r etries hav e been exh austed | |
| 181 | // t hrow a nea r-line exc eption | |
| 182 | thro w new Imag eNearLineE xception(" Cannot rea d Near-Lin e image fi le '" + sm bServerSha re.getSmbP ath() + "' yet, retr y later.") ; | |
| 183 | } | |
| 184 | ||
| 185 | pr ivate List <Integer> getSortedC onnectionP orts(SmbSe rverShare smbServerS hare) | |
| 186 | { | |
| 187 | List <Integer> connection Ports = ne w ArrayLis t<Integer> (); | |
| 188 | SmbC onnectionI nformation Manager sm bConnectio nInformati onManager = getSmbCo nnectionIn formationM anager(); | |
| 189 | int firstTryPo rt = | |
| 190 | smbCon nectionInf ormationMa nager.getS uccessfulP ort(smbSer verShare.g etServer() , | |
| 191 | SmbServerS hare.defau ltServerSh arePort); | |
| 192 | conn ectionPort s.add(firs tTryPort); | |
| 193 | ||
| 194 | for( int port : SmbServer Share.poss ibleConnec tionPorts) | |
| 195 | { | |
| 196 | // don 't add the initial p ort again | |
| 197 | if(por t != first TryPort) | |
| 198 | connecti onPorts.ad d(port); | |
| 199 | } | |
| 200 | retu rn connect ionPorts; | |
| 201 | } | |
| 202 | ||
| 203 | pr ivate SmbC onnectionI nformation Manager ge tSmbConnec tionInform ationManag er() | |
| 204 | { | |
| 205 | retu rn SmbConn ectionInfo rmationMan ager.getSm bConnectio nInformati onManager( ); | |
| 206 | } | |
| 207 | ||
| 208 | pr ivate void updateSuc cessfulPor t(SmbServe rShare smb ServerShar e) | |
| 209 | { | |
| 210 | if(s mbServerSh are != nul l) | |
| 211 | { | |
| 212 | SmbCon nectionInf ormationMa nager smbC onnectionI nformation Manager = | |
| 213 | getSmbCo nnectionIn formationM anager(); | |
| 214 | smbCon nectionInf ormationMa nager.upda teSuccessf ulPort(smb ServerShar e.getServe r(), | |
| 215 | smbServerS hare.getPo rt()); | |
| 216 | } | |
| 217 | } | |
| 218 | ||
| 219 | /* * | |
| 220 | * Open the input stre am for the file and create a S izedInputS tream that contains the filesi ze | |
| 221 | * @param fi lename The filename to open (f ull UNC pa th) | |
| 222 | * @param st orageCrede ntials The network l ocation th at stores the file ( with crede ntials set ) | |
| 223 | * @param im ageProximi ty The cur rent locat ion of the image (ma gnetic, wo rm, offlin e) | |
| 224 | * @return T he SizedIn putStream with the i nput strea m open and set to th e desired file and t he number of bytes f rom the fi le set | |
| 225 | * @throws I mageNearLi neExceptio n Occurs i f the imag e is on a jukebox an d is not r eadable | |
| 226 | * @throws I mageNotFou ndExceptio n Occurs i f the imag e does not exist (ca nnot be re ad and is on magneti c) | |
| 227 | * / | |
| 228 | pr ivate Byte BufferBack edImageStr eamRespons e openFile Stream( | |
| 229 | String filename, | |
| 230 | Storag eCredentia ls storage Credential s, | |
| 231 | Storag eProximity imageProx imity) | |
| 232 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, MethodE xception | |
| 233 | { | |
| 234 | lo gger.debug ("StorageC redentials .getUserna me() : " + storageCr edentials. getUsernam e() + " sy stem usern ame: " + S ystem.getP roperty("u ser.name") ); | |
| 235 | ||
| 236 | if ( storageCre dentials.g etUsername ().equalsI gnoreCase( System.get Property(" user.name" ))) | |
| 237 | { | |
| 238 | return openLocal FileStream (filename, storageCr edentials, imageProx imity); | |
| 239 | } | |
| 240 | ||
| 241 | Stri ng storage CredUserna me = null; | |
| 242 | Stri ng[] stora geCredUser = storage Credential s.getUsern ame().spli t("\\\\"); | |
| 243 | if ( storageCre dUser.leng th > 1) | |
| 244 | { | |
| 245 | storag eCredUsern ame = stor ageCredUse r[1]; | |
| 246 | } | |
| 247 | else | |
| 248 | { | |
| 249 | storag eCredUsern ame = stor ageCredUse r[0]; | |
| 250 | } | |
| 251 | ||
| 252 | Stri ng systemU sername = null; | |
| 253 | Stri ng[] syste mUser = Sy stem.getPr operty("us er.name"). split("\\\ \"); | |
| 254 | if ( systemUser .length > 1) | |
| 255 | { | |
| 256 | system Username = systemUse r[1]; | |
| 257 | } | |
| 258 | else | |
| 259 | { | |
| 260 | system Username = systemUse r[0]; | |
| 261 | } | |
| 262 | ||
| 263 | lo gger.debug ("StorageC redUsernam e: " + sto rageCredUs ername + " system us ername: " + systemUs ername); | |
| 264 | ||
| 265 | if ( storageCre dUsername. equalsIgno reCase(sys temUsernam e)) | |
| 266 | { | |
| 267 | return openLocal FileStream (filename, storageCr edentials, imageProx imity); | |
| 268 | } | |
| 269 | else | |
| 270 | { | |
| 271 | return openUncFi leStream(f ilename, s torageCred entials, i mageProxim ity); | |
| 272 | } | |
| 273 | } | |
| 274 | ||
| 275 | ||
| 276 | pr ivate Byte BufferBack edImageStr eamRespons e openLoca lFileStrea m( | |
| 277 | String f ilename, S torageCred entials st orageCrede ntials, St orageProxi mity image Proximity) | |
| 278 | throws ImageNear LineExcept ion, Image NotFoundEx ception, M ethodExcep tion | |
| 279 | { | |
| 280 | lo gger.info( "Opening l ocal image with File path '" + filename + "'."); | |
| 281 | By teBufferBa ckedImageS treamRespo nse respon se = openL ocalFileSt ream(filen ame, image Proximity) ; | |
| 282 | if (response == null) | |
| 283 | { | |
| 284 | retu rn openUnc FileStream (filename, storageCr edentials, imageProx imity); | |
| 285 | } | |
| 286 | el se | |
| 287 | { | |
| 288 | retu rn respons e; | |
| 289 | } | |
| 290 | } | |
| 291 | ||
| 292 | pr ivate Byte BufferBack edImageStr eamRespons e openLoca lFileStrea m( | |
| 293 | String f ilename, S torageProx imity imag eProximity ) | |
| 294 | { | |
| 295 | lo gger.info( "Opening l ocal image with File path '" + filename + "'."); | |
| 296 | By teBufferBa ckedImageS treamRespo nse respon se = null; | |
| 297 | fo r(int near lineRetry= 0; nearlin eRetry < g etNearLine Retries(); ++nearlin eRetry) | |
| 298 | { | |
| 299 | File ima geFile = n ew File(fi lename); | |
| 300 | if(!imag eFile.exis ts()) | |
| 301 | //th row new Im ageNotFoun dException ("Local fi le '" + fi lename + " ' does not exist"); | |
| 302 | retu rn null; | |
| 303 | ||
| 304 | // logge r.info("Im age opened "); | |
| 305 | if( imag eFile.canR ead() ) | |
| 306 | { | |
| 307 | int fileLength = (int)im ageFile.le ngth(); | |
| 308 | if(f ileLength > 0) | |
| 309 | { | |
| 310 | logger.inf o("Local f ile '" + f ilename + "' has fi leLength=" + fileLen gth + ", r eading ima ge into bu ffer."); | |
| 311 | try | |
| 312 | { | |
| 313 | respon se = new B yteBufferB ackedImage StreamResp onse( | |
| 314 | new Byte BufferBack edImageInp utStream(n ew FileInp utStream(i mageFile), | |
| 315 | (int)fileL ength, tru e)); | |
| 316 | } | |
| 317 | catch(IOEx ception io X) | |
| 318 | { | |
| 319 | return null; | |
| 320 | } | |
| 321 | logger.inf o("Local f ile '" + f ilename + "' read in to buffer. "); | |
| 322 | return res ponse; | |
| 323 | } | |
| 324 | else | |
| 325 | { | |
| 326 | return null; | |
| 327 | } | |
| 328 | } | |
| 329 | // if we cannot re ad the fil e and the problem is not that the image is | |
| 330 | // proba bly near-l ine then b ug out | |
| 331 | else if( imageProx imity == n ull || ima geProximit y != Stora geProximit y.NEARLINE ) | |
| 332 | retu rn null; | |
| 333 | } | |
| 334 | ||
| 335 | // if we get to here t hen the al l nearline retries h ave been e xhausted | |
| 336 | re turn null; | |
| 337 | } | |
| 338 | ||
| 339 | pr ivate Byte BufferBack edImageStr eamRespons e openUncF ileStream( | |
| 340 | String filename, | |
| 341 | Storag eCredentia ls storage Credential s, | |
| 342 | Storag eProximity imageProx imity) | |
| 343 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, MethodE xception | |
| 344 | { | |
| 345 | SmbS erverShare smbServer Share = nu ll; | |
| 346 | try | |
| 347 | { | |
| 348 | smbSer verShare = new SmbSe rverShare( filename); | |
| 349 | } | |
| 350 | catc h(Malforme dURLExcept ion murlX) | |
| 351 | { | |
| 352 | String msg = "Ma lformedURL Exception creating s mb server share, " + murlX.get Message(); | |
| 353 | logger .error(msg , murlX); | |
| 354 | throw new Method Exception( murlX); | |
| 355 | } | |
| 356 | List <Integer> connection Ports = ge tSortedCon nectionPor ts(smbServ erShare); | |
| 357 | ||
| 358 | Ntlm PasswordAu thenticati on ntPassA uth = null ; | |
| 359 | ||
| 360 | Iter ator<Integ er> portIt erator = c onnectionP orts.itera tor(); | |
| 361 | whil e(portIter ator.hasNe xt()) | |
| 362 | { | |
| 363 | try | |
| 364 | { | |
| 365 | int conn ectionPort = portIte rator.next (); | |
| 366 | smbServe rShare.set Port(conne ctionPort) ; | |
| 367 | SmbCrede ntials smb Credential s = SmbCre dentials.c reate(smbS erverShare , | |
| 368 | st orageCrede ntials); | |
| 369 | // ntPas sAuth does n't change based on connection port, so only creat e it once | |
| 370 | if(ntPas sAuth == n ull) | |
| 371 | { | |
| 372 | ntPassAuth = | |
| 373 | ne w NtlmPass wordAuthen tication(s mbCredenti als.getDom ain(), smb Credential s.getUsern ame(), | |
| 374 | smbCre dentials.g etPassword ()); | |
| 375 | } | |
| 376 | ByteBuff erBackedIm ageStreamR esponse re sponse = | |
| 377 | openFileSt ream(smbCr edentials, ntPassAut h, imagePr oximity); | |
| 378 | updateSu ccessfulPo rt(smbServ erShare); | |
| 379 | return r esponse; | |
| 380 | } | |
| 381 | catch( SmbExcepti on smbX) | |
| 382 | { | |
| 383 | // if th e exceptio n is a Con nection Ti meout, the root caus e will be a Transpor tException | |
| 384 | logger.e rror(smbX) ; | |
| 385 | boolean includesRo otCause = false; | |
| 386 | String m sg = smbX. getMessage (); | |
| 387 | if((msg == null) | | (msg.len gth() <= 0 )) | |
| 388 | { | |
| 389 | if(smbX.ge tRootCause () != null ) | |
| 390 | { | |
| 391 | ms g = smbX.g etRootCaus e().getMes sage(); | |
| 392 | in cludesRoot Cause = tr ue; | |
| 393 | } | |
| 394 | } | |
| 395 | boolean throwExcep tion = tru e; | |
| 396 | if((smbX .getRootCa use() != n ull) && (s mbX.getRoo tCause() i nstanceof TransportE xception)) | |
| 397 | { | |
| 398 | logger.war n("SmbExce ption root Cause is T ransportEx ception, w ill attemp t to use n ext port t o connect. Error='" + smbX.get RootCause( ).getMessa ge() + "'. "); | |
| 399 | // if it i s a transp ort except ion then i t could be a connect ion timeou t exceptio n which | |
| 400 | // indicat es the VIX is not co nnecting o n the righ t port, wa nt to try the next a vailable p ort | |
| 401 | if(portIte rator.hasN ext()) | |
| 402 | { | |
| 403 | ||
| 404 | // if there is another port to t ry, don't throw the exception just yet | |
| 405 | th rowExcepti on = false ; | |
| 406 | } | |
| 407 | else | |
| 408 | { | |
| 409 | lo gger.warn( "No more a vailable p orts to co nnect to s hare with, will thro w exceptio n"); | |
| 410 | } | |
| 411 | } | |
| 412 | else if( (!includes RootCause) && (smbX. getRootCau se() != nu ll) && (sm bX.getRoot Cause() in stanceof U nknownHost Exception) ) | |
| 413 | { | |
| 414 | // if JCIF S has an U nknownHost Exception, it is cau ght here | |
| 415 | // just wa nt to make sure unkn ownhost ge ts into th e exceptio n message | |
| 416 | msg += ", " + smbX.g etRootCaus e().toStri ng(); | |
| 417 | } | |
| 418 | ||
| 419 | if(throw Exception) | |
| 420 | { | |
| 421 | throw new ImageNotFo undExcepti on("SMBExc eption ope ning SMB f ile '" + f ilename + "', NT sta tus [" + s mbX.getNtS tatus() + "], " + ms g, smbX); | |
| 422 | } | |
| 423 | } | |
| 424 | catch( UnknownHos tException uhX) | |
| 425 | { | |
| 426 | // this doesn't ev er seem to be trigge red, caugh t as SmbEx ception | |
| 427 | logger.e rror(uhX); | |
| 428 | //throw new ImageN otFoundExc eption("Un knownHostE xception o pening SMB file '" + filename + "', " + uhX.getMes sage(), uh X); | |
| 429 | // if th ere is an UnknownHos tException , throw th is as a Me thodExcept ion since the VIX ca nnot resol ve the hos t name - t his is a p roblem whi ch should be correct ed! | |
| 430 | throw ne w MethodEx ception("U nknownHost Exception opening SM B file '" + filename + "', " + uhX.getMe ssage(), u hX); | |
| 431 | } | |
| 432 | catch( IOExceptio n ioX) | |
| 433 | { | |
| 434 | logger.e rror(ioX); | |
| 435 | throw ne w ImageNot FoundExcep tion("IOEx ception op ening SMB file '" + filename + "', " + i oX.getMess age(), ioX ); | |
| 436 | } | |
| 437 | } | |
| 438 | // i f we've go tten here then we've run out o f possible ports to try to con nect to im age shares on | |
| 439 | ||
| 440 | ||
| 441 | retu rn null; | |
| 442 | } | |
| 443 | ||
| 444 | /* * | |
| 445 | * This meth od reads i n SMB file data to a byte buff er and ret urns an | |
| 446 | * InputStre am over th e in memor y byte arr ay. | |
| 447 | * @param in Stream SMB input str eam to be read in me mory | |
| 448 | * @param st reamLength in bytes | |
| 449 | * @return I nputStream fetchable inputstre am of in m emory byte aray | |
| 450 | * @throws I mageNotFou ndExceptio n | |
| 451 | * / | |
| 452 | /* | |
| 453 | pr ivate Inpu tStream op enSmbFileI nStream(In putStream inStream, int stream Length) | |
| 454 | th rows Image NotFoundEx ception | |
| 455 | { | |
| 456 | // J MW 3/15/20 10 | |
| 457 | // F or patch 8 3, the str eaming doe s NOT work properly because we don't pro perly clos e the inpu t | |
| 458 | // s tream in a ll cases. Under hea vy load th is caused 0xC0000001 exception s from JCI FS | |
| 459 | // t his should be fixed for a futu re version of the VI X, for now the confi guration f ile proper ty | |
| 460 | // i s ignored and will a lways read the image into the buffer. | |
| 461 | ||
| 462 | ||
| 463 | // i f not read ing full i mage into buffer, th en open Bu fferedInpu tStream to file | |
| 464 | //if (!getVista StorageCon figuration ().isReadF ileIntoBuf fer()) | |
| 465 | //{ | |
| 466 | // return new Buffe redInputSt ream(inStr eam, defau ltBufferSi ze); | |
| 467 | //} | |
| 468 | ||
| 469 | Byte ArrayInput Stream bin Stream = n ull; | |
| 470 | int len = 0; | |
| 471 | int bytesRead = 0; | |
| 472 | int iterationC ount = 0; | |
| 473 | try | |
| 474 | { | |
| 475 | ByteAr rayOutputS tream outp utStream = new ByteA rrayOutput Stream(str eamLength) ; | |
| 476 | byte[] buffer = new byte[1 6 * 1024]; | |
| 477 | long s tartTime = System.cu rrentTimeM illis(); | |
| 478 | whil e ((len = inStream.r ead(buffer )) > 0) | |
| 479 | { | |
| 480 | iterat ionCount++ ; | |
| 481 | bytesR ead += len ; | |
| 482 | output Stream.wri te(buffer, 0, len); | |
| 483 | } | |
| 484 | long endTime = System.cu rrentTimeM illis(); | |
| 485 | binS tream = ne w ByteArra yInputStre am(outputS tream.toBy teArray()) ; | |
| 486 | logg er.info("L oaded file into memo ry with '" + iterati onCount + "' iterati ons in '" + (endTime - startTi me) + "' m s."); | |
| 487 | outp utStream = null; | |
| 488 | if(b ytesRead < streamLen gth) | |
| 489 | { | |
| 490 | String msg = "On ly read '" + bytesRe ad + "' of expected '" + strea mLength + "', could mean did n ot read fu ll stream! "; | |
| 491 | logger .error(msg ); | |
| 492 | throw new ImageN otFoundExc eption(msg ); | |
| 493 | } | |
| 494 | } | |
| 495 | catc h (IOExcep tion exc) { | |
| 496 | throw new ImageN otFoundExc eption("IO Exception during SMB buffered data read = " | |
| 497 | + exc); | |
| 498 | } | |
| 499 | fina lly { | |
| 500 | try { | |
| 501 | if (inSt ream != nu ll) | |
| 502 | inStream.c lose(); | |
| 503 | } | |
| 504 | catch (IOExcepti on exc) { | |
| 505 | } | |
| 506 | } | |
| 507 | retu rn (binStr eam); | |
| 508 | }* / | |
| 509 | ||
| 510 | /* (non-Java doc) | |
| 511 | * @see gov. va.med.ima ging.excha nge.storag e.Abstract ImageStora geFacade#o penImageSt reamIntern al(java.la ng.String, gov.va.me d.imaging. core.inter faces.Stor ageCredent ials, gov. va.med.ima ging.excha nge.enums. StoragePro ximity, go v.va.med.i maging.exc hange.busi ness.Image FormatQual ityList) | |
| 512 | * / | |
| 513 | @O verride | |
| 514 | pr otected By teBufferBa ckedImageS treamRespo nse openIm ageStreamI nternal(St ring image Identifier , | |
| 515 | Stor ageCredent ials image Credential s, | |
| 516 | Stor ageProximi ty imagePr oximity, | |
| 517 | Imag eFormatQua lityList r equestForm atQualityL ist) | |
| 518 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, | |
| 519 | Conn ectionExce ption, Met hodExcepti on | |
| 520 | { | |
| 521 | Byte BufferBack edImageStr eamRespons e response = | |
| 522 | openFi leStream(i mageIdenti fier, imag eCredentia ls, imageP roximity); | |
| 523 | // s et the dat a source r esponse va lue, not n eeded in i mage conve rsion sinc e set by h ttp client | |
| 524 | // p ut in here so not ch anged by T XT file re quest | |
| 525 | if(( response ! = null) && (response .getImageS tream() != null)) | |
| 526 | { | |
| 527 | Transa ctionConte xt context = Transac tionContex tFactory.g et(); | |
| 528 | contex t.setDataS ourceBytes Received(n ew Long(re sponse.get ImageStrea m().getSiz e())); | |
| 529 | } | |
| 530 | retu rn respons e; | |
| 531 | } | |
| 532 | ||
| 533 | /* (non-Java doc) | |
| 534 | * @see gov. va.med.ima ging.excha nge.storag e.Abstract ImageStora geFacade#o penTXTStre amInternal (java.lang .String, g ov.va.med. imaging.co re.interfa ces.Storag eCredentia ls, gov.va .med.imagi ng.exchang e.enums.St orageProxi mity) | |
| 535 | * / | |
| 536 | @O verride | |
| 537 | pr otected By teBufferBa ckedInputS tream open TXTStreamI nternal(St ring image Identifier , | |
| 538 | Stor ageCredent ials image Credential s, Storage Proximity imageProxi mity) | |
| 539 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, | |
| 540 | Conn ectionExce ption, Met hodExcepti on | |
| 541 | { | |
| 542 | Stri ng txtFile name = cha ngeFileExt ension(ima geIdentifi er, "txt") ; | |
| 543 | Byte BufferBack edImageStr eamRespons e response = | |
| 544 | openFi leStream(t xtFilename , imageCre dentials, imageProxi mity); | |
| 545 | if(r esponse != null) | |
| 546 | return response. getImageSt ream(); | |
| 547 | retu rn null; | |
| 548 | } | |
| 549 | ||
| 550 | /* (non-Java doc) | |
| 551 | * @see gov. va.med.ima ging.core. interfaces .ImageStor ageFacade# openPhotoI d(java.lan g.String, gov.va.med .imaging.c ore.interf aces.Stora geCredenti als) | |
| 552 | * / | |
| 553 | @O verride | |
| 554 | pu blic ByteB ufferBacke dInputStre am openPho toId(Strin g imageIde ntifier, | |
| 555 | Storag eCredentia ls imageCr edentials) | |
| 556 | th rows Image NotFoundEx ception, C onnectionE xception, MethodExce ption | |
| 557 | { | |
| 558 | try | |
| 559 | { | |
| 560 | ByteBu fferBacked ImageStrea mResponse response = openFileS tream(imag eIdentifie r, | |
| 561 | imageCrede ntials, St orageProxi mity.ONLIN E); | |
| 562 | if(res ponse != n ull) | |
| 563 | { | |
| 564 | return r esponse.ge tImageStre am(); | |
| 565 | } | |
| 566 | throw new Connec tionExcept ion("Image stream re sponse is null"); | |
| 567 | } | |
| 568 | catc h(ImageNea rLineExcep tion inlX) | |
| 569 | { | |
| 570 | logger .error("Ne arline exc eption get ting photo id", inlX ); | |
| 571 | throw new ImageN otFoundExc eption(inl X); | |
| 572 | } | |
| 573 | } | |
| 574 | ||
| 575 | pu blic DataS ourceImage InputStrea m openFile InputStrea m(String u ncFilePath , | |
| 576 | Storag eCredentia ls imageCr edentials) | |
| 577 | th rows Image NotFoundEx ception, C onnectionE xception, MethodExce ption | |
| 578 | { | |
| 579 | try | |
| 580 | { | |
| 581 | ImageS treamRespo nse respon se = openF ileStream( uncFilePat h, | |
| 582 | imageCrede ntials, St orageProxi mity.ONLIN E); | |
| 583 | if(res ponse != n ull) | |
| 584 | { | |
| 585 | return r esponse.ge tImageStre am(); | |
| 586 | } | |
| 587 | throw new Connec tionExcept ion("Image stream re sponse is null"); | |
| 588 | } | |
| 589 | catc h(ImageNea rLineExcep tion inlX) | |
| 590 | { | |
| 591 | logger .error("Ne arline exc eption get ting photo id", inlX ); | |
| 592 | throw new ImageN otFoundExc eption(inl X); | |
| 593 | } | |
| 594 | } | |
| 595 | ||
| 596 | pr ivate Vist aStorageCo nfiguratio n getVista StorageCon figuration () | |
| 597 | { | |
| 598 | retu rn VistaSt orageConfi guration.g etVistaSto rageConfig uration(); | |
| 599 | } | |
| 600 | ||
| 601 | pu blic Outpu tStream op enOutputSt ream(Strin g filename , StorageC redentials storageCr edentials) | |
| 602 | th rows IOEx ception | |
| 603 | { | |
| 604 | logg er.info("O pening out put stream to file [ " + filena me + "]"); | |
| 605 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
| 606 | file .createNew File(); | |
| 607 | retu rn file.ge tOutputStr eam(); | |
| 608 | ||
| 609 | } | |
| 610 | ||
| 611 | pu blic void deleteFile (String fi lename, St orageCrede ntials sto rageCreden tials) | |
| 612 | th rows IOEx ception | |
| 613 | { | |
| 614 | logg er.info("D eleting fi le [" + fi lename + " ]"); | |
| 615 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
| 616 | file .delete(); | |
| 617 | } | |
| 618 | ||
| 619 | pu blic void copyFile(S tring sour cePath, St ring desti nationPath , StorageC redentials storageCr edentials) | |
| 620 | th rows IOEx ception | |
| 621 | { | |
| 622 | logg er.info("C opying fil e [" + sou rcePath + "] to file [" + dest inationPat h+ "]"); | |
| 623 | SmbF ile source File = get SmbFile(so urcePath, storageCre dentials); | |
| 624 | SmbF ile destin ationFile = getSmbFi le(destina tionPath, storageCre dentials); | |
| 625 | sour ceFile.cop yTo(destin ationFile) ; | |
| 626 | } | |
| 627 | ||
| 628 | pu blic void copyRemote FileToLoca lFile(Stri ng remoteP ath, Strin g localPat h, Storage Credential s storageC redentials ) | |
| 629 | th rows IOEx ception | |
| 630 | { | |
| 631 | logg er.info("C opying fil e [" + rem otePath + "] to file [" + loca lPath+ "]" ); | |
| 632 | SmbF ile remote File = get SmbFile(re motePath, storageCre dentials); | |
| 633 | SmbF ileInputSt ream in = new SmbFil eInputStre am(remoteF ile); | |
| 634 | ||
| 635 | ||
| 636 | File localFile = new Fil e(localPat h); | |
| 637 | if(! localFile. exists()) { | |
| 638 | localF ile.getPar entFile(). mkdirs(); | |
| 639 | localF ile.create NewFile(); | |
| 640 | } | |
| 641 | File OutputStre am out = n ew FileOut putStream( localFile, false); | |
| 642 | ||
| 643 | byte [] buffer = new byte [16904]; | |
| 644 | int read = 0; | |
| 645 | whil e ((read = in.read(b uffer)) > 0) | |
| 646 | out.write( buffer, 0, read); | |
| 647 | ||
| 648 | in.c lose(); | |
| 649 | out. close(); | |
| 650 | } | |
| 651 | ||
| 652 | pu blic void renameFile (String fi lename, St ring newFi lename, St orageCrede ntials sto rageCreden tials) | |
| 653 | th rows IOEx ception | |
| 654 | { | |
| 655 | logg er.info("r enaming fi le [" + fi lename + " ]"); | |
| 656 | SmbF ile oldFil e = getSmb File(filen ame, stora geCredenti als); | |
| 657 | SmbF ile newFil e = getSmb File(newFi lename, st orageCrede ntials); | |
| 658 | oldF ile.rename To(newFile ); | |
| 659 | } | |
| 660 | ||
| 661 | pu blic boole an fileExi sts(String filename, StorageCr edentials storageCre dentials) | |
| 662 | th rows IOEx ception | |
| 663 | { | |
| 664 | logg er.info("C hecking to see if fi le exists [" + filen ame + "]") ; | |
| 665 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
| 666 | retu rn file.ex ists(); | |
| 667 | } | |
| 668 | ||
| 669 | pu blic Strin g readFile AsString ( String fil ename, Sto rageCreden tials stor ageCredent ials) | |
| 670 | th rows IOEx ception | |
| 671 | { | |
| 672 | logg er.info("R eading fil e [" + fil ename + "] as string "); | |
| 673 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
| 674 | ||
| 675 | StringBu ilder text = new Str ingBuilder (); | |
| 676 | String N L = System .getProper ty("line.s eparator") ; | |
| 677 | Scanner scanner = new Scanne r(new SmbF ileInputSt ream(file) ); | |
| 678 | try { | |
| 679 | while (scanner.h asNextLine ()){ | |
| 680 | text .append(sc anner.next Line() + N L); | |
| 681 | } | |
| 682 | } | |
| 683 | finally{ | |
| 684 | scanne r.close(); | |
| 685 | } | |
| 686 | ||
| 687 | retu rn text.to String(); | |
| 688 | } | |
| 689 | ||
| 690 | pu blic void writeStrin gToFile(St ring fileC ontents, S tring file name, Stor ageCredent ials stora geCredenti als) | |
| 691 | th rows IOEx ception | |
| 692 | { | |
| 693 | logg er.info("W riting to file [" + filename + "]"); | |
| 694 | ||
| 695 | Writer o ut = new O utputStrea mWriter(op enOutputSt ream(filen ame, stora geCredenti als)); | |
| 696 | try { | |
| 697 | out.wr ite(fileCo ntents); | |
| 698 | } | |
| 699 | finally { | |
| 700 | out.cl ose(); | |
| 701 | } | |
| 702 | ||
| 703 | } | |
| 704 | ||
| 705 | pr ivate SmbF ile getSmb File(Strin g filename , StorageC redentials storageCr edentials) | |
| 706 | th rows Malfo rmedURLExc eption, Sm bException | |
| 707 | { | |
| 708 | SmbC redentials fileCrede ntials = S mbCredenti als.create (new SmbSe rverShare( filename), | |
| 709 | storageC redentials ); | |
| 710 | SmbC redentials directory Credential s = SmbCre dentials.c reate(new SmbServerS hare(this. getDirecto ry(filenam e)), | |
| 711 | storageC redentials ); | |
| 712 | SmbF ile file = null; | |
| 713 | SmbF ile direct ory = null ; | |
| 714 | ||
| 715 | Ntlm PasswordAu thenticati on ntPassA uth = | |
| 716 | new Nt lmPassword Authentica tion(fileC redentials .getDomain (), | |
| 717 | fileCreden tials.getU sername(), | |
| 718 | fileCreden tials.getP assword()) ; | |
| 719 | dire ctory = ne w SmbFile( directoryC redentials .getSmbSer verShare() .getSmbPat h(), ntPas sAuth); | |
| 720 | if ( !directory .exists()) { | |
| 721 | direct ory.mkdirs (); | |
| 722 | } | |
| 723 | file = new Smb File(fileC redentials .getSmbSer verShare() .getSmbPat h(), ntPas sAuth); | |
| 724 | retu rn file; | |
| 725 | } | |
| 726 | ||
| 727 | pr otected St ring getDi rectory(St ring fullF ileSpec){ | |
| 728 | int endIndex = fullFileS pec.lastIn dexOf("\\" ); | |
| 729 | retu rn fullFil eSpec.subs tring(0, e ndIndex); | |
| 730 | } | |
| 731 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.