Produced by Araxis Merge on 10/18/2018 2:02:23 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 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\VistaStorage\main\src\java\gov\va\med\imaging\vista\storage | SmbStorageUtility.java | Thu Oct 11 13:30:10 2018 UTC |
2 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\VistaStorage\main\src\java\gov\va\med\imaging\vista\storage | SmbStorageUtility.java | Wed Oct 17 19:16:32 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 1384 |
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: PI I
|
|
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 jav a.io.File; | |
29 | import jav a.io.FileI nputStream ; | |
30 | import jav a.io.FileO utputStrea m; | |
31 | import jav a.io.IOExc eption; | |
32 | import jav a.io.Outpu tStream; | |
33 | import jav a.io.Outpu tStreamWri ter; | |
34 | import jav a.io.Write r; | |
35 | import jav a.net.Malf ormedURLEx ception; | |
36 | import jav a.net.Unkn ownHostExc eption; | |
37 | import jav a.util.Arr ayList; | |
38 | import jav a.util.Ite rator; | |
39 | import jav a.util.Lis t; | |
40 | import jav a.util.Pro perties; | |
41 | import jav a.util.Sca nner; | |
42 | ||
43 | import org .apache.lo gging.log4 j.LogManag er; | |
44 | import org .apache.lo gging.log4 j.Logger; | |
45 | ||
46 | import gov .va.med.im aging.core .interface s.ImageSto rageFacade ; | |
47 | import gov .va.med.im aging.core .interface s.StorageC redentials ; | |
48 | import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on; | |
49 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageNe arLineExce ption; | |
50 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageNo tFoundExce ption; | |
51 | import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception; | |
52 | import gov .va.med.im aging.exch ange.busin ess.ImageF ormatQuali tyList; | |
53 | import gov .va.med.im aging.exch ange.busin ess.ImageS treamRespo nse; | |
54 | import gov .va.med.im aging.exch ange.enums .StoragePr oximity; | |
55 | import gov .va.med.im aging.exch ange.stora ge.Abstrac tBufferedI mageStorag eFacade; | |
56 | import gov .va.med.im aging.exch ange.stora ge.ByteBuf ferBackedI mageInputS tream; | |
57 | import gov .va.med.im aging.exch ange.stora ge.ByteBuf ferBackedI mageStream Response; | |
58 | import gov .va.med.im aging.exch ange.stora ge.ByteBuf ferBackedI nputStream ; | |
59 | import gov .va.med.im aging.exch ange.stora ge.DataSou rceImageIn putStream; | |
60 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont ext; | |
61 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ; | |
62 | import gov .va.med.im aging.vist a.storage. configurat ion.VistaS torageConf iguration; | |
63 | import jci fs.CIFSCon text; | |
64 | import jci fs.context .Singleton Context; | |
65 | import jci fs.smb.Ntl mPasswordA uthenticat ion; | |
66 | import jci fs.smb.Smb Exception; | |
67 | import jci fs.smb.Smb File; | |
68 | import jci fs.smb.Smb FileInputS tream; | |
69 | import jci fs.util.tr ansport.Tr ansportExc eption; | |
70 | ||
71 | /** | |
72 | * Utility functions to open i mage share s and retr ieve files | |
73 | * | |
74 | * @author PI I
|
|
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 | pr ivate int getNearLin eRetries() | |
91 | { | |
92 | return m axNearLine Retries; | |
93 | } | |
94 | ||
95 | pu blic long getNearLin eRetryDela y() | |
96 | { | |
97 | re turn nearL ineRetryDe lay; | |
98 | } | |
99 | ||
100 | st atic | |
101 | { | |
102 | Prop erties pro ps = new P roperties( ); | |
103 | prop s.put("jci fs.netbios .cachePoli cy", "3600 "); | |
104 | prop s.put("jci fs.smb.cli ent.soTime out", "350 00"); | |
105 | prop s.put("jci fs.smb.cli ent.respon seTimeout" , "35000") ; | |
106 | ||
107 | logg er.info("J CIFS Confi guration - jcifs.net bios.cache Policy = " + jcifs.C onfig.getI nt(props, "jcifs.net bios.cache Policy") ) ; | |
108 | logg er.info("J CIFS Confi guration - jcifs.smb .client.so Timeout = " + jcifs. Config.get Int(props, "jcifs.sm b.client.s oTimeout") ); | |
109 | logg er.info("J CIFS Confi guration - jcifs.smb .client.re sponseTime out = " + jcifs.Conf ig.getInt( props, "jc ifs.smb.cl ient.respo nseTimeout ") ); | |
110 | } | |
111 | ||
112 | // st atic { | |
113 | // Prop erties pro ps = new P roperties( ); | |
114 | // 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) | |
115 | // // J MW 1/3/200 8 | |
116 | // // 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. | |
117 | // // 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 | |
118 | // prop s.put("jci fs.smb.cli ent.soTime out", "350 00"); | |
119 | // prop s.put("jci fs.smb.cli ent.respon seTimeout" , "35000") ; | |
120 | // jcif s.Config.s etProperti es(props); | |
121 | // } | |
122 | ||
123 | /* * | |
124 | * Change th e extensio n of a fil e | |
125 | * @param fi lename The filename to change | |
126 | * @param ne wExtension The new e xtension f or the fil ename (do not includ e the '.') | |
127 | * @return | |
128 | * / | |
129 | pr ivate Stri ng changeF ileExtensi on(String filename, String new Extension) { | |
130 | Stri ng fname = filename; | |
131 | int loc = file name.lastI ndexOf("." ); | |
132 | if(l oc >= 0) { | |
133 | fname = filename .substring (0, loc); | |
134 | fname += "." + n ewExtensio n; | |
135 | } | |
136 | retu rn fname; | |
137 | } | |
138 | ||
139 | pu blic Strin g getFileE xtension(S tring file name) | |
140 | { | |
141 | int loc = file name.lastI ndexOf("." ); | |
142 | if(l oc >= 0) | |
143 | { | |
144 | return filename. substring( loc + 1); | |
145 | } | |
146 | retu rn filenam e; | |
147 | } | |
148 | ||
149 | ||
150 | pr ivate Byte BufferBack edImageStr eamRespons e openFile Stream(Smb Credential s smbCrede ntials, | |
151 | NtlmPa sswordAuth entication ntPassAut h, Storage Proximity imageProxi mity) | |
152 | th rows Image NotFoundEx ception, I mageNearLi neExceptio n, SmbExce ption, IOE xception | |
153 | { | |
154 | SmbS erverShare smbServer Share = sm bCredentia ls.getSmbS erverShare (); | |
155 | logg er.info("O pening ima ge with UR L '" + smb ServerShar e.getSmbPa th() + "'. "); | |
156 | Byte BufferBack edImageStr eamRespons e response = null; | |
157 | CIFS Context co ntext = nu ll; | |
158 | for( int nearli neRetry=0; nearlineR etry < get NearLineRe tries(); + +nearlineR etry) | |
159 | { | |
160 | if(con text == nu ll){ | |
161 | //contex t = Single tonContext .getInstan ce(); | |
162 | context = Singleto nContext.g etInstance ().withCre dentials(n tPassAuth) ; | |
163 | } | |
164 | logger .debug("Cr edentials stored in CIFS Conte xt: " + co ntext.getC redentials ().toStrin g()); | |
165 | SmbFil e imageFil e = new Sm bFile(smbS erverShare .getSmbPat h(), conte xt); | |
166 | // log ger.info(" Image open ed"); | |
167 | if( im ageFile.ca nRead() ) | |
168 | { | |
169 | int file Length = ( int)imageF ile.length (); | |
170 | if(fileL ength > 0) | |
171 | { | |
172 | logger.inf o("File '" + smbServ erShare.ge tSmbPath() + "' has fileLength =" + fileL ength + ", reading i mage into buffer."); | |
173 | response = new ByteB ufferBacke dImageStre amResponse ( | |
174 | new ByteBuffer BackedImag eInputStre am(imageFi le.getInpu tStream(), | |
175 | (int)ima geFile.len gth(), tru e)); | |
176 | logger.inf o("File '" + smbServ erShare.ge tSmbPath() + "' read into buff er."); | |
177 | imageFile. close(); | |
178 | return res ponse; | |
179 | } | |
180 | else | |
181 | { | |
182 | imageFile. close(); | |
183 | // was thr owing File NotFoundEx ception (e xtends IOE xception) - changed to ImageNo tFoundExce ption and improved e rror messa ge | |
184 | 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"); | |
185 | } | |
186 | } | |
187 | // if we cannot read the f ile and th e problem is not tha t the imag e is | |
188 | // pro bably near -line then bug out | |
189 | else i f( imagePr oximity == null || i mageProxim ity != Sto rageProxim ity.NEARLI NE ) | |
190 | imageFil e.close(); | |
191 | 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."); | |
192 | } | |
193 | // i f we get t o here the n the all nearline r etries hav e been exh austed | |
194 | // t hrow a nea r-line exc eption | |
195 | thro w new Imag eNearLineE xception(" Cannot rea d Near-Lin e image fi le '" + sm bServerSha re.getSmbP ath() + "' yet, retr y later.") ; | |
196 | } | |
197 | ||
198 | pr ivate List <Integer> getSortedC onnectionP orts(SmbSe rverShare smbServerS hare) | |
199 | { | |
200 | List <Integer> connection Ports = ne w ArrayLis t<Integer> (); | |
201 | SmbC onnectionI nformation Manager sm bConnectio nInformati onManager = getSmbCo nnectionIn formationM anager(); | |
202 | int firstTryPo rt = | |
203 | smbCon nectionInf ormationMa nager.getS uccessfulP ort(smbSer verShare.g etServer() , | |
204 | SmbServerS hare.defau ltServerSh arePort); | |
205 | conn ectionPort s.add(firs tTryPort); | |
206 | ||
207 | for( int port : SmbServer Share.poss ibleConnec tionPorts) | |
208 | { | |
209 | // don 't add the initial p ort again | |
210 | if(por t != first TryPort) | |
211 | connecti onPorts.ad d(port); | |
212 | } | |
213 | retu rn connect ionPorts; | |
214 | } | |
215 | ||
216 | pr ivate SmbC onnectionI nformation Manager ge tSmbConnec tionInform ationManag er() | |
217 | { | |
218 | retu rn SmbConn ectionInfo rmationMan ager.getSm bConnectio nInformati onManager( ); | |
219 | } | |
220 | ||
221 | pr ivate void updateSuc cessfulPor t(SmbServe rShare smb ServerShar e) | |
222 | { | |
223 | if(s mbServerSh are != nul l) | |
224 | { | |
225 | SmbCon nectionInf ormationMa nager smbC onnectionI nformation Manager = | |
226 | getSmbCo nnectionIn formationM anager(); | |
227 | smbCon nectionInf ormationMa nager.upda teSuccessf ulPort(smb ServerShar e.getServe r(), | |
228 | smbServerS hare.getPo rt()); | |
229 | } | |
230 | } | |
231 | ||
232 | /* * | |
233 | * Open the input stre am for the file and create a S izedInputS tream that contains the filesi ze | |
234 | * @param fi lename The filename to open (f ull UNC pa th) | |
235 | * @param st orageCrede ntials The network l ocation th at stores the file ( with crede ntials set ) | |
236 | * @param im ageProximi ty The cur rent locat ion of the image (ma gnetic, wo rm, offlin e) | |
237 | * @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 | |
238 | * @throws I mageNearLi neExceptio n Occurs i f the imag e is on a jukebox an d is not r eadable | |
239 | * @throws I mageNotFou ndExceptio n Occurs i f the imag e does not exist (ca nnot be re ad and is on magneti c) | |
240 | * / | |
241 | pr ivate Byte BufferBack edImageStr eamRespons e openFile Stream( | |
242 | String filename, | |
243 | Storag eCredentia ls storage Credential s, | |
244 | Storag eProximity imageProx imity) | |
245 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, MethodE xception | |
246 | { | |
247 | lo gger.debug ("StorageC redentials Username( ) : " + st orageCrede ntials.get Username() + " Sys tem userna me: " + Sy stem.getPr operty("us er.name")) ; | |
248 | ||
249 | if ( storageCre dentials.g etUsername ().equalsI gnoreCase( System.get Property(" user.name" ))) | |
250 | { | |
251 | return openLocal FileStream (filename, storageCr edentials, imageProx imity); | |
252 | } | |
253 | ||
254 | Stri ng storage CredUserna me = null; | |
255 | Stri ng[] stora geCredUser = storage Credential s.getUsern ame().spli t("\\\\"); | |
256 | if ( storageCre dUser.leng th > 1) | |
257 | { | |
258 | storag eCredUsern ame = stor ageCredUse r[1]; | |
259 | } | |
260 | else | |
261 | { | |
262 | storag eCredUsern ame = stor ageCredUse r[0]; | |
263 | } | |
264 | ||
265 | Stri ng systemU sername = null; | |
266 | Stri ng[] syste mUser = Sy stem.getPr operty("us er.name"). split("\\\ \"); | |
267 | if ( systemUser .length > 1) | |
268 | { | |
269 | system Username = systemUse r[1]; | |
270 | } | |
271 | else | |
272 | { | |
273 | system Username = systemUse r[0]; | |
274 | } | |
275 | ||
276 | lo gger.debug ("StorageC redUsernam e: " + sto rageCredUs ername + " System username: " + system Username); | |
277 | ||
278 | if ( storageCre dUsername. equalsIgno reCase(sys temUsernam e)) | |
279 | { | |
280 | return openLocal FileStream (filename, storageCr edentials, imageProx imity); | |
281 | } | |
282 | else | |
283 | { | |
284 | return openUncFi leStream(f ilename, s torageCred entials, i mageProxim ity); | |
285 | } | |
286 | } | |
287 | ||
288 | ||
289 | pr ivate Byte BufferBack edImageStr eamRespons e openLoca lFileStrea m( | |
290 | String f ilename, S torageCred entials st orageCrede ntials, St orageProxi mity image Proximity) | |
291 | throws ImageNear LineExcept ion, Image NotFoundEx ception, M ethodExcep tion | |
292 | { | |
293 | lo gger.info( "Opening l ocal image with File path '" + filename + "'."); | |
294 | By teBufferBa ckedImageS treamRespo nse respon se = openL ocalFileSt ream(filen ame, image Proximity) ; | |
295 | if (response == null) | |
296 | { | |
297 | retu rn openUnc FileStream (filename, storageCr edentials, imageProx imity); | |
298 | } | |
299 | el se | |
300 | { | |
301 | retu rn respons e; | |
302 | } | |
303 | } | |
304 | ||
305 | pr ivate Byte BufferBack edImageStr eamRespons e openLoca lFileStrea m( | |
306 | String f ilename, S torageProx imity imag eProximity ) | |
307 | { | |
308 | lo gger.info( "Opening l ocal image with File path '" + filename + "'."); | |
309 | By teBufferBa ckedImageS treamRespo nse respon se = null; | |
310 | fo r(int near lineRetry= 0; nearlin eRetry < g etNearLine Retries(); ++nearlin eRetry) | |
311 | { | |
312 | File ima geFile = n ew File(fi lename); | |
313 | if(!imag eFile.exis ts()) | |
314 | //th row new Im ageNotFoun dException ("Local fi le '" + fi lename + " ' does not exist"); | |
315 | retu rn null; | |
316 | ||
317 | // logge r.info("Im age opened "); | |
318 | if( imag eFile.canR ead() ) | |
319 | { | |
320 | int fileLength = (int)im ageFile.le ngth(); | |
321 | if(f ileLength > 0) | |
322 | { | |
323 | logger.inf o("Local f ile '" + f ilename + "' has fi leLength=" + fileLen gth + ", r eading ima ge into bu ffer."); | |
324 | try | |
325 | { | |
326 | respon se = new B yteBufferB ackedImage StreamResp onse( | |
327 | new Byte BufferBack edImageInp utStream(n ew FileInp utStream(i mageFile), | |
328 | (int)fileL ength, tru e)); | |
329 | } | |
330 | catch(IOEx ception io X) | |
331 | { | |
332 | return null; | |
333 | } | |
334 | logger.inf o("Local f ile '" + f ilename + "' read in to buffer. "); | |
335 | return res ponse; | |
336 | } | |
337 | else | |
338 | { | |
339 | return null; | |
340 | } | |
341 | } | |
342 | // if we cannot re ad the fil e and the problem is not that the image is | |
343 | // proba bly near-l ine then b ug out | |
344 | else if( imageProx imity == n ull || ima geProximit y != Stora geProximit y.NEARLINE ) | |
345 | retu rn null; | |
346 | } | |
347 | ||
348 | // if we get to here t hen the al l nearline retries h ave been e xhausted | |
349 | re turn null; | |
350 | } | |
351 | ||
352 | pr ivate Byte BufferBack edImageStr eamRespons e openUncF ileStream( | |
353 | String filename, | |
354 | Storag eCredentia ls storage Credential s, | |
355 | Storag eProximity imageProx imity) | |
356 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, MethodE xception | |
357 | { | |
358 | SmbS erverShare smbServer Share = nu ll; | |
359 | try | |
360 | { | |
361 | smbSer verShare = new SmbSe rverShare( filename); | |
362 | } | |
363 | catc h(Malforme dURLExcept ion murlX) | |
364 | { | |
365 | String msg = "Ma lformedURL Exception creating s mb server share, " + murlX.get Message(); | |
366 | logger .error(msg , murlX); | |
367 | throw new Method Exception( murlX); | |
368 | } | |
369 | List <Integer> connection Ports = ge tSortedCon nectionPor ts(smbServ erShare); | |
370 | ||
371 | Ntlm PasswordAu thenticati on ntPassA uth = null ; | |
372 | CIFS Context co ntext = nu ll; | |
373 | Iter ator<Integ er> portIt erator = c onnectionP orts.itera tor(); | |
374 | whil e(portIter ator.hasNe xt()) | |
375 | { | |
376 | try | |
377 | { | |
378 | int conn ectionPort = portIte rator.next (); | |
379 | smbServe rShare.set Port(conne ctionPort) ; | |
380 | logger.d ebug("Tryi ng this po ssible Con nectionPor t: " + con nectionPor t + | |
381 | " smbServerS hare: " + smbServerS hare.toStr ing()); | |
382 | if(conte xt == null ){ | |
383 | context = SingletonC ontext.get Instance() ; | |
384 | } | |
385 | SmbCrede ntials smb Credential s = SmbCre dentials.c reate(smbS erverShare , | |
386 | st orageCrede ntials); | |
387 | // ntPas sAuth does n't change based on connection port, so only creat e it once | |
388 | if(ntPas sAuth == n ull) | |
389 | { | |
390 | logger.deb ug("SmbCre dential Do main: " + smbCredent ials.getDo main() + | |
391 | " username: " + smbCre dentials.g etUsername () + | |
392 | " password: <protected >"); | |
393 | ntPassAuth = | |
394 | ne w NtlmPass wordAuthen tication(c ontext, sm bCredentia ls.getDoma in(), smbC redentials .getUserna me(), | |
395 | smbCre dentials.g etPassword ()); | |
396 | } | |
397 | context. withCreden tials(ntPa ssAuth); | |
398 | ByteBuff erBackedIm ageStreamR esponse re sponse = | |
399 | openFileSt ream(smbCr edentials, ntPassAut h, imagePr oximity); | |
400 | updateSu ccessfulPo rt(smbServ erShare); | |
401 | return r esponse; | |
402 | } | |
403 | catch( SmbExcepti on smbX) | |
404 | { | |
405 | // if th e exceptio n is a Con nection Ti meout, the root caus e will be a Transpor tException | |
406 | logger.e rror(smbX) ; | |
407 | boolean includesRo otCause = false; | |
408 | String m sg = smbX. getMessage (); | |
409 | if((msg == null) | | (msg.len gth() <= 0 )) | |
410 | { | |
411 | if(smbX.ge tRootCause () != null ) | |
412 | { | |
413 | ms g = smbX.g etRootCaus e().getMes sage(); | |
414 | in cludesRoot Cause = tr ue; | |
415 | } | |
416 | } | |
417 | boolean throwExcep tion = tru e; | |
418 | if((smbX .getRootCa use() != n ull) && (s mbX.getRoo tCause() i nstanceof TransportE xception)) | |
419 | { | |
420 | 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() + "'. "); | |
421 | // if it i s a transp ort except ion then i t could be a connect ion timeou t exceptio n which | |
422 | // indicat es the VIX is not co nnecting o n the righ t port, wa nt to try the next a vailable p ort | |
423 | if(portIte rator.hasN ext()) | |
424 | { | |
425 | ||
426 | // if there is another port to t ry, don't throw the exception just yet | |
427 | th rowExcepti on = false ; | |
428 | } | |
429 | else | |
430 | { | |
431 | lo gger.warn( "No more a vailable p orts to co nnect to s hare with, will thro w exceptio n"); | |
432 | } | |
433 | } | |
434 | else if( (!includes RootCause) && (smbX. getRootCau se() != nu ll) && (sm bX.getRoot Cause() in stanceof U nknownHost Exception) ) | |
435 | { | |
436 | // if JCIF S has an U nknownHost Exception, it is cau ght here | |
437 | // just wa nt to make sure unkn ownhost ge ts into th e exceptio n message | |
438 | msg += ", " + smbX.g etRootCaus e().toStri ng(); | |
439 | } | |
440 | ||
441 | if(throw Exception) | |
442 | { | |
443 | throw new ImageNotFo undExcepti on("SMBExc eption ope ning SMB f ile '" + f ilename + "', NT sta tus [" + s mbX.getNtS tatus() + "], " + ms g, smbX); | |
444 | } | |
445 | } | |
446 | catch( UnknownHos tException uhX) | |
447 | { | |
448 | // this doesn't ev er seem to be trigge red, caugh t as SmbEx ception | |
449 | logger.e rror(uhX); | |
450 | //throw new ImageN otFoundExc eption("Un knownHostE xception o pening SMB file '" + filename + "', " + uhX.getMes sage(), uh X); | |
451 | // 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! | |
452 | throw ne w MethodEx ception("U nknownHost Exception opening SM B file '" + filename + "', " + uhX.getMe ssage(), u hX); | |
453 | } | |
454 | catch( IOExceptio n ioX) | |
455 | { | |
456 | logger.e rror(ioX); | |
457 | throw ne w ImageNot FoundExcep tion("IOEx ception op ening SMB file '" + filename + "', " + i oX.getMess age(), ioX ); | |
458 | } | |
459 | } | |
460 | // 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 | |
461 | ||
462 | ||
463 | retu rn null; | |
464 | } | |
465 | ||
466 | ||
467 | /* (non-Java doc) | |
468 | * @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) | |
469 | * / | |
470 | @O verride | |
471 | pr otected By teBufferBa ckedImageS treamRespo nse openIm ageStreamI nternal(St ring image Identifier , | |
472 | Stor ageCredent ials image Credential s, | |
473 | Stor ageProximi ty imagePr oximity, | |
474 | Imag eFormatQua lityList r equestForm atQualityL ist) | |
475 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, | |
476 | Conn ectionExce ption, Met hodExcepti on | |
477 | { | |
478 | Byte BufferBack edImageStr eamRespons e response = | |
479 | openFi leStream(i mageIdenti fier, imag eCredentia ls, imageP roximity); | |
480 | // 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 | |
481 | // p ut in here so not ch anged by T XT file re quest | |
482 | if(( response ! = null) && (response .getImageS tream() != null)) | |
483 | { | |
484 | Transa ctionConte xt context = Transac tionContex tFactory.g et(); | |
485 | contex t.setDataS ourceBytes Received(n ew Long(re sponse.get ImageStrea m().getSiz e())); | |
486 | } | |
487 | retu rn respons e; | |
488 | } | |
489 | ||
490 | /* (non-Java doc) | |
491 | * @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) | |
492 | * / | |
493 | @O verride | |
494 | pr otected By teBufferBa ckedInputS tream open TXTStreamI nternal(St ring image Identifier , | |
495 | Stor ageCredent ials image Credential s, Storage Proximity imageProxi mity) | |
496 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, | |
497 | Conn ectionExce ption, Met hodExcepti on | |
498 | { | |
499 | Stri ng txtFile name = cha ngeFileExt ension(ima geIdentifi er, "txt") ; | |
500 | Byte BufferBack edImageStr eamRespons e response = | |
501 | openFi leStream(t xtFilename , imageCre dentials, imageProxi mity); | |
502 | if(r esponse != null) | |
503 | return response. getImageSt ream(); | |
504 | retu rn null; | |
505 | } | |
506 | ||
507 | /* (non-Java doc) | |
508 | * @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) | |
509 | * / | |
510 | @O verride | |
511 | pu blic ByteB ufferBacke dInputStre am openPho toId(Strin g imageIde ntifier, | |
512 | Storag eCredentia ls imageCr edentials) | |
513 | th rows Image NotFoundEx ception, C onnectionE xception, MethodExce ption | |
514 | { | |
515 | try | |
516 | { | |
517 | ByteBu fferBacked ImageStrea mResponse response = openFileS tream(imag eIdentifie r, | |
518 | imageCrede ntials, St orageProxi mity.ONLIN E); | |
519 | if(res ponse != n ull) | |
520 | { | |
521 | return r esponse.ge tImageStre am(); | |
522 | } | |
523 | throw new Connec tionExcept ion("Image stream re sponse is null"); | |
524 | } | |
525 | catc h(ImageNea rLineExcep tion inlX) | |
526 | { | |
527 | logger .error("Ne arline exc eption get ting photo id", inlX ); | |
528 | throw new ImageN otFoundExc eption(inl X); | |
529 | } | |
530 | } | |
531 | ||
532 | pu blic DataS ourceImage InputStrea m openFile InputStrea m(String u ncFilePath , | |
533 | Storag eCredentia ls imageCr edentials) | |
534 | th rows Image NotFoundEx ception, C onnectionE xception, MethodExce ption | |
535 | { | |
536 | try | |
537 | { | |
538 | ImageS treamRespo nse respon se = openF ileStream( uncFilePat h, | |
539 | imageCrede ntials, St orageProxi mity.ONLIN E); | |
540 | if(res ponse != n ull) | |
541 | { | |
542 | return r esponse.ge tImageStre am(); | |
543 | } | |
544 | throw new Connec tionExcept ion("Image stream re sponse is null"); | |
545 | } | |
546 | catc h(ImageNea rLineExcep tion inlX) | |
547 | { | |
548 | logger .error("Ne arline exc eption get ting photo id", inlX ); | |
549 | throw new ImageN otFoundExc eption(inl X); | |
550 | } | |
551 | } | |
552 | ||
553 | pr ivate Vist aStorageCo nfiguratio n getVista StorageCon figuration () | |
554 | { | |
555 | retu rn VistaSt orageConfi guration.g etVistaSto rageConfig uration(); | |
556 | } | |
557 | ||
558 | pu blic Outpu tStream op enOutputSt ream(Strin g filename , StorageC redentials storageCr edentials) | |
559 | th rows IOEx ception | |
560 | { | |
561 | logg er.info("O pening out put stream to file [ " + filena me + "]"); | |
562 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
563 | file .createNew File(); | |
564 | retu rn file.ge tOutputStr eam(); | |
565 | ||
566 | } | |
567 | ||
568 | pu blic void deleteFile (String fi lename, St orageCrede ntials sto rageCreden tials) | |
569 | th rows IOEx ception | |
570 | { | |
571 | logg er.info("D eleting fi le [" + fi lename + " ]"); | |
572 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
573 | file .delete(); | |
574 | } | |
575 | ||
576 | pu blic void copyFile(S tring sour cePath, St ring desti nationPath , StorageC redentials storageCr edentials) | |
577 | th rows IOEx ception | |
578 | { | |
579 | logg er.info("C opying fil e [" + sou rcePath + "] to file [" + dest inationPat h+ "]"); | |
580 | SmbF ile source File = get SmbFile(so urcePath, storageCre dentials); | |
581 | SmbF ile destin ationFile = getSmbFi le(destina tionPath, storageCre dentials); | |
582 | sour ceFile.cop yTo(destin ationFile) ; | |
583 | } | |
584 | ||
585 | pu blic void copyRemote FileToLoca lFile(Stri ng remoteP ath, Strin g localPat h, Storage Credential s storageC redentials ) | |
586 | th rows IOEx ception | |
587 | { | |
588 | logg er.info("C opying fil e [" + rem otePath + "] to file [" + loca lPath+ "]" ); | |
589 | SmbF ile remote File = get SmbFile(re motePath, storageCre dentials); | |
590 | SmbF ileInputSt ream in = new SmbFil eInputStre am(remoteF ile); | |
591 | ||
592 | ||
593 | File localFile = new Fil e(localPat h); | |
594 | if(! localFile. exists()) { | |
595 | localF ile.getPar entFile(). mkdirs(); | |
596 | localF ile.create NewFile(); | |
597 | } | |
598 | File OutputStre am out = n ew FileOut putStream( localFile, false); | |
599 | ||
600 | byte [] buffer = new byte [16904]; | |
601 | int read = 0; | |
602 | whil e ((read = in.read(b uffer)) > 0) | |
603 | out.write( buffer, 0, read); | |
604 | ||
605 | in.c lose(); | |
606 | out. close(); | |
607 | } | |
608 | ||
609 | pu blic void renameFile (String fi lename, St ring newFi lename, St orageCrede ntials sto rageCreden tials) | |
610 | th rows IOEx ception | |
611 | { | |
612 | logg er.info("r enaming fi le [" + fi lename + " ]"); | |
613 | SmbF ile oldFil e = getSmb File(filen ame, stora geCredenti als); | |
614 | SmbF ile newFil e = getSmb File(newFi lename, st orageCrede ntials); | |
615 | oldF ile.rename To(newFile ); | |
616 | } | |
617 | ||
618 | pu blic boole an fileExi sts(String filename, StorageCr edentials storageCre dentials) | |
619 | th rows IOEx ception | |
620 | { | |
621 | logg er.info("C hecking to see if fi le exists [" + filen ame + "]") ; | |
622 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
623 | retu rn file.ex ists(); | |
624 | } | |
625 | ||
626 | pu blic Strin g readFile AsString ( String fil ename, Sto rageCreden tials stor ageCredent ials) | |
627 | th rows IOEx ception | |
628 | { | |
629 | logg er.info("R eading fil e [" + fil ename + "] as string "); | |
630 | SmbF ile file = getSmbFil e(filename , storageC redentials ); | |
631 | ||
632 | StringBu ilder text = new Str ingBuilder (); | |
633 | String N L = System .getProper ty("line.s eparator") ; | |
634 | Scanner scanner = new Scanne r(new SmbF ileInputSt ream(file) ); | |
635 | try { | |
636 | while (scanner.h asNextLine ()){ | |
637 | text .append(sc anner.next Line() + N L); | |
638 | } | |
639 | } | |
640 | finally{ | |
641 | scanne r.close(); | |
642 | } | |
643 | ||
644 | retu rn text.to String(); | |
645 | } | |
646 | ||
647 | pu blic void writeStrin gToFile(St ring fileC ontents, S tring file name, Stor ageCredent ials stora geCredenti als) | |
648 | th rows IOEx ception | |
649 | { | |
650 | logg er.info("W riting to file [" + filename + "]"); | |
651 | ||
652 | Writer o ut = new O utputStrea mWriter(op enOutputSt ream(filen ame, stora geCredenti als)); | |
653 | try { | |
654 | out.wr ite(fileCo ntents); | |
655 | } | |
656 | finally { | |
657 | out.cl ose(); | |
658 | } | |
659 | ||
660 | } | |
661 | ||
662 | pr ivate SmbF ile getSmb File(Strin g filename , StorageC redentials storageCr edentials) | |
663 | th rows Malfo rmedURLExc eption, Sm bException | |
664 | { | |
665 | SmbC redentials fileCrede ntials = S mbCredenti als.create (new SmbSe rverShare( filename), | |
666 | storageC redentials ); | |
667 | SmbC redentials directory Credential s = SmbCre dentials.c reate(new SmbServerS hare(this. getDirecto ry(filenam e)), | |
668 | storageC redentials ); | |
669 | SmbF ile file = null; | |
670 | SmbF ile direct ory = null ; | |
671 | CIFS Context co ntext = nu ll; | |
672 | if(c ontext == null){ | |
673 | contex t = Single tonContext .getInstan ce(); | |
674 | } | |
675 | Ntlm PasswordAu thenticati on ntPassA uth = | |
676 | new Nt lmPassword Authentica tion(conte xt, fileCr edentials. getDomain( ), | |
677 | fileCreden tials.getU sername(), | |
678 | fileCreden tials.getP assword()) ; | |
679 | dire ctory = ne w SmbFile( directoryC redentials .getSmbSer verShare() .getSmbPat h(), conte xt); | |
680 | if ( !directory .exists()) { | |
681 | direct ory.mkdirs (); | |
682 | } | |
683 | file = new Smb File(fileC redentials .getSmbSer verShare() .getSmbPat h(), conte xt); | |
684 | dire ctory.clos e(); | |
685 | retu rn file; | |
686 | } | |
687 | ||
688 | pr otected St ring getDi rectory(St ring fullF ileSpec){ | |
689 | int endIndex = fullFileS pec.lastIn dexOf("\\" ); | |
690 | retu rn fullFil eSpec.subs tring(0, e ndIndex); | |
691 | } | |
692 | ||
693 | ||
694 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.