Produced by Araxis Merge on 12/5/2017 12:06:46 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\ImagingVistaRealm\main\src\java\gov\va\med\imaging\tomcat\vistarealm | RpcBroker.java | Mon Dec 4 21:35:10 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingVistaRealm\main\src\java\gov\va\med\imaging\tomcat\vistarealm | RpcBroker.java | Tue Dec 5 13:23:49 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1746 |
| Changed | 1 | 2 |
| 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 | package go v.va.med.i maging.tom cat.vistar ealm; | |
| 2 | ||
| 3 | import gov .va.med.im aging.tomc at.vistare alm.except ions.*; | |
| 4 | ||
| 5 | import jav a.net.Inet Address; | |
| 6 | import jav a.net.Unkn ownHostExc eption; | |
| 7 | import jav a.text.Sim pleDateFor mat; | |
| 8 | import jav a.util.Has hMap; | |
| 9 | import jav a.util.con current.Ar rayBlockin gQueue; | |
| 10 | import jav a.util.con current.Bl ockingQueu e; | |
| 11 | import jav a.util.con current.Th readPoolEx ecutor; | |
| 12 | import jav a.util.con current.Ti meUnit; | |
| 13 | import org .apache.lo gging.log4 j.LogManag er; | |
| 14 | import org .apache.lo gging.log4 j.Logger; | |
| 15 | ||
| 16 | /** | |
| 17 | * @author
|
|
| 18 | * | |
| 19 | * impleme nts Runnab le so that the disco nnect may be done as ynchronous ly. | |
| 20 | * | |
| 21 | */ | |
| 22 | public cla ss RpcBrok er | |
| 23 | implements Runnable | |
| 24 | { | |
| 25 | pr ivate stat ic final i nt MAX_DIS CONNECT_TH READ = 32; | |
| 26 | pr ivate stat ic final i nt DISCONN ECT_THREAD _COUNT = 5 ; | |
| 27 | pr ivate stat ic final i nt DISCONN ECT_QUEUE_ SIZE = 128 ; | |
| 28 | ||
| 29 | pr ivate stat ic Logger logger = L ogManager. getLogger( RpcBroker. class); | |
| 30 | ||
| 31 | pr ivate stat ic Blockin gQueue<Run nable> dis connectQue ue; | |
| 32 | pr ivate stat ic ThreadP oolExecuto r disconne ctExecutor ; | |
| 33 | ||
| 34 | pr ivate fina l static S tring MAG_ WINDOWS_CO NTEXT = "M AG WINDOWS "; | |
| 35 | pr ivate fina l static S tring CPRS _CONTEXT = "OR CPRS GUI CHART" ; | |
| 36 | pr ivate fina l static S tring CAPR I_CONTEXT = "DVBA CA PRI GUI"; | |
| 37 | ||
| 38 | pr ivate fina l static S tring DATA SOURCE_PRO TOCOL = "V ISTA"; | |
| 39 | pr ivate fina l static S tring DATA SOURCE_MOD ALITY = "H IS"; | |
| 40 | ||
| 41 | pr ivate fina l static S tring RPC_ GET_TREATI NG_LIST = "VAFCTFU G ET TREATIN G LIST"; | |
| 42 | pr ivate fina l static S tring RPC_ CONVERT_IC N_TO_DFN = "VAFCTFU CONVERT IC N TO DFN"; | |
| 43 | pr ivate fina l static S tring RPC_ SIGNON = " XUS SIGNON SETUP"; | |
| 44 | pr ivate fina l static S tring RPC_ AV_CODE = "XUS AV CO DE"; | |
| 45 | pr ivate fina l static S tring RPC_ CREATE_CON TEXT = "XW B CREATE C ONTEXT"; | |
| 46 | pr ivate fina l static S tring RPC_ GET_VARIAB LE_VALUE = "XWB GET VARIABLE V ALUE"; | |
| 47 | pr ivate fina l static S tring RPC_ DDR_FILER = "DDR FIL ER"; | |
| 48 | pr ivate fina l static S tring RPC_ GET_USER_I NFO = "ORW U USERINFO "; | |
| 49 | pr ivate fina l static S tring RPC_ DG_SENSITI VE_RECORD_ ACCESS = " DG SENSITI VE RECORD ACCESS"; | |
| 50 | ||
| 51 | pr ivate fina l static S tring RPC_ MAG_LOGOFF = "MAGG L OGOFF"; | |
| 52 | pr ivate fina l static S tring RPC_ MAG_GET_ST UDIES = "M AG4 PAT GE T IMAGES"; | |
| 53 | pr ivate fina l static S tring RPC_ MAG_GET_ST UDY_IMAGES = "MAGG G ROUP IMAGE S"; | |
| 54 | pr ivate fina l static S tring RPC_ MAG_REPORT = "MAGGRP T"; | |
| 55 | pr ivate fina l static S tring RPC_ MAG_GET_NE TLOC = "MA G GET NETL OC"; | |
| 56 | pr ivate fina l static S tring RPC_ MAG_MAGGUS ER2 = "MAG GUSER2"; | |
| 57 | // pr ivate fina l static S tring RPC_ MAG_MAGG_S YS_GLOBAL_ NODE = "MA GG SYS GLO BAL NODE"; | |
| 58 | pr ivate fina l static S tring RPC_ MAG_DOD_GE T_STUDIES_ BY_IEN = " MAG DOD GE T STUDIES IEN"; | |
| 59 | pr ivate fina l static S tring RPC_ MAG_IMAGE_ CURRENT_IN FO = "MAG IMAGE CURR ENT INFO"; | |
| 60 | pr ivate fina l static S tring RPC_ MAG_NEW_SO P_INSTANCE _UID = "MA G NEW SOP INSTANCE U ID"; | |
| 61 | pr ivate fina l static S tring RPC_ MAG_LOGACT ION = "MAG 3 LOGACTIO N"; | |
| 62 | pr ivate fina l static S tring RPC_ MAG_ACTION _LOG = "MA GGACTION L OG"; | |
| 63 | pr ivate fina l static S tring RPC_ MAG_WRKS_U PDATES = " MAGG WRKS UPDATES"; | |
| 64 | ||
| 65 | pr ivate fina l static S tring RPC_ XUS_SET_VI SITOR = "X US SET VIS ITOR"; | |
| 66 | pr ivate fina l static S tring RPC_ MAG_BROKER _SECURITY = "MAG BRO KER SECURI TY"; | |
| 67 | ||
| 68 | pr ivate fina l static S tring MENU _SUBSCRIPT = "200.03 "; | |
| 69 | pr ivate fina l static S tring DELE GATE_SUBSC RIPT = "20 0.19"; | |
| 70 | ||
| 71 | pr ivate fina l static i nt FAILED_ CONNECTION _MAX_COUNT = 3; // n umber of t imes the b roker will try to co nnect befo re giving up on the connection | |
| 72 | pr ivate fina l static i nt FAILED_ CONNECTION _MIN_WAIT_ TIME = 100 ; // maxim um number of ms to w ait betwee n retrying connectio ns | |
| 73 | pr ivate fina l static i nt FAILED_ CONNECTION _MAX_WAIT_ TIME = 100 0; // maxi mum number of ms to wait betwe en retryin g connecti ons | |
| 74 | ||
| 75 | pr ivate fina l static i nt FAILED_ SIGNON_MAX _COUNT = 1 0; // maxim um number of times t o rety an RPC_SIGNON | |
| 76 | pr ivate fina l static i nt FAILED_ SIGNON_MIN _WAIT_TIME = 1000; / / maximum number of ms to wait between r etrying th e RPC_SIGN ON | |
| 77 | pr ivate fina l static i nt FAILED_ SIGNIN_MAX _WAIT_TIME = 3000; / / maximum number of ms to wait between r etrying th e RPC_SIGN ON | |
| 78 | ||
| 79 | pr ivate fina l static S impleDateF ormat date Format = n ew SimpleD ateFormat( "yyyyMMddH HmmssSSS") ; // for D ICOM UID g eneration only | |
| 80 | ||
| 81 | pr ivate fina l static S tring MAG_ QA_CHECK = "0"; | |
| 82 | ||
| 83 | pr ivate fina l static S tring VIX_ BSE_APP_NA ME = "VIST A IMAGING VIX"; | |
| 84 | ||
| 85 | // the disco nnects are done in a worker th read pool | |
| 86 | st atic | |
| 87 | { | |
| 88 | disc onnectQueu e = new Ar rayBlockin gQueue<Run nable>(DIS CONNECT_QU EUE_SIZE); | |
| 89 | disc onnectExec utor = new ThreadPoo lExecutor( | |
| 90 | DISCON NECT_THREA D_COUNT, M AX_DISCONN ECT_THREAD , 10L, Tim eUnit.SECO NDS, disco nnectQueue ); | |
| 91 | } | |
| 92 | ||
| 93 | pu blic stati c Blocking Queue<Runn able> getD isconnectQ ueue() | |
| 94 | { | |
| 95 | retu rn disconn ectQueue; | |
| 96 | } | |
| 97 | ||
| 98 | pu blic stati c ThreadPo olExecutor getDiscon nectExecut or() | |
| 99 | { | |
| 100 | retu rn disconn ectExecuto r; | |
| 101 | } | |
| 102 | ||
| 103 | pr ivate stat ic String workstatio nId = null ; | |
| 104 | pu blic stati c String g etWorkstat ionId() { | |
| 105 | if(w orkstation Id == null ) { | |
| 106 | try { | |
| 107 | InetAddr ess addr = InetAddre ss.getLoca lHost(); | |
| 108 | workstat ionId = ad dr.getHost Name(); | |
| 109 | } | |
| 110 | catch( UnknownHos tException uhX) { | |
| 111 | logger.w arn("Unabl e to get l ocal hostn ame, using default v alue"); | |
| 112 | workstat ionId = "D OD-VA_WebS ervice"; | |
| 113 | } | |
| 114 | logger .info("Loc al host na me set to [" + works tationId + "]"); | |
| 115 | return workstati onId; | |
| 116 | } | |
| 117 | retu rn worksta tionId; | |
| 118 | } | |
| 119 | ||
| 120 | pr ivate Vist aRealmPrin cipal cred entials; | |
| 121 | pr ivate Stri ng remoteD uz; | |
| 122 | ||
| 123 | pr ivate Data Source ds = null; | |
| 124 | pr ivate ICon nection co nnection = null; | |
| 125 | ||
| 126 | /* * | |
| 127 | * Initiates a connect ion to the database without us ing any Vi stA Imagin g RPC call s | |
| 128 | * @param si te | |
| 129 | * @param cr edentials | |
| 130 | * @throws C onnectionF ailedExcep tion | |
| 131 | * @throws I nvalidCred entialsExc eption | |
| 132 | * @throws M ethodExcep tion | |
| 133 | * / | |
| 134 | pu blic void localConne ctWithoutI maging(Vis taRealmSit e site, Vi staRealmPr incipal cr edentials) | |
| 135 | th rows Conne ctionFaile dException , InvalidC redentials Exception, MethodExc eption | |
| 136 | { | |
| 137 | logg er.info("l ocalConnec tWithoutIm aging star ted"); | |
| 138 | this .credentia ls = crede ntials; | |
| 139 | ||
| 140 | ds = new DataS ource(); | |
| 141 | ds.s etSource(s ite.getVis taServer() ); | |
| 142 | ds.s etPort(sit e.getVista Port()); | |
| 143 | ds.s etProtocol (DATASOURC E_PROTOCOL ); | |
| 144 | ds.s etModality (DATASOURC E_MODALITY ); | |
| 145 | ds.s etUid(cred entials.ge tAccessCod e()); | |
| 146 | ds.s etPassword (credentia ls.getVeri fyCode()); | |
| 147 | ds.s etContext( CPRS_CONTE XT); | |
| 148 | ||
| 149 | conn ection = n ew VistaCo nnection(d s); | |
| 150 | ||
| 151 | Stri ng vistaRe sult = nul l; | |
| 152 | bool ean succes s = false; | |
| 153 | try | |
| 154 | { | |
| 155 | VistaQ uery vm = new VistaQ uery(RPC_S IGNON); | |
| 156 | ||
| 157 | connec tAndSignon (vm); | |
| 158 | ||
| 159 | vm.cle ar(); | |
| 160 | vm.set RpcName(RP C_AV_CODE) ; | |
| 161 | vm.add EncryptedP arameter(V istaQuery. LITERAL, d s.getUid() + ';' + d s.getPassw ord()); | |
| 162 | vistaR esult = co nnection.c all(vm.bui ldMessage( )); | |
| 163 | ||
| 164 | // val idate user credentia ls login i nformation | |
| 165 | String [] authRe sults = St ringUtils. Split(vist aResult, S tringUtils .NEW_LINE) ; | |
| 166 | long a uthValue = Long.pars eLong(auth Results[0] .trim()); | |
| 167 | if(aut hValue <= 0) | |
| 168 | { | |
| 169 | // faile d authenti cation, di sconnect b roker | |
| 170 | connecti on.disconn ect(); | |
| 171 | if(authR esults[2]. trim().equ als("1")) | |
| 172 | throw new Credential sExpiredEx ception("E xpired Ver ify Code") ; | |
| 173 | else | |
| 174 | throw new InvalidCre dentialsEx ception("I nvalid Acc ess/Verify Codes"); | |
| 175 | } | |
| 176 | ||
| 177 | setCon text(CPRS_ CONTEXT); | |
| 178 | setUse rPropertie s(); | |
| 179 | creden tials.setS iteNumber( site.getSi teNumber() ); | |
| 180 | creden tials.setS iteName(si te.getSite Name()); | |
| 181 | ||
| 182 | succes s = true; | |
| 183 | } | |
| 184 | catc h(UnableTo CreateCont extExcepti on utccX) | |
| 185 | { | |
| 186 | logger .error(utc cX); | |
| 187 | throw new Method Exception( utccX); | |
| 188 | } | |
| 189 | catc h(RpcExcep tion rpcX) | |
| 190 | { | |
| 191 | logger .error(rpc X); | |
| 192 | throw new Method Exception( rpcX); | |
| 193 | } | |
| 194 | catc h(InvalidC redentials Exception icX) | |
| 195 | { | |
| 196 | logger .error(icX ); | |
| 197 | throw icX; | |
| 198 | } | |
| 199 | catc h(NumberFo rmatExcept ion nfX) | |
| 200 | { | |
| 201 | logger .error( "U nable to p roperly pa rse Vista response." , nfX ); | |
| 202 | throw new Method Exception( nfX); | |
| 203 | } | |
| 204 | catc h(ArrayInd exOutOfBou ndsExcepti on aioobX) | |
| 205 | { | |
| 206 | logger .error( "U nable to p roperly pa rse Vista response." , aioobX ) ; | |
| 207 | throw new Method Exception( aioobX); | |
| 208 | } | |
| 209 | catc h(Exceptio n ex) | |
| 210 | { | |
| 211 | logger .error(ex) ; | |
| 212 | throw new Method Exception( ex); | |
| 213 | } | |
| 214 | fina lly | |
| 215 | { | |
| 216 | if( !s uccess && connection != null ) | |
| 217 | { | |
| 218 | try | |
| 219 | { | |
| 220 | logger.war n( "Connec tion faile d in RpcBr oker.local Connect(), disconnec ting..." ) ; | |
| 221 | connection .disconnec t(); | |
| 222 | } | |
| 223 | catch(Ex ception eX ) | |
| 224 | { | |
| 225 | logger.war n( "Except ion during error han dling disc onnect, co ntinuing . ...", eX ) ; | |
| 226 | } | |
| 227 | } | |
| 228 | logger .info("loc alConnect( ) complete "); | |
| 229 | } | |
| 230 | } | |
| 231 | ||
| 232 | /* * | |
| 233 | * | |
| 234 | * @param si te | |
| 235 | * @param cr edentials | |
| 236 | * @throws C onnectionF ailedExcep tion | |
| 237 | * @throws I nvalidCred entialsExc eption | |
| 238 | * @throws M ethodExcep tion | |
| 239 | * / | |
| 240 | pu blic void localConne ct(VistaRe almSite si te, VistaR ealmPrinci pal creden tials) | |
| 241 | th rows Conne ctionFaile dException , InvalidC redentials Exception, MethodExc eption | |
| 242 | { | |
| 243 | logg er.info("L ocalConnec t started to " + sit e.getVista Server() + ":" + sit e.getVista Port()); | |
| 244 | this .credentia ls = crede ntials; | |
| 245 | ||
| 246 | ds = new DataS ource( | |
| 247 | site.g etVistaSer ver(), | |
| 248 | site.g etVistaPor t().intVal ue(), | |
| 249 | DATASO URCE_PROTO COL, | |
| 250 | DATASO URCE_MODAL ITY, | |
| 251 | creden tials.getA ccessCode( ), | |
| 252 | creden tials.getV erifyCode( ), | |
| 253 | MAG_WI NDOWS_CONT EXT); | |
| 254 | ||
| 255 | conn ection = n ew VistaCo nnection(d s); | |
| 256 | ||
| 257 | Stri ng vistaRe sult = nul l; | |
| 258 | bool ean succes s = false; | |
| 259 | try | |
| 260 | { | |
| 261 | VistaQ uery vm = new VistaQ uery(RPC_S IGNON); | |
| 262 | ||
| 263 | connec tAndSignon (vm); | |
| 264 | ||
| 265 | vm.cle ar(); | |
| 266 | vm.set RpcName(RP C_AV_CODE) ; | |
| 267 | vm.add EncryptedP arameter(V istaQuery. LITERAL, d s.getUid() + ';' + d s.getPassw ord()); | |
| 268 | vistaR esult = co nnection.c all(vm.bui ldMessage( )); | |
| 269 | ||
| 270 | // val idate user credentia ls login i nformation | |
| 271 | String [] authRe sults = St ringUtils. Split(vist aResult, S tringUtils .NEW_LINE) ; | |
| 272 | long a uthValue = Long.pars eLong(auth Results[0] .trim()); | |
| 273 | if(aut hValue <= 0) | |
| 274 | { | |
| 275 | // faile d authenti cation, di sconnect b roker | |
| 276 | connecti on.disconn ect(); | |
| 277 | if(authR esults[2]. trim().equ als("1")) | |
| 278 | throw new Credential sExpiredEx ception("E xpired Ver ify Code") ; | |
| 279 | else | |
| 280 | throw new InvalidCre dentialsEx ception("I nvalid Acc ess/Verify Codes"); | |
| 281 | } | |
| 282 | ||
| 283 | setCon text(CPRS_ CONTEXT); | |
| 284 | setUse rPropertie s(); | |
| 285 | creden tials.setS iteNumber( site.getSi teNumber() ); | |
| 286 | creden tials.setS iteName(si te.getSite Name()); | |
| 287 | ||
| 288 | //setC ontext(ds. getContext ()); | |
| 289 | setCon text(MAG_W INDOWS_CON TEXT); | |
| 290 | succes s = true; | |
| 291 | ||
| 292 | } | |
| 293 | catc h(UnableTo CreateCont extExcepti on utccX) | |
| 294 | { | |
| 295 | logger .error(utc cX); | |
| 296 | throw new Method Exception( utccX); | |
| 297 | } | |
| 298 | catc h(RpcExcep tion rpcX) | |
| 299 | { | |
| 300 | logger .error(rpc X); | |
| 301 | throw new Method Exception( rpcX); | |
| 302 | } | |
| 303 | catc h(InvalidC redentials Exception icX) | |
| 304 | { | |
| 305 | logger .error(icX ); | |
| 306 | throw icX; | |
| 307 | } | |
| 308 | catc h(NumberFo rmatExcept ion nfX) | |
| 309 | { | |
| 310 | logger .error( "U nable to p roperly pa rse Vista response." , nfX ); | |
| 311 | throw new Method Exception( nfX); | |
| 312 | } | |
| 313 | catc h(ArrayInd exOutOfBou ndsExcepti on aioobX) | |
| 314 | { | |
| 315 | logger .error( "U nable to p roperly pa rse Vista response." , aioobX ) ; | |
| 316 | throw new Method Exception( aioobX); | |
| 317 | } | |
| 318 | catc h(Exceptio n ex) | |
| 319 | { | |
| 320 | logger .error(ex) ; | |
| 321 | throw new Method Exception( ex); | |
| 322 | } | |
| 323 | fina lly | |
| 324 | { | |
| 325 | if( !s uccess && connection != null ) | |
| 326 | { | |
| 327 | try | |
| 328 | { | |
| 329 | logger.war n( "Connec tion faile d in RpcBr oker.local Connect(), disconnec ting..." ) ; | |
| 330 | connection .disconnec t(); | |
| 331 | } | |
| 332 | catch(Ex ception eX ) | |
| 333 | { | |
| 334 | logger.war n( "Except ion during error han dling disc onnect, co ntinuing . ...", eX ) ; | |
| 335 | } | |
| 336 | } | |
| 337 | logger .info("loc alConnect( ) complete "); | |
| 338 | } | |
| 339 | } | |
| 340 | ||
| 341 | /* * | |
| 342 | * | |
| 343 | * @param si te | |
| 344 | * @param cr edentials | |
| 345 | * @throws C onnectionF ailedExcep tion | |
| 346 | * @throws M ethodExcep tion | |
| 347 | * / | |
| 348 | /* | |
| 349 | / / this met hod is not used in t he realm ( can't thin k of a rea son it wou ld be used ) | |
| 350 | pu blic void remoteConn ect(VistaR ealmSite s ite, Vista RealmPrinc ipal crede ntials) | |
| 351 | th rows Conne ctionFaile dException , MethodEx ception | |
| 352 | { | |
| 353 | this .credentia ls = crede ntials; | |
| 354 | bool ean succes s = false; | |
| 355 | ||
| 356 | ds = new DataS ource(); | |
| 357 | ds.s etSource(s ite.getVis taServer() ); | |
| 358 | ds.s etPort(sit e.getVista Port()); | |
| 359 | ds.s etProtocol (DATASOURC E_PROTOCOL ); | |
| 360 | ds.s etModality (DATASOURC E_MODALITY ); | |
| 361 | ||
| 362 | conn ection = n ew VistaCo nnection(d s); | |
| 363 | ||
| 364 | // p erform a l ogin | |
| 365 | Vist aQuery vm = new Vist aQuery(RPC _SIGNON); | |
| 366 | vm.a ddParamete r( | |
| 367 | VistaQue ry.LITERAL , | |
| 368 | "-31^DVB A_^" + cre dentials.g etSsn() + | |
| 369 | "^" + cr edentials. getFullNam e() + | |
| 370 | "^" + cr edentials. getSiteNam e() + | |
| 371 | "^" + cr edentials. getSiteNum ber() + | |
| 372 | "^" + cr edentials. getDuz() + "^No Phon e"); | |
| 373 | ||
| 374 | Stri ng remoteD UZ = ""; | |
| 375 | try | |
| 376 | { | |
| 377 | connec tAndSignon (vm); | |
| 378 | ||
| 379 | // can 't run thi s unless h as proper context | |
| 380 | try { | |
| 381 | setConte xt(MAG_WIN DOWS_CONTE XT); | |
| 382 | remoteDU Z = getDUZ (credentia ls.getSsn( )); | |
| 383 | remoteDu z = remote DUZ; | |
| 384 | ((VistaC onnection) connection ).setUid(r emoteDuz); | |
| 385 | success = true; | |
| 386 | } | |
| 387 | catch( UnableToCr eateContex tException utccX) { | |
| 388 | try { | |
| 389 | // user mi ght not ha ve MAG WIN DOWS conte xt assigne d to them | |
| 390 | setContext (CAPRI_CON TEXT); | |
| 391 | String mag WindowsCon textIEN = getContext IEN(MAG_WI NDOWS_CONT EXT); | |
| 392 | ||
| 393 | remoteDUZ = getDUZ(c redentials .getSsn()) ; | |
| 394 | remoteDuz = remoteDU Z; | |
| 395 | ((VistaCon nection)co nnection). setUid(rem oteDuz); | |
| 396 | ||
| 397 | assignOpti on(MENU_SU BSCRIPT, m agWindowsC ontextIEN) ; | |
| 398 | ||
| 399 | try | |
| 400 | { | |
| 401 | Th read.sleep (2000); | |
| 402 | } | |
| 403 | catch (Int erruptedEx ception ie ) | |
| 404 | { | |
| 405 | th row new Me thodExcept ion(ie); | |
| 406 | } | |
| 407 | ||
| 408 | String cap riIEN = ge tContextIE N(CAPRI_CO NTEXT); | |
| 409 | if (!capri IEN.equals ("")) | |
| 410 | { | |
| 411 | St ring capri MenuOption Number = g etOptionIE N(MENU_SUB SCRIPT, ca priIEN); | |
| 412 | if (!capriMe nuOptionNu mber.equal s("")) | |
| 413 | { | |
| 414 | remo veOption(M ENU_SUBSCR IPT, capri MenuOption Number); | |
| 415 | } | |
| 416 | } | |
| 417 | setContext (MAG_WINDO WS_CONTEXT ); | |
| 418 | success = true; | |
| 419 | } | |
| 420 | catch(Un ableToCrea teContextE xception u tccX2) { | |
| 421 | logger.war n("Unable to create context, " + utccX.t oString()) ; | |
| 422 | throw new MethodExce ption(utcc X2); | |
| 423 | } | |
| 424 | } | |
| 425 | } | |
| 426 | catc h (Excepti on ex) | |
| 427 | { | |
| 428 | throw new Method Exception( ex); | |
| 429 | } | |
| 430 | fina lly | |
| 431 | { | |
| 432 | if(! s uccess && connection != null) { | |
| 433 | try | |
| 434 | { | |
| 435 | logger.war n("Unable to connect remotely, disconnec ting"); | |
| 436 | connection .disconnec t(); | |
| 437 | } | |
| 438 | catch(Ex ception eX ) {} | |
| 439 | } | |
| 440 | } | |
| 441 | } | |
| 442 | */ | |
| 443 | ||
| 444 | /* * | |
| 445 | * @param vm | |
| 446 | * @return | |
| 447 | * @throws E xception | |
| 448 | * @throws M ethodExcep tion | |
| 449 | * / | |
| 450 | pr ivate Stri ng connect AndSignon( VistaQuery vm) | |
| 451 | th rows Excep tion, Meth odExceptio n | |
| 452 | { | |
| 453 | Stri ng vistaRe sult = nul l; | |
| 454 | ||
| 455 | int retryCount ; | |
| 456 | Exce ption sign onExceptio n = null; | |
| 457 | for( retryCount =0; retryC ount<FAILE D_SIGNON_M AX_COUNT; ++retryCou nt) | |
| 458 | { | |
| 459 | connec tion.conne ct(); | |
| 460 | ||
| 461 | try | |
| 462 | { | |
| 463 | vistaRes ult = conn ection.cal l(vm.build Message()) ; | |
| 464 | if (vist aResult == null) | |
| 465 | throw new UnableToCo nnectToBro kerExcepti on("Null r esult retu rned from Vista in r esponse to RPC_SIGNI N call."); | |
| 466 | ||
| 467 | break; | |
| 468 | } | |
| 469 | catch (Exception ex) | |
| 470 | { | |
| 471 | // remem ber the fi rst except ion | |
| 472 | signonEx ception = signonExce ption == n ull ? ex : signonExc eption; | |
| 473 | ||
| 474 | // disco nnect and ignore all errors | |
| 475 | try{conn ection.dis connect(); } | |
| 476 | catch(Th rowable t) {} | |
| 477 | ||
| 478 | // delay for a ran dom amount of time f rom 1 to 2 seconds | |
| 479 | long ran domDelay = (long)(Ma th.random( ) * (FAILE D_SIGNIN_M AX_WAIT_TI ME - FAILE D_SIGNON_M IN_WAIT_TI ME) + FAIL ED_SIGNON_ MIN_WAIT_T IME); | |
| 480 | logger.w arn("RPC_S IGNON fail ed (" + re tryCount + "), retry ing in " + randomDel ay + " mil liseconds" ); | |
| 481 | try{Thre ad.sleep(r andomDelay );} | |
| 482 | catch(In terruptedE xception i X){} | |
| 483 | } | |
| 484 | } | |
| 485 | ||
| 486 | if(r etryCount >= FAILED_ SIGNON_MAX _COUNT) | |
| 487 | { | |
| 488 | logger .error("RP C_SIGNON f ailed, ret ry count e xceeded.") ; | |
| 489 | throw new Method Exception( signonExce ption); | |
| 490 | } | |
| 491 | retu rn vistaRe sult; | |
| 492 | } | |
| 493 | ||
| 494 | ||
| 495 | /* * | |
| 496 | * Makes Vis tA rpc bro ker connec tion. Han dles autom atically a ttempting reconnects until FAI LED_CONNEC TION_MAX_C OUNT thres hold is me t. | |
| 497 | * | |
| 498 | * @param vi staConnect ion The Vi stA server to connec t to, excp ected to b e created and have s erver and port set b ut disconn ected. | |
| 499 | * @throws U nableToCon nectToBrok erExceptio n Thrown i f the conn ection is unable to be made af ter FAILED _CONNECTIO N_MAX_COUN T. | |
| 500 | * / | |
| 501 | pr ivate void connect() | |
| 502 | th rows Unabl eToConnect ToBrokerEx ception | |
| 503 | { | |
| 504 | bool ean connec tionOK = f alse; | |
| 505 | Exce ption last Exception = null; | |
| 506 | for( int failur eCount = 0 ; failureC ount < FAI LED_CONNEC TION_MAX_C OUNT && !c onnectionO K; ++failu reCount) | |
| 507 | { | |
| 508 | try | |
| 509 | { | |
| 510 | connecti on.connect (); | |
| 511 | // if th ere was on e or more failures b ut the con nection ha ppened eve ntually, l og it | |
| 512 | if(failu reCount > 0) | |
| 513 | logger.inf o("RpcBrok er.connect () connect ed after [ " + failur eCount + " ] attempts "); | |
| 514 | ||
| 515 | connecti onOK = tru e; | |
| 516 | } | |
| 517 | catch( Exception eX) | |
| 518 | { | |
| 519 | logger.i nfo("Excep tion in Rp cBroker.co nnect() [" + eX.getM essage() + "] on att empt [" + failureCou nt + "]"); | |
| 520 | if(failu reCount >= FAILED_CO NNECTION_M AX_COUNT) | |
| 521 | { | |
| 522 | lastExcept ion = eX; | |
| 523 | logger.inf o("RpcBrok er.connect () failed after [" + FAILED_CO NNECTION_M AX_COUNT + "] attemp ts"); | |
| 524 | } | |
| 525 | else | |
| 526 | { | |
| 527 | // wait a random amo unt of tim e to break a race co ndition if another c onnection is interfe ring | |
| 528 | // with ou r connecti on | |
| 529 | long sleep Time = (lo ng)(Math.r andom() * (FAILED_CO NNECTION_M AX_WAIT_TI ME - FAILE D_CONNECTI ON_MIN_WAI T_TIME) + FAILED_CON NECTION_MI N_WAIT_TIM E); | |
| 530 | logger.inf o("RpcBrok er.connect () sleepin g for [" + sleepTime + "] ms") ; | |
| 531 | try | |
| 532 | { | |
| 533 | Th read.sleep (sleepTime ); | |
| 534 | } | |
| 535 | catch(Inte rruptedExc eption iX) | |
| 536 | { | |
| 537 | // not reall y much to do here, i f the slee p fails, w e'll just continue o n - hopefu lly the co nnection w ill then w ork | |
| 538 | } | |
| 539 | } | |
| 540 | } | |
| 541 | } | |
| 542 | // i f the conn ection fai led, then throw the last excep tion | |
| 543 | if(! connection OK) | |
| 544 | throw new Unable ToConnectT oBrokerExc eption(las tException ); | |
| 545 | } | |
| 546 | ||
| 547 | ||
| 548 | pr ivate fina l static S tring RPC_ MAG_USER_K EYS = "MAG GUSERKEYS" ; | |
| 549 | pu blic Strin g[] getUse rKeys() | |
| 550 | th rows RpcEx ception | |
| 551 | { | |
| 552 | Vist aQuery vm = new Vist aQuery(RPC _MAG_USER_ KEYS); | |
| 553 | ||
| 554 | try | |
| 555 | { | |
| 556 | String rtn = con nection.ca ll(vm.buil dMessage() ); | |
| 557 | ||
| 558 | String [] keys = StringUtil s.Split(rt n, StringU tils.NEW_L INE); | |
| 559 | ||
| 560 | // tri m whitespa ce, includ ing CR and /or LF cha racters | |
| 561 | if(key s != null) | |
| 562 | for(int index=0; i ndex<keys. length; ++ index) | |
| 563 | keys[index ] = keys[i ndex].trim (); | |
| 564 | ||
| 565 | return keys; | |
| 566 | } | |
| 567 | catc h (Excepti on ex) | |
| 568 | { | |
| 569 | throw new RpcExc eption(ex) ; | |
| 570 | } | |
| 571 | } | |
| 572 | ||
| 573 | pr ivate Stri ng getDUZ( String use rSSN) thro ws Excepti on | |
| 574 | { | |
| 575 | Vist aQuery msg = new Vis taQuery(RP C_GET_VARI ABLE_VALUE ); | |
| 576 | Stri ng arg = " $O(^VA(200 ,\"SSN\",\ "" + userS SN + "\",0 ))"; | |
| 577 | msg. addParamet er(VistaQu ery.REFERE NCE, arg); | |
| 578 | Stri ng rtn = c onnection. call(msg.b uildMessag e()); | |
| 579 | if ( !StringUti ls.isNumer ic(rtn)) | |
| 580 | { | |
| 581 | throw new Except ion("Non-n umeric DUZ "); | |
| 582 | } | |
| 583 | retu rn rtn; | |
| 584 | } | |
| 585 | ||
| 586 | pr ivate Stri ng getCont extIEN(Str ing contex t) throws Exception | |
| 587 | { | |
| 588 | Vist aQuery msg = new Vis taQuery(RP C_GET_VARI ABLE_VALUE ); | |
| 589 | Stri ng arg = " $O(^DIC(19 ,\"B\",\"" + context + "\",0)) "; | |
| 590 | msg. addParamet er(VistaQu ery.REFERE NCE, arg); | |
| 591 | Stri ng rtn = c onnection. call(msg.b uildMessag e()); | |
| 592 | if ( !StringUti ls.isNumer ic(rtn)) | |
| 593 | { | |
| 594 | throw new Except ion("Non-n umeric con text IEN f or " + con text); | |
| 595 | } | |
| 596 | retu rn rtn; | |
| 597 | } | |
| 598 | ||
| 599 | pr ivate Stri ng assignO ption(Stri ng subscri pt, String contextIE N) | |
| 600 | throws Exception | |
| 601 | { | |
| 602 | Vist aQuery msg = new Vis taQuery(RP C_DDR_FILE R); | |
| 603 | msg. addParamet er(VistaQu ery.LITERA L, "ADD"); | |
| 604 | Stri ng arg = s ubscript + "^.01^+1, " + remote Duz + ",^" | |
| 605 | + contex tIEN; | |
| 606 | Hash Map<String , String> lst = new HashMap<St ring, Stri ng>(); | |
| 607 | lst. put("1", a rg); | |
| 608 | msg. addParamet er(VistaQu ery.LIST, lst); | |
| 609 | // m sg.addPara meter(Vist aQuery.LIS T,".x",arg ); | |
| 610 | Stri ng rtn = c onnection. call(msg.b uildMessag e()); | |
| 611 | retu rn parseOp tionNumber (rtn); | |
| 612 | } | |
| 613 | ||
| 614 | pr ivate Stri ng getOpti onIEN(Stri ng subscri pt, String contextIe n) throws Exception { | |
| 615 | Vist aQuery msg = new Vis taQuery(RP C_GET_VARI ABLE_VALUE ); | |
| 616 | Stri ng arg = " $O(^VA(200 ," + remot eDuz; | |
| 617 | if ( subscript. equals(DEL EGATE_SUBS CRIPT)) { | |
| 618 | arg += ",19.5," + contextI en + ",-1) )"; | |
| 619 | } el se if (sub script.equ als(MENU_S UBSCRIPT)) { | |
| 620 | arg += ",203,\"B \"," + con textIen + ",0))"; | |
| 621 | } | |
| 622 | msg. addParamet er(VistaQu ery.REFERE NCE, arg); | |
| 623 | Stri ng rtn = c onnection. call(msg.b uildMessag e()); | |
| 624 | if ( !StringUti ls.isNumer ic(rtn)) { | |
| 625 | throw new Except ion("Non-n umeric opt ion IEN fo r " + subs cript); | |
| 626 | } | |
| 627 | retu rn rtn; | |
| 628 | } | |
| 629 | ||
| 630 | pr ivate void removeOpt ion(String subscript , String o ptNum) thr ows Except ion { | |
| 631 | Vist aQuery msg = new Vis taQuery(RP C_DDR_FILE R); | |
| 632 | msg. addParamet er(VistaQu ery.LITERA L, "EDIT") ; | |
| 633 | Stri ng arg = s ubscript + "^.01^" + optNum + "," + remo teDuz | |
| 634 | + ",^@"; | |
| 635 | Hash Map<String , String> lst = new HashMap<St ring, Stri ng>(); | |
| 636 | lst. put("1", a rg); | |
| 637 | msg. addParamet er(VistaQu ery.LIST, lst); | |
| 638 | // m sg.addPara meter(Vist aQuery.LIS T,".x",arg ); | |
| 639 | Stri ng rtn = c onnection. call(msg.b uildMessag e()); | |
| 640 | if ( !rtn.equal s("[Data]" )) { | |
| 641 | throw new Except ion("ERROR : " + rtn) ; | |
| 642 | } | |
| 643 | } | |
| 644 | ||
| 645 | pr ivate Stri ng parseOp tionNumber (String rt n) throws Exception { | |
| 646 | Stri ng[] lines = StringU tils.Split (rtn, Stri ngUtils.CR LF); | |
| 647 | if ( !lines[0]. equals("[D ata]")) { | |
| 648 | throw new Except ion("Inval id return format (" + rtn + ") "); | |
| 649 | } | |
| 650 | if ( lines[1].s tartsWith( "[BEGIN_di ERRORS]")) { | |
| 651 | throw new Except ion(rtn.su bstring(8) ); | |
| 652 | } | |
| 653 | if ( lines.leng th == 1) { | |
| 654 | throw new Except ion("No op tion numbe r data"); | |
| 655 | } | |
| 656 | int p = lines[ 1].indexOf (",^"); | |
| 657 | Stri ng optNum = lines[1] .substring (p + 2); | |
| 658 | if ( !StringUti ls.isNumer ic(optNum) ) { | |
| 659 | throw new Except ion("Non-n umeric opt ion number "); | |
| 660 | } | |
| 661 | retu rn optNum; | |
| 662 | } | |
| 663 | ||
| 664 | pr ivate void setContex t(String c ontext) th rows Unabl eToCreateC ontextExce ption { | |
| 665 | Vi staQuery v m = new Vi staQuery(R PC_CREATE_ CONTEXT); | |
| 666 | vm .addEncryp tedParamet er(VistaQu ery.LITERA L, context ); | |
| 667 | St ring rtn = ""; | |
| 668 | tr y { | |
| 669 | rtn = connecti on.call(vm .buildMess age()); | |
| 670 | } | |
| 671 | ca tch(Except ion ex) { | |
| 672 | thro w new Unab leToCreate ContextExc eption(ex) ; | |
| 673 | } | |
| 674 | if (!rtn.equ als("1")) | |
| 675 | { | |
| 676 | thro w new Unab leToCreate ContextExc eption("Un able to se t context [" + conte xt + "]"); | |
| 677 | } | |
| 678 | } | |
| 679 | ||
| 680 | pr ivate void setUserPr operties() throws Rp cException { | |
| 681 | Vist aQuery vm = new Vist aQuery(RPC _GET_USER_ INFO); | |
| 682 | St ring rtn = null; | |
| 683 | tr y { | |
| 684 | rtn = connecti on.call(vm .buildMess age()); | |
| 685 | } | |
| 686 | ca tch(Except ion ex) { | |
| 687 | thro w new RpcE xception(e x); | |
| 688 | } | |
| 689 | if (rtn == n ull) | |
| 690 | { | |
| 691 | thro w new RpcE xception(" Unable to get user i nfo"); | |
| 692 | } | |
| 693 | Stri ng[] parts = StringU tils.Split (rtn,Strin gUtils.CAR ET); | |
| 694 | tr y | |
| 695 | { | |
| 696 | cred entials.se tDuz(parts [0]); | |
| 697 | cred entials.se tFullName( parts[1]); | |
| 698 | } | |
| 699 | ca tch (Excep tion ex) | |
| 700 | { | |
| 701 | thro w new RpcE xception(e x); | |
| 702 | //throw new DaoExc eption(ex) ; | |
| 703 | } | |
| 704 | vm = new Vis taQuery(RP C_GET_VARI ABLE_VALUE ); | |
| 705 | St ring arg = "@\"^VA(2 00," + cre dentials.g etDuz() + ",1)\""; | |
| 706 | vm .addParame ter(VistaQ uery.REFER ENCE,arg); | |
| 707 | tr y { | |
| 708 | rtn = connecti on.call(vm .buildMess age()); | |
| 709 | } | |
| 710 | ca tch(Except ion ex) { | |
| 711 | thro w new RpcE xception(e x); | |
| 712 | ||
| 713 | } | |
| 714 | if (rtn.equa ls("")) | |
| 715 | { | |
| 716 | thro w new RpcE xception(" Ubable to get user S SN"); | |
| 717 | //throw new DaoExc eption("Un able to ge t user SSN "); | |
| 718 | } | |
| 719 | part s = String Utils.Spli t(rtn,Stri ngUtils.CA RET); | |
| 720 | tr y | |
| 721 | { | |
| 722 | cred entials.se tSsn(parts [8]); | |
| 723 | } | |
| 724 | ca tch (Excep tion ex) | |
| 725 | { | |
| 726 | thro w new RpcE xception(e x); | |
| 727 | //throw new DaoExc eption(ex) ; | |
| 728 | } | |
| 729 | } | |
| 730 | ||
| 731 | bo olean disc onnecting = false; | |
| 732 | bo olean disc onnectWith Imaging = true; | |
| 733 | ||
| 734 | pu blic boole an isDisco nnectWithI maging() | |
| 735 | { | |
| 736 | retu rn this.di sconnectWi thImaging; | |
| 737 | } | |
| 738 | ||
| 739 | /* * | |
| 740 | * Submit th e connecti on for an asynchrono us disconn ect | |
| 741 | * @return | |
| 742 | * / | |
| 743 | pu blic boole an disconn ectWithout Imaging() | |
| 744 | { | |
| 745 | this .disconnec ting = tru e; | |
| 746 | this .disconnec tWithImagi ng = false ; | |
| 747 | getD isconnectE xecutor(). submit(thi s); | |
| 748 | retu rn true; | |
| 749 | } | |
| 750 | /* * | |
| 751 | * Submit th e connecti on for an asynchrono us disconn ect | |
| 752 | * @return | |
| 753 | * / | |
| 754 | pu blic boole an disconn ect() | |
| 755 | { | |
| 756 | this .disconnec ting = tru e; | |
| 757 | this .disconnec tWithImagi ng = true; | |
| 758 | getD isconnectE xecutor(). submit(thi s); | |
| 759 | retu rn true; | |
| 760 | } | |
| 761 | ||
| 762 | /* * | |
| 763 | * Closes th e connecti on to the VistA data base witho ut making any VistA Imaging RP C calls | |
| 764 | * @return | |
| 765 | * / | |
| 766 | pr ivate bool ean discon nectWithou tImagingIm mediate() | |
| 767 | { | |
| 768 | try | |
| 769 | { | |
| 770 | connec tion.disco nnect(); | |
| 771 | return true; | |
| 772 | } | |
| 773 | catc h(Exceptio n ex) | |
| 774 | { | |
| 775 | ex.pri ntStackTra ce(); | |
| 776 | return false; | |
| 777 | } | |
| 778 | } | |
| 779 | ||
| 780 | pr ivate bool ean discon nectImmedi ate() | |
| 781 | { | |
| 782 | Vist aQuery vm = new Vist aQuery(RPC _MAG_LOGOF F); | |
| 783 | bool ean maggLo goffComple te = false ; | |
| 784 | try | |
| 785 | { | |
| 786 | connec tion.call( vm.buildMe ssage()); | |
| 787 | maggLo goffComple te = true; | |
| 788 | connec tion.disco nnect(); | |
| 789 | return true; | |
| 790 | } | |
| 791 | catc h (Excepti on ex) | |
| 792 | { | |
| 793 | if (!m aggLogoffC omplete) | |
| 794 | { | |
| 795 | try | |
| 796 | { | |
| 797 | connection .disconnec t(); | |
| 798 | return tru e; | |
| 799 | } | |
| 800 | catch (E xception e x2) | |
| 801 | { | |
| 802 | // log exc eption | |
| 803 | ex2.printS tackTrace( ); | |
| 804 | return fal se; | |
| 805 | } | |
| 806 | } | |
| 807 | } | |
| 808 | retu rn true; | |
| 809 | } | |
| 810 | ||
| 811 | pu blic Strin g getBroke rSecurityT okenWithou tImaging(S tring bseR ealm) | |
| 812 | th rows RpcEx ception | |
| 813 | { | |
| 814 | Vist aQuery vm = new Vist aQuery(RPC _XUS_SET_V ISITOR); | |
| 815 | ||
| 816 | try | |
| 817 | { | |
| 818 | String rtn = con nection.ca ll(vm.buil dMessage() ); | |
| 819 | return createFul lVIXTokenS tring(rtn, bseRealm) ; | |
| 820 | } | |
| 821 | catc h (Excepti on ex) | |
| 822 | { | |
| 823 | throw new RpcExc eption(ex) ; | |
| 824 | } | |
| 825 | } | |
| 826 | ||
| 827 | pu blic Strin g getBroke rSecurityT okenWithIm aging(Stri ng bseReal m) | |
| 828 | th rows RpcEx ception | |
| 829 | { | |
| 830 | Vist aQuery vm = new Vist aQuery(RPC _MAG_BROKE R_SECURITY ); | |
| 831 | ||
| 832 | try | |
| 833 | { | |
| 834 | String rtn = con nection.ca ll(vm.buil dMessage() ); | |
| 835 | return createFul lVIXTokenS tring(rtn, bseRealm) ; | |
| 836 | } | |
| 837 | catc h (Excepti on ex) | |
| 838 | { | |
| 839 | throw new RpcExc eption(ex) ; | |
| 840 | } | |
| 841 | } | |
| 842 | ||
| 843 | pr ivate Stri ng createF ullVIXToke nString(St ring xwbTo ken, Strin g bseRealm ) | |
| 844 | { | |
| 845 | if(b seRealm == null) | |
| 846 | bseRea lm = this. credential s.getRealm (); | |
| 847 | retu rn VIX_BSE _APP_NAME + StringUt ils.CARET + | |
| 848 | xwbTok en + Strin gUtils.CAR ET + | |
| 849 | bseRea lm + Strin gUtils.CAR ET + | |
| 850 | this.c onnection. getDataSou rce().getP ort(); | |
| 851 | } | |
| 852 | ||
| 853 | /* | |
| 854 | * Asynchron ous discon nect | |
| 855 | * | |
| 856 | * @see java .lang.Runn able#run() | |
| 857 | * / | |
| 858 | @O verride | |
| 859 | pu blic void run() | |
| 860 | { | |
| 861 | try | |
| 862 | { | |
| 863 | logger .info("Dis connecting RPCBroker " + this. toString() ); | |
| 864 | if(isD isconnectW ithImaging ()) | |
| 865 | this.dis connectImm ediate(); | |
| 866 | else | |
| 867 | this.dis connectWit houtImagin gImmediate (); | |
| 868 | } | |
| 869 | catc h(Throwabl e x) | |
| 870 | { | |
| 871 | logger .warn(x.ge tMessage() + "while disconnect ing RPCBro ker " + th is.toStrin g()); | |
| 872 | } | |
| 873 | } | |
| 874 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.