Produced by Araxis Merge on 12/5/2017 12:06:45 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\ImagingExchangeBaseWebProxy\main\src\java\gov\va\med\imaging\proxy | ImagingProxy.java | Mon Dec 4 21:34:34 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingExchangeBaseWebProxy\main\src\java\gov\va\med\imaging\proxy | ImagingProxy.java | Mon Dec 4 22:03:15 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1468 |
| 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.pro xy; | |
| 2 | ||
| 3 | ||
| 4 | import gov .va.med.im aging.Size dInputStre am; | |
| 5 | import gov .va.med.im aging.chan nels.Check sumValue; | |
| 6 | import gov .va.med.im aging.chan nels.excep tions.Chec ksumFormat Exception; | |
| 7 | import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on; | |
| 8 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageCo nversionEx ception; | |
| 9 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageNe arLineExce ption; | |
| 10 | import gov .va.med.im aging.core .interface s.exceptio ns.ImageNo tFoundExce ption; | |
| 11 | import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception; | |
| 12 | import gov .va.med.im aging.core .interface s.exceptio ns.Securit yCredentia lsExpiredE xception; | |
| 13 | import gov .va.med.im aging.exch ange.busin ess.ImageF ormatQuali tyList; | |
| 14 | import gov .va.med.im aging.exch ange.busin ess.Reques tor; | |
| 15 | import gov .va.med.im aging.exch ange.enums .ImageForm at; | |
| 16 | import gov .va.med.im aging.exch ange.enums .ImageQual ity; | |
| 17 | import gov .va.med.im aging.prox y.exceptio ns.ProxySe rviceNotFo undExcepti on; | |
| 18 | import gov .va.med.im aging.prox y.services .ProxyServ ice; | |
| 19 | import gov .va.med.im aging.prox y.services .ProxyServ iceType; | |
| 20 | import gov .va.med.im aging.prox y.services .ProxyServ ices; | |
| 21 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont ext; | |
| 22 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ; | |
| 23 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extHttpHea ders; | |
| 24 | ||
| 25 | import jav a.io.IOExc eption; | |
| 26 | import jav a.io.Input Stream; | |
| 27 | import jav a.text.Dat eFormat; | |
| 28 | import jav a.text.Sim pleDateFor mat; | |
| 29 | import jav a.util.zip .CheckedIn putStream; | |
| 30 | import jav a.util.zip .Checksum; | |
| 31 | import jav a.util.zip .GZIPInput Stream; | |
| 32 | ||
| 33 | import org .apache.ax is.transpo rt.http.HT TPConstant s; | |
| 34 | import org .apache.co mmons.http client.Hea der; | |
| 35 | import org .apache.co mmons.http client.Htt pClient; | |
| 36 | import org .apache.co mmons.http client.Htt pException ; | |
| 37 | import org .apache.co mmons.http client.Htt pStatus; | |
| 38 | import org .apache.co mmons.http client.URI ; | |
| 39 | import org .apache.co mmons.http client.Use rnamePassw ordCredent ials; | |
| 40 | import org .apache.co mmons.http client.aut h.AuthScop e; | |
| 41 | import org .apache.co mmons.http client.met hods.GetMe thod; | |
| 42 | import org .apache.lo gging.log4 j.LogManag er; | |
| 43 | import org .apache.lo gging.log4 j.Logger; | |
| 44 | ||
| 45 | /** | |
| 46 | * This cl ass is a s imple prox y for the web access to images . | |
| 47 | * The fun ctionality in here i s shared b y the thre e webservi ce proxies (exchange , federati on and cli nicaldispl ay). | |
| 48 | * This cl ass may be used as a concrete class, tho ugh there is current ly nowhere that it i s used as such | |
| 49 | * @author
|
|
| 50 | * | |
| 51 | */ | |
| 52 | public abs tract clas s ImagingP roxy | |
| 53 | { | |
| 54 | // the list of HTTP he aders fiel ds set by the proxy and unders tood by | |
| 55 | // the serve r | |
| 56 | /* | |
| 57 | // JMW 8/19/ 2010 | |
| 58 | // these hea der values no longer used, usi ng values from Trans actionCont extHttpHea ders class | |
| 59 | // (identica l to these here) | |
| 60 | pu blic final static St ring httpH eaderDuz = "xxx-duz" ; | |
| 61 | pu blic final static St ring httpH eaderFullN ame = "xxx -fullname" ; | |
| 62 | pu blic final static St ring httpH eaderSiteN ame = "xxx -sitename" ; | |
| 63 | pu blic final static St ring httpH eaderSiteN umber = "x xx-sitenum ber"; | |
| 64 | pu blic final static St ring httpH eaderSSN = "xxx-ssn" ; | |
| 65 | pu blic final static St ring httpH eaderPurpo seOfUse = "xxx-purpo se-of-use" ; | |
| 66 | pu blic final static St ring httpH eaderCheck sum = "xxx -checksum" ; | |
| 67 | pu blic final static St ring httpH eaderTrans actionId = "xxx-tran saction-id "; | |
| 68 | pu blic final static St ring httpH eaderBroke rSecurityT okenId = " xxx-securi tyToken"; | |
| 69 | pu blic final static St ring httpH eaderCache LocationId = "xxx-ca cheLocatio nId"; | |
| 70 | pu blic final static St ring httpH eaderUserD ivision = "xxx-userD ivision"; | |
| 71 | ||
| 72 | pu blic final static St ring httpH eaderImage Checksum = "xxx-imag e-checksum "; | |
| 73 | pu blic final static St ring httpH eaderTXTCh ecksum = " xxx-txt-ch ecksum"; | |
| 74 | pu blic final static St ring httpH eaderImage Quality = "xxx-image -quality"; | |
| 75 | pu blic final static St ring httpH eaderImage Size = "xx x-image-le ngth"; | |
| 76 | pu blic final static St ring httpH eaderTxtSi ze = "xxx- txt-length "; | |
| 77 | */ | |
| 78 | ||
| 79 | pr otected Lo gger logge r = LogMan ager.getLo gger(Imagi ngProxy.cl ass); | |
| 80 | ||
| 81 | ||
| 82 | // YYYYMMDDH HMMSS.FFFF FF+ZZZZ | |
| 83 | // The compo nents of t his string , from lef t to right , are | |
| 84 | // YYYY = Ye ar, | |
| 85 | // MM = Mont h, | |
| 86 | // DD = Day, | |
| 87 | // HH = Hour , | |
| 88 | // MM = Minu te, | |
| 89 | // SS = Seco nd, | |
| 90 | // FFFFFF = millisecon ds | |
| 91 | // ZZZZ - ti mezone off set | |
| 92 | pr ivate fina l static S tring dico mDateForma t = "yyyyM MddHHmmss. SSSSzzzzz" ; | |
| 93 | // do not re -use a sim ple date f ormat inst ance, they are not t hread safe | |
| 94 | pu blic final static Da teFormat g etDicomDat eFormat() | |
| 95 | { | |
| 96 | retu rn new Sim pleDateFor mat(dicomD ateFormat) ; | |
| 97 | } | |
| 98 | ||
| 99 | pr ivate fina l static S tring requ estDateFor mat = "MM/ dd/yyyy"; | |
| 100 | pu blic final static Da teFormat g etRequestD ateFormat( ) | |
| 101 | { | |
| 102 | retu rn new Sim pleDateFor mat(reques tDateForma t); | |
| 103 | } | |
| 104 | ||
| 105 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 106 | // | |
| 107 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 108 | pr otected St ring respo nseContent Type=""; | |
| 109 | pr otected St ring respo nseEncodin g=""; | |
| 110 | pr otected St ring respo nseMessage =""; | |
| 111 | pr otected St ring respo nseChecksu m=null; | |
| 112 | pr otected St ring image Checksum=n ull; | |
| 113 | pr otected St ring txtCh ecksum = n ull; | |
| 114 | pr otected Im ageQuality requested Quality = null; | |
| 115 | pr otected bo olean requ estGzip = false; | |
| 116 | pr otected in t fileLeng th = 0; | |
| 117 | pr otected in t txtLengt h = 0; | |
| 118 | ||
| 119 | pr otected fi nal ProxyS ervices pr oxyService s; | |
| 120 | pr ivate fina l boolean instanceUr lEscaped; | |
| 121 | ||
| 122 | pr otected Im agingProxy (ProxyServ ices proxy Service, b oolean ins tanceUrlEs caped) | |
| 123 | { | |
| 124 | asse rt proxySe rvice != n ull; | |
| 125 | this .proxyServ ices = pro xyService; | |
| 126 | this .instanceU rlEscaped = instance UrlEscaped ; | |
| 127 | } | |
| 128 | ||
| 129 | /* * | |
| 130 | * Returns t he ProxySe rvice for the ProxyS erviceType .image, if none is f ound | |
| 131 | * then the exception is caught and null i s returned . | |
| 132 | * / | |
| 133 | pu blic Proxy Service ge tImageProx yService() | |
| 134 | { | |
| 135 | try | |
| 136 | { | |
| 137 | return proxyServ ices.getPr oxyService (ProxyServ iceType.im age); | |
| 138 | } | |
| 139 | catc h(ProxySer viceNotFou ndExceptio n psnfX) | |
| 140 | { | |
| 141 | return null; | |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | /* * | |
| 146 | * Returns t he ProxySe rvice for the ProxyS erviceType .metadata, if none i s found | |
| 147 | * then the exception is caught and null i s returned . | |
| 148 | * / | |
| 149 | pu blic Proxy Service ge tMetadataP roxyServic e() | |
| 150 | { | |
| 151 | try | |
| 152 | { | |
| 153 | return proxyServ ices.getPr oxyService (ProxyServ iceType.me tadata); | |
| 154 | } | |
| 155 | catc h(ProxySer viceNotFou ndExceptio n psnfX) | |
| 156 | { | |
| 157 | return null; | |
| 158 | } | |
| 159 | } | |
| 160 | ||
| 161 | pu blic Strin g getRespo nseContent Type() | |
| 162 | { | |
| 163 | retu rn this.re sponseCont entType; | |
| 164 | } | |
| 165 | ||
| 166 | pu blic Strin g getRespo nseMessage () | |
| 167 | { | |
| 168 | retu rn this.re sponseMess age; | |
| 169 | } | |
| 170 | ||
| 171 | pu blic Strin g getRespo nseChecksu m() | |
| 172 | { | |
| 173 | retu rn this.re sponseChec ksum; | |
| 174 | } | |
| 175 | ||
| 176 | pu blic Image Quality ge tRequested Quality() { | |
| 177 | retu rn request edQuality; | |
| 178 | } | |
| 179 | ||
| 180 | pu blic Check sumValue g etResponse ChecksumVa lue() | |
| 181 | { | |
| 182 | try | |
| 183 | { | |
| 184 | return getRespon seChecksum () == null ? | |
| 185 | null : new ChecksumV alue(getRe sponseChec ksum()); | |
| 186 | } | |
| 187 | catc h (Checksu mFormatExc eption x) | |
| 188 | { | |
| 189 | logger .warn("Err or parsing checksum '" + getRe sponseChec ksum() + " '.", x); | |
| 190 | return null; | |
| 191 | } | |
| 192 | } | |
| 193 | ||
| 194 | pu blic Strin g getImage Checksum() { | |
| 195 | retu rn imageCh ecksum; | |
| 196 | } | |
| 197 | ||
| 198 | pu blic Strin g getTxtCh ecksum() { | |
| 199 | retu rn txtChec ksum; | |
| 200 | } | |
| 201 | ||
| 202 | /* * | |
| 203 | * @return t he fileLen gth | |
| 204 | * / | |
| 205 | pu blic int g etFileLeng th() { | |
| 206 | retu rn fileLen gth; | |
| 207 | } | |
| 208 | ||
| 209 | /* * | |
| 210 | * @return t he txtLeng th | |
| 211 | * / | |
| 212 | pu blic int g etTxtLengt h() { | |
| 213 | retu rn txtLeng th; | |
| 214 | } | |
| 215 | ||
| 216 | /* * | |
| 217 | * Set or ge t whether the reques t should s et the acc ept-conten t to | |
| 218 | * include g zip or not . | |
| 219 | * | |
| 220 | * @return | |
| 221 | * / | |
| 222 | pu blic boole an isReque stGzip() | |
| 223 | { | |
| 224 | re turn reque stGzip; | |
| 225 | } | |
| 226 | ||
| 227 | pu blic void setRequest Gzip(boole an request Gzip) | |
| 228 | { | |
| 229 | th is.request Gzip = req uestGzip; | |
| 230 | } | |
| 231 | ||
| 232 | /* * | |
| 233 | * Create a URL string for an im age specif ic to this proxy. | |
| 234 | * | |
| 235 | * @param im ageUrn | |
| 236 | * @return | |
| 237 | * / | |
| 238 | pu blic Strin g createIm ageUrl(Str ing imageU rn, ImageF ormatQuali tyList req uestFormat QualityLis t) | |
| 239 | th rows Proxy ServiceNot FoundExcep tion | |
| 240 | { | |
| 241 | retu rn Utiliti es.createI mageUrl(th is.proxySe rvices, im ageUrn, | |
| 242 | requestF ormatQuali tyList, ge tInstanceR equestProx yServiceTy pe()); | |
| 243 | } | |
| 244 | ||
| 245 | pu blic Strin g createTx tUrl(Strin g imageUrn , String a ccept) | |
| 246 | th rows Proxy ServiceNot FoundExcep tion | |
| 247 | { | |
| 248 | retu rn Utiliti es.createT xtUrl(this .proxyServ ices, imag eUrn, acce pt, | |
| 249 | getTextF ileRequest ProxyServi ceType()); | |
| 250 | } | |
| 251 | ||
| 252 | /* * | |
| 253 | * | |
| 254 | * @param im ageUrn | |
| 255 | * @param im ageQuality | |
| 256 | * @param ac cept | |
| 257 | * @return | |
| 258 | * @throws P roxyExcept ion | |
| 259 | * / | |
| 260 | pu blic Sized InputStrea m getInsta nce(String imageUrn, ImageForm atQualityL ist reques tFormatQua lityList, boolean in cludeVista SecurityCo ntext) | |
| 261 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, | |
| 262 | Se curityCred entialsExp iredExcept ion, Image Conversion Exception, MethodExc eption, Co nnectionEx ception | |
| 263 | { | |
| 264 | retu rn getInst ance(image Urn, reque stFormatQu alityList, null, inc ludeVistaS ecurityCon text); | |
| 265 | } | |
| 266 | ||
| 267 | /* * | |
| 268 | * Make an H TTP reques t to get t he image n amed by th e given UR N. | |
| 269 | * The check sum will c ontain the calculate d checksum only afte r | |
| 270 | * the entir e stream c ontents ha ve been re ad. | |
| 271 | * | |
| 272 | * @param im ageUrn | |
| 273 | * @param im ageQuality | |
| 274 | * @param im ageFormat | |
| 275 | * @param ch ecksum | |
| 276 | * @return a n InputStr eam contai ning the c ontents of the image . | |
| 277 | * If the ch ecksum par ameter is not null t hen the In putStream will be of type | |
| 278 | * java.util .zip.Check edInputStr eam. | |
| 279 | * / | |
| 280 | pu blic Sized InputStrea m getInsta nce(String imageUrn, ImageForm atQualityL ist reques tFormatQua lityList, | |
| 281 | Checks um checksu m, boolean includeVi staSecurit yContext) | |
| 282 | th rows Image NearLineEx ception, I mageNotFou ndExceptio n, | |
| 283 | Se curityCred entialsExp iredExcept ion, Image Conversion Exception, MethodExc eption, Co nnectionEx ception | |
| 284 | { | |
| 285 | Stri ng imageUr lString = null; | |
| 286 | Imag eFormat fi rstImageFo rmat = req uestFormat QualityLis t.get(0).g etImageFor mat(); | |
| 287 | this .requested Quality = requestFor matQuality List.get(0 ).getImage Quality(); | |
| 288 | try | |
| 289 | { | |
| 290 | if(fir stImageFor mat == Ima geFormat.T EXT_DICOM) | |
| 291 | { | |
| 292 | imageUrl String = c reateTxtUr l(imageUrn , firstIma geFormat.g etMime()); | |
| 293 | } | |
| 294 | else | |
| 295 | { | |
| 296 | imageUrl String = c reateImage Url(imageU rn, reques tFormatQua lityList); | |
| 297 | } | |
| 298 | } | |
| 299 | catc h(ProxySer viceNotFou ndExceptio n psnfX) | |
| 300 | { | |
| 301 | logger .error("Er ror findin g proxy se rvice", ps nfX); | |
| 302 | throw new Connec tionExcept ion(psnfX. getMessage ()); | |
| 303 | } | |
| 304 | Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get(); | |
| 305 | Stri ng transac tionIdenti fier = tra nsactionCo ntext.getT ransaction Id(); | |
| 306 | logg er.info("T ransaction [" + tran sactionIde ntifier + "] initiat ed, retrei ving [" + imageUrlSt ring + "]" ); | |
| 307 | tran sactionCon text.addDe bugInforma tion("getI nstance to URL '" + imageUrlSt ring + "'. "); | |
| 308 | ||
| 309 | int result = 0 ; | |
| 310 | Http Client cli ent = null ; | |
| 311 | GetM ethod getM ethod = nu ll; | |
| 312 | ||
| 313 | try | |
| 314 | { | |
| 315 | client = new Htt pClient(); | |
| 316 | client .getHttpCo nnectionMa nager().ge tParams(). setConnect ionTimeout (30000); / / DKB - 30 sec to ge t a connec tion | |
| 317 | client.g etHttpConn ectionMana ger().getP arams().se tSoTimeout (120000); // 120 sec to wait f or data | |
| 318 | client .getParams ().setAuth entication Preemptive (true); | |
| 319 | //getM ethod = ne w GetMetho d(imageUrl String); | |
| 320 | getMet hod = new GetMethod( ); | |
| 321 | getMet hod.setURI (new URI(i mageUrlStr ing, insta nceUrlEsca ped)); | |
| 322 | ||
| 323 | Header acceptHea der = new Header("Ac cept", req uestFormat QualityLis t.getAccep tString(fa lse)); | |
| 324 | getMet hod.setReq uestHeader (acceptHea der); | |
| 325 | ||
| 326 | Header acceptLan guageHeade r = new He ader("Acce pt-Languag e", "en-us ,en"); | |
| 327 | getMet hod.setReq uestHeader (acceptLan guageHeade r); | |
| 328 | ||
| 329 | Header acceptCha rsetHeader = new Hea der("Accep t-Charset" , "ISO-885 9-1,utf-8" ); | |
| 330 | getMet hod.setReq uestHeader (acceptCha rsetHeader ); | |
| 331 | ||
| 332 | // ++ CTB 14MAy2 008 | |
| 333 | if(isR equestGzip ()) | |
| 334 | { | |
| 335 | Header e ncodingHea der = new Header("Ac cept-Encod ing", "gzi p"); | |
| 336 | getMetho d.setReque stHeader(e ncodingHea der); | |
| 337 | } | |
| 338 | ||
| 339 | getMet hod.setFol lowRedirec ts(true); | |
| 340 | ||
| 341 | getMet hod.setReq uestHeader ( HTTPCons tants.HEAD ER_CACHE_C ONTROL, "n o-cache,no -store,no- transform" ); | |
| 342 | getMet hod.setReq uestHeader ( HTTPCons tants.HEAD ER_PRAGMA, "no-cache "); | |
| 343 | ||
| 344 | // add the secur ity inform ation to t he http he aders | |
| 345 | addSec urityConte xtToHeader (client, g etMethod, includeVis taSecurity Context); | |
| 346 | ||
| 347 | addOpt ionalGetIn stanceHead ers(getMet hod); | |
| 348 | ||
| 349 | result = client. executeMet hod(getMet hod); | |
| 350 | ||
| 351 | // How m any bytes received? | |
| 352 | transact ionContext .setDataSo urceBytesR eceived (g etMethod.g etBytesRec eived ()); | |
| 353 | ||
| 354 | // How long did it take to get a res ponse comi ng back? | |
| 355 | Long t imeSent = getMethod. getTimeReq uestSent ( ); | |
| 356 | Long t imeReceive d = getMet hod.getTim eFirstByte Received ( ); | |
| 357 | if (ti meSent != null && ti meReceived != null) | |
| 358 | { | |
| 359 | lon g timeTook = timeRec eived.long Value () - timeSent. longValue (); | |
| 360 | tra nsactionCo ntext.setT imeToFirst Byte (new Long (time Took)); | |
| 361 | } | |
| 362 | ||
| 363 | Header contentTy peHeader=g etMethod.g etResponse Header("Co ntent-Type "); | |
| 364 | if (co ntentTypeH eader != n ull) | |
| 365 | response ContentTyp e = conten tTypeHeade r.getValue (); // def ault is em pty string | |
| 366 | ||
| 367 | // ++ CTB 14MAy2 008 | |
| 368 | Header encodingT ypeHeader= getMethod. getRespons eHeader("C ontent-Enc oding"); | |
| 369 | if (en codingType Header != null) | |
| 370 | response Encoding = encodingT ypeHeader. getValue() ; // defau lt is empt y string | |
| 371 | ||
| 372 | Header checksumH eader=getM ethod.getR esponseHea der(Transa ctionConte xtHttpHead ers.httpHe aderChecks um); | |
| 373 | if (ch ecksumHead er != null ) | |
| 374 | response Checksum = checksumH eader.getV alue(); // default i s empty st ring | |
| 375 | else | |
| 376 | response Checksum = null; | |
| 377 | ||
| 378 | // get the check sums for a zip file (only used in Federa tion) | |
| 379 | Header imageChec ksumHeader = getMeth od.getResp onseHeader (Transacti onContextH ttpHeaders .httpHeade rImageChec ksum); | |
| 380 | if(ima geChecksum Header != null) | |
| 381 | imageChe cksum = im ageChecksu mHeader.ge tValue(); | |
| 382 | else | |
| 383 | imageChe cksum = nu ll; | |
| 384 | ||
| 385 | Header txtChecks umHeader = getMethod .getRespon seHeader(T ransaction ContextHtt pHeaders.h ttpHeaderT XTChecksum ); | |
| 386 | if(txt ChecksumHe ader != nu ll) | |
| 387 | txtCheck sum = txtC hecksumHea der.getVal ue(); | |
| 388 | else | |
| 389 | txtCheck sum = null ; | |
| 390 | ||
| 391 | Header imgFileLe ngthHeader = getMeth od.getResp onseHeader (Transacti onContextH ttpHeaders .httpHeade rImageSize ); | |
| 392 | if(img FileLength Header != null) | |
| 393 | { | |
| 394 | try | |
| 395 | { | |
| 396 | fileLength = Integer .parseInt( imgFileLen gthHeader. getValue() ); | |
| 397 | } | |
| 398 | catch(Nu mberFormat Exception nfX) | |
| 399 | { | |
| 400 | logger.deb ug("Error parsing im age length header va lue [" + i mgFileLeng thHeader.g etValue() + "].", nf X); | |
| 401 | } | |
| 402 | } | |
| 403 | else | |
| 404 | fileLeng th = 0; | |
| 405 | ||
| 406 | Header txtFileLe ngthHeader = getMeth od.getResp onseHeader (Transacti onContextH ttpHeaders .httpHeade rTxtSize); | |
| 407 | if(txt FileLength Header != null) | |
| 408 | { | |
| 409 | try | |
| 410 | { | |
| 411 | txtLength = Integer. parseInt(t xtFileLeng thHeader.g etValue()) ; | |
| 412 | } | |
| 413 | catch(Nu mberFormat Exception nfX) | |
| 414 | { | |
| 415 | logger.deb ug("Error parsing TX T file len gth header value [" + imgFileL engthHeade r.getValue () + "].", nfX); | |
| 416 | } | |
| 417 | } | |
| 418 | else | |
| 419 | txtLengt h = 0; | |
| 420 | ||
| 421 | Header responseQ ualityHead er = getMe thod.getRe sponseHead er(Transac tionContex tHttpHeade rs.httpHea derImageQu ality); | |
| 422 | if(res ponseQuali tyHeader ! = null) | |
| 423 | { | |
| 424 | try | |
| 425 | { | |
| 426 | requestedQ uality = I mageQualit y.getImage Quality(re sponseQual ityHeader. getValue() ); | |
| 427 | } | |
| 428 | catch(Nu mberFormat Exception nfX) | |
| 429 | { | |
| 430 | logger.deb ug("Error parsing qu ality head er value [ " + respon seQualityH eader.getV alue() + " ].", nfX); | |
| 431 | } | |
| 432 | } | |
| 433 | Header responseM achineName Header = | |
| 434 | getMetho d.getRespo nseHeader( Transactio nContextHt tpHeaders. httpHeader MachineNam e); | |
| 435 | if(res ponseMachi neNameHead er != null ) | |
| 436 | { | |
| 437 | String m achineName = respons eMachineNa meHeader.g etValue(); | |
| 438 | logger.i nfo("Recei ved respon se from ma chine name '" + mach ineName + "'."); | |
| 439 | transact ionContext .setDataSo urceRespon seServer(m achineName ); | |
| 440 | } | |
| 441 | } | |
| 442 | catc h (HttpExc eption e) | |
| 443 | { | |
| 444 | e.prin tStackTrac e(); | |
| 445 | respon seMessage = "HTTPExc eption on execute GE T method, got respon se code '" + result + "', " + e.getMessa ge(); | |
| 446 | throw new Connec tionExcept ion(respon seMessage, e); | |
| 447 | } | |
| 448 | catc h (IOExcep tion e) | |
| 449 | { | |
| 450 | e.prin tStackTrac e(); | |
| 451 | respon seMessage = "IOExcep tion on ex ecute GET method, go t response code '" + result + "', " + e. getMessage (); | |
| 452 | throw new Connec tionExcept ion(respon seMessage, e); | |
| 453 | } | |
| 454 | ||
| 455 | // 1 00 series codes shou ld have be en dealt w ith by the underlyin g HTTP pro xy. | |
| 456 | // I f not then we have n o choice b ut to pass the error message o n up and l et the cli ent | |
| 457 | // d ecide if t hey can re -try. | |
| 458 | if ( result >= HttpStatus .SC_CONTIN UE && resu lt < HttpS tatus.SC_O K) | |
| 459 | { | |
| 460 | String message = readRespo nseMessage Body(respo nseContent Type, getM ethod); | |
| 461 | if(mes sage == nu ll) | |
| 462 | message = "Server response w as '" + re sult + "', responses other tha n 200 (OK) are consi dered erro rs."; | |
| 463 | ||
| 464 | logger .warn("Tra nsaction [ " + transa ctionIdent ifier + "] response code = '" + result + "' messag e is '" + message + "'"); | |
| 465 | throw new Connec tionExcept ion(messag e); | |
| 466 | } | |
| 467 | ||
| 468 | else if(result == HttpSt atus.SC_OK ) | |
| 469 | { | |
| 470 | try | |
| 471 | { | |
| 472 | int byte sRead = 0; | |
| 473 | InputStr eam input = null; | |
| 474 | ||
| 475 | try | |
| 476 | { | |
| 477 | Header con tentLength Header = g etMethod.g etResponse Header("co ntent-leng th"); | |
| 478 | if (conten tLengthHea der!=null) | |
| 479 | { | |
| 480 | St ring heade rLengthVal ue = conte ntLengthHe ader.getVa lue(); | |
| 481 | by tesRead = Integer.pa rseInt(hea derLengthV alue); | |
| 482 | } | |
| 483 | } | |
| 484 | catch (E xception e ) | |
| 485 | { | |
| 486 | responseMe ssage = "E xception o n get resp onse heade r/value"; | |
| 487 | logger.err or(e); | |
| 488 | } | |
| 489 | ||
| 490 | logger.i nfo("Trans action [" + transact ionIdentif ier + "] r eturned SU CCESS. Con tent Lengt h [" + byt esRead + " ]"); | |
| 491 | InputStr eam inStre am = getMe thod.getRe sponseBody AsStream() ; | |
| 492 | ||
| 493 | // ++ CT B 14MAy200 8 | |
| 494 | // if th e response body is g zip encode d then cre ate a GZIP decoding input stre am and | |
| 495 | // retur n that | |
| 496 | if(respo nseEncodin g.indexOf( "gzip") >= 0) | |
| 497 | { | |
| 498 | GZIPInputS tream zipI n = new GZ IPInputStr eam(inStre am); | |
| 499 | inStream = zipIn; | |
| 500 | } | |
| 501 | ||
| 502 | // if a checksum i nstance wa s provided , attach i t to a Che ckedInputS tream inst ance | |
| 503 | // and r eturn it, else retur n the raw stream | |
| 504 | if(check sum != nul l) | |
| 505 | { | |
| 506 | input = ne w CheckedI nputStream (inStream, checksum) ; | |
| 507 | } | |
| 508 | else | |
| 509 | input = in Stream; | |
| 510 | //return i nStream; | |
| 511 | return n ew SizedIn putStream( input, byt esRead); | |
| 512 | } | |
| 513 | catch (IOExcepti on e) | |
| 514 | { | |
| 515 | logger.e rror(e); | |
| 516 | } | |
| 517 | } | |
| 518 | // 2 00 series error code s that are not expli citly an O K | |
| 519 | // s ome of the se can be lived with , some not . For now we call t hem all er rors. | |
| 520 | else if (resul t > HttpSt atus.SC_OK && resul t < HttpSt atus.SC_MU LTIPLE_CHO ICES) | |
| 521 | { | |
| 522 | String message = readRespo nseMessage Body(respo nseContent Type, getM ethod); | |
| 523 | if(mes sage == nu ll) | |
| 524 | message = "Server response w as '" + re sult + "', responses other tha n 200 (OK) are consi dered erro rs."; | |
| 525 | ||
| 526 | logger .warn("Tra nsaction [ " + transa ctionIdent ifier + "] response code = '" + result + "' messag e is '" + message + "'"); | |
| 527 | throw new Connec tionExcept ion(messag e); | |
| 528 | } | |
| 529 | ||
| 530 | // 3 00 series error code s | |
| 531 | // r esult is p robably a client err or, report it, the u ser may be able to m odify the request an d re-submi t | |
| 532 | else if (resul t >= HttpS tatus.SC_M ULTIPLE_CH OICES && result < H ttpStatus. SC_BAD_REQ UEST) | |
| 533 | { | |
| 534 | String message = readRespo nseMessage Body(respo nseContent Type, getM ethod); | |
| 535 | if(mes sage == nu ll) | |
| 536 | message = "Server response w as '" + re sult + "', responses other tha n 200 (OK) are consi dered erro rs."; | |
| 537 | ||
| 538 | logger .warn("Tra nsaction [ " + transa ctionIdent ifier + "] response code = '" + result + "' messag e is '" + message + "'"); | |
| 539 | throw new Connec tionExcept ion(messag e); | |
| 540 | } | |
| 541 | ||
| 542 | // 4 00 series error code s | |
| 543 | // r esult is a client er ror, repor t it, the user may b e able to modify the request a nd re-subm it | |
| 544 | else if (resul t >= HttpS tatus.SC_B AD_REQUEST && resul t < HttpSt atus.SC_IN TERNAL_SER VER_ERROR) | |
| 545 | { | |
| 546 | String message = "Server r esponse wa s '" + res ult + "', responses other than 200 (OK) are consid ered error s."; | |
| 547 | if("te xt/html".e quals(resp onseConten tType)) | |
| 548 | message = readHTTP Message(cl ient, getM ethod); | |
| 549 | else i f (("appli cation/dic om".equals (responseC ontentType )) || | |
| 550 | ("image/jp eg/dicom". equals(res ponseConte ntType))) | |
| 551 | message += readHTT PMessage(c lient, get Method); | |
| 552 | logger .warn("Tra nsaction [ " + transa ctionIdent ifier + "] response code = '" + result + "' messag e is '" + message + "'"); | |
| 553 | ||
| 554 | // 409 result | |
| 555 | if(res ult == Htt pStatus.SC _CONFLICT) | |
| 556 | { | |
| 557 | throw ne w ImageNea rLineExcep tion(image Urn); | |
| 558 | } | |
| 559 | // The Exchange interface does not r espond wit h a 404 fo r file not founds bu t Federati on does | |
| 560 | else i f(result = = HttpStat us.SC_NOT_ FOUND) | |
| 561 | { | |
| 562 | throw ne w ImageNot FoundExcep tion(messa ge); | |
| 563 | } | |
| 564 | else i f(result = = HttpStat us.SC_PREC ONDITION_F AILED) | |
| 565 | { | |
| 566 | throw ne w Security Credential sExpiredEx ception(me ssage); | |
| 567 | } | |
| 568 | else i f(result = = HttpStat us.SC_UNSU PPORTED_ME DIA_TYPE) | |
| 569 | { | |
| 570 | throw ne w ImageCon versionExc eption(mes sage); | |
| 571 | } | |
| 572 | ||
| 573 | ||
| 574 | throw new Connec tionExcept ion(messag e); | |
| 575 | } | |
| 576 | ||
| 577 | // 5 00 series error code s | |
| 578 | // r esult is a server er ror, repor t it but n ot much we can do to correct i t | |
| 579 | else if (resul t >= HttpS tatus.SC_I NTERNAL_SE RVER_ERROR ) | |
| 580 | { | |
| 581 | String message = "Server r esponse wa s '" + res ult + "', responses other than 200 (OK) are consid ered error s."; | |
| 582 | if("te xt/html".e quals(resp onseConten tType)) | |
| 583 | message += readHTT PMessage(c lient, get Method); | |
| 584 | ||
| 585 | if(res ult == Htt pStatus.SC _BAD_GATEW AY) | |
| 586 | { | |
| 587 | logger.e rror("Conn ectionExce ption tran saction [" + transac tionIdenti fier + "], response code = '" + result + "' messag e is '" + message + "'"); | |
| 588 | throw ne w Connecti onExceptio n(message) ; | |
| 589 | } | |
| 590 | else | |
| 591 | { | |
| 592 | logger.e rror("Meth odExceptio n transact ion [" + t ransaction Identifier + "], res ponse code = '" + re sult + "' message is '" + mess age + "'") ; | |
| 593 | throw ne w MethodEx ception(me ssage); | |
| 594 | } | |
| 595 | } | |
| 596 | ||
| 597 | retu rn null; | |
| 598 | } | |
| 599 | ||
| 600 | /* * | |
| 601 | * Function adds optio nal header s to the r equest. Th is functio n should b e overridd en by othe r classes to add the se | |
| 602 | * optional headers | |
| 603 | * @param ge tMethod | |
| 604 | * / | |
| 605 | pr otected ab stract voi d addOptio nalGetInst anceHeader s(GetMetho d getMetho d); | |
| 606 | ||
| 607 | /* * | |
| 608 | * Returns t he ProxySe rviceType to use whe n doing a getInstanc e request | |
| 609 | * @return | |
| 610 | * / | |
| 611 | pr otected ab stract Pro xyServiceT ype getIns tanceReque stProxySer viceType() ; | |
| 612 | ||
| 613 | /* * | |
| 614 | * Returns t he ProxySe rviceType used when doing a ge tInstance for a text file requ est. | |
| 615 | * @return | |
| 616 | * / | |
| 617 | pr otected ab stract Pro xyServiceT ype getTex tFileReque stProxySer viceType() ; | |
| 618 | ||
| 619 | /* * | |
| 620 | * @param cl ient | |
| 621 | * @param ge tMethod | |
| 622 | * @return | |
| 623 | * / | |
| 624 | pr otected St ring readR esponseMes sageBody(S tring cont entType, G etMethod g etMethod) | |
| 625 | { | |
| 626 | if(c ontentType != null & & contentT ype.toLowe rCase().st artsWith(" text")) | |
| 627 | { | |
| 628 | try | |
| 629 | { | |
| 630 | return g etMethod.g etResponse BodyAsStri ng(); | |
| 631 | } | |
| 632 | catch (IOExcepti on x) | |
| 633 | { | |
| 634 | logger.e rror(x); | |
| 635 | } | |
| 636 | } | |
| 637 | ||
| 638 | retu rn null; | |
| 639 | } | |
| 640 | ||
| 641 | /* * | |
| 642 | * @param cl ient | |
| 643 | * @param ge tMethod | |
| 644 | * @return | |
| 645 | * / | |
| 646 | pr otected St ring readH TTPMessage (HttpClien t client, GetMethod getMethod) | |
| 647 | { | |
| 648 | String response = " " + ge tMethod.ge tStatusTex t(); | |
| 649 | return response; | |
| 650 | } | |
| 651 | ||
| 652 | /* * | |
| 653 | * Adds the user ID an d password to the HT TP headers using BAS IC securit y. | |
| 654 | * Adds the parameter of the thr ead local security c ontext to the HTTP h eader. | |
| 655 | * | |
| 656 | * @param ge tMethod | |
| 657 | * / | |
| 658 | pr otected vo id addSecu rityContex tToHeader( HttpClient client, G etMethod g etMethod, | |
| 659 | boolea n includeV istaSecuri tyContext) | |
| 660 | { | |
| 661 | // B TW, don't import the Credentia ls class b ecause the re is an a pp specifi c Credenti als | |
| 662 | // t hat derive s from the java Prin cipal clas s, which i s where th e thread l ocal | |
| 663 | // s ecutity co ntext is s tored | |
| 664 | org. apache.com mons.httpc lient.Cred entials im ageXChange Credential s = null; | |
| 665 | ||
| 666 | try | |
| 667 | { | |
| 668 | ProxyS ervice ima geService = proxySer vices.getP roxyServic e(ProxySer viceType.i mage); | |
| 669 | ||
| 670 | if(ima geService. getCredent ials() ins tanceof St ring) | |
| 671 | imageXCh angeCreden tials = | |
| 672 | new Userna mePassword Credential s(imageSer vice.getUi d(), (Stri ng)(imageS ervice.get Credential s()) ); | |
| 673 | ||
| 674 | AuthSc ope imageX ChangeAuth Scope = ne w AuthScop e(imageSer vice.getHo st(), imag eService.g etPort(), AuthScope. ANY_REALM) ; | |
| 675 | client .getState( ).setCrede ntials(ima geXChangeA uthScope, imageXChan geCredenti als); | |
| 676 | } | |
| 677 | catc h(ProxySer viceNotFou ndExceptio n psnfX) | |
| 678 | { | |
| 679 | logger .warn("Can not find i mage proxy service t o set cred entials, c ontinuing without", psnfX); | |
| 680 | } | |
| 681 | //He ader autho rizationHe ader = new Header("A uthorizati on", "Basi c "); | |
| 682 | //ge tMethod.se tRequestHe ader(autho rizationHe ader); | |
| 683 | ||
| 684 | // t he thread local secu rity crede ntials (th e VistA sp ecific stu ff) is wri tten into | |
| 685 | // a pp specifi c HTTP hea ders | |
| 686 | Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get(); | |
| 687 | ||
| 688 | // 3 -11-2008 D KB - modif ied to sen d all head ers except the DUZ i f includeV istaSecuri tyContext is false | |
| 689 | // t he silver BIA was th rowing an error beca use we wer e not send ing httpHe aderFullNa me, httpHe aderSiteNa me, | |
| 690 | // h ttpHeaderS iteNumber and httpHe aderSSN | |
| 691 | if(i ncludeVist aSecurityC ontext) | |
| 692 | { | |
| 693 | if(tra nsactionCo ntext.getD uz() != nu ll) | |
| 694 | getMetho d.setReque stHeader(n ew Header( Transactio nContextHt tpHeaders. httpHeader Duz, | |
| 695 | tr ansactionC ontext.get Duz())); | |
| 696 | logger .debug("Se tting DUZ in Request Header: " +transacti onContext. getDuz()); | |
| 697 | String securityT oken = tra nsactionCo ntext.getB rokerSecur ityToken() ; | |
| 698 | if(s ecurityTok en != null && securi tyToken.le ngth() > 0 ) | |
| 699 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erBrokerSe curityToke nId, | |
| 700 | securityTo ken)); | |
| 701 | logg er.debug(" Setting Se curity Tok en in Requ est Header : "+securi tyToken); | |
| 702 | Stri ng cacheLo cationId = transacti onContext. getCacheLo cationId() ; | |
| 703 | if(c acheLocati onId != nu ll && cach eLocationI d.length() > 0) | |
| 704 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erCacheLoc ationId, | |
| 705 | cacheLocat ionId)); | |
| 706 | ||
| 707 | Stri ng userDiv ision = tr ansactionC ontext.get UserDivisi on(); | |
| 708 | if(u serDivisio n != null && userDiv ision.leng th() > 0) | |
| 709 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erUserDivi sion, | |
| 710 | userDivisi on)); | |
| 711 | ||
| 712 | } | |
| 713 | if(t ransaction Context.ge tFullName( ) != null) | |
| 714 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erFullName , | |
| 715 | transactio nContext.g etFullName ())); | |
| 716 | if(t ransaction Context.ge tSiteName( ) != null) | |
| 717 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erSiteName , | |
| 718 | transactio nContext.g etSiteName ())); | |
| 719 | if(t ransaction Context.ge tSiteNumbe r() != nul l) | |
| 720 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erSiteNumb er, | |
| 721 | transactio nContext.g etSiteNumb er())); | |
| 722 | lo gger.debug ("Setting Site Numbe r in Reque st Header: "+transac tionContex t.getSiteN umber()); | |
| 723 | if(t ransaction Context.ge tSsn() != null) | |
| 724 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erSSN, | |
| 725 | transactio nContext.g etSsn())); | |
| 726 | logg er.debug(" Setting SS N in Reque st Header. "); | |
| 727 | ||
| 728 | if(t ransaction Context.ge tTransacti onId() != null) | |
| 729 | getMet hod.setReq uestHeader (new Heade r(Transact ionContext HttpHeader s.httpHead erTransact ionId, | |
| 730 | transactio nContext.g etTransact ionId())); | |
| 731 | // 1 /8/07 JMW - Add the purpose of use to th e request for images | |
| 732 | getM ethod.setR equestHead er(new Hea der(Transa ctionConte xtHttpHead ers.httpHe aderPurpos eOfUse, | |
| 733 | Requesto r.PurposeO fUse.routi neMedicalC are.getDes cription() )); | |
| 734 | } | |
| 735 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.