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