Produced by Araxis Merge on 6/9/2017 3:51:24 PM Eastern 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 | Fri Jun 9 19:51:24 2017 UTC | ||
| 2 | eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-web\src\main\java\gov\va\nvap\web\app | ResponseDispatcherHttpServlet.java | Fri Apr 21 20:03:30 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 1 | 388 |
| 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.nvap. web.app; | |||||
| 2 | ||||||
| 3 | import gov .va.nvap.c ommon.exce ption.Stac kTraceUtil ; | |||||
| 4 | import gov .va.nvap.c ommon.vali dation.Nul lChecker; | |||||
| 5 | import gov .va.nvap.w eb.helper. document.D ocumentHel per; | |||||
| 6 | import gov .va.nvap.w eb.helper. document.M ediaType; | |||||
| 7 | ||||||
| 8 | import jav a.io.IOExc eption; | |||||
| 9 | import jav a.io.Input Stream; | |||||
| 10 | import jav a.lang.ref lect.Invoc ationTarge tException ; | |||||
| 11 | import jav a.lang.ref lect.Metho d; | |||||
| 12 | import jav a.util.Arr ayList; | |||||
| 13 | import jav a.util.Arr ays; | |||||
| 14 | import jav a.util.Enu meration; | |||||
| 15 | import jav a.util.Has hMap; | |||||
| 16 | import jav a.util.Ite rator; | |||||
| 17 | import jav a.util.Lis t; | |||||
| 18 | import jav a.util.Map ; | |||||
| 19 | import jav a.util.UUI D; | |||||
| 20 | ||||||
| 21 | import jav ax.servlet .ServletEx ception; | |||||
| 22 | import jav ax.servlet .http.Http Servlet; | |||||
| 23 | import jav ax.servlet .http.Http ServletReq uest; | |||||
| 24 | import jav ax.servlet .http.Http ServletRes ponse; | |||||
| 25 | import jav ax.servlet .http.Http Session; | |||||
| 26 | ||||||
| 27 | import org .apache.co mmons.file upload.Fil eItem; | |||||
| 28 | import org .apache.co mmons.file upload.Fil eUploadBas e.SizeLimi tExceededE xception; | |||||
| 29 | import org .apache.co mmons.file upload.Fil eUploadExc eption; | |||||
| 30 | import org .apache.co mmons.file upload.dis k.DiskFile ItemFactor y; | |||||
| 31 | import org .apache.co mmons.file upload.ser vlet.Servl etFileUplo ad; | |||||
| 32 | import org .apache.co mmons.logg ing.Log; | |||||
| 33 | import org .apache.co mmons.logg ing.LogFac tory; | |||||
| 34 | import org .apache.co mmons.vali dator.Vali dator; | |||||
| 35 | import org .apache.co mmons.vali dator.Vali datorExcep tion; | |||||
| 36 | import org .apache.co mmons.vali dator.Vali datorResou rces; | |||||
| 37 | import org .apache.co mmons.vali dator.Vali datorResul ts; | |||||
| 38 | import org .springfra mework.web .context.W ebApplicat ionContext ; | |||||
| 39 | import org .springfra mework.web .context.s upport.Web Applicatio nContextUt ils; | |||||
| 40 | import org .xml.sax.S AXExceptio n; | |||||
| 41 | ||||||
| 42 | /** | |||||
| 43 | * The abs tract resp onse dispa tcher serv let. It ca lls the ap propriate method by | |||||
| 44 | * using r eflection. | |||||
| 45 | * | |||||
| 46 | * @author Asha Amri traj | |||||
| 47 | */ | |||||
| 48 | abstract p ublic clas s Response Dispatcher HttpServle t extends HttpServle t { | |||||
| 49 | /* * | |||||
| 50 | * Logger. | |||||
| 51 | * / | |||||
| 52 | st atic priva te final L og LOG = L ogFactory | |||||
| 53 | .getLo g(Response Dispatcher HttpServle t.class); | |||||
| 54 | /* * | |||||
| 55 | * Serial UI D. | |||||
| 56 | * / | |||||
| 57 | pr ivate stat ic final l ong serial VersionUID = 8771859 2436536486 87L; | |||||
| 58 | /* * | |||||
| 59 | * The valid ation file for valid ating fiel ds. | |||||
| 60 | * / | |||||
| 61 | st atic priva te final S tring VALI DATION_FIL E_PATH = " WEB-INF/va lidation.x ml"; | |||||
| 62 | /* * | |||||
| 63 | * Generic v alidation based on v alidation. xml file. | |||||
| 64 | * / | |||||
| 65 | pr ivate Vali datorResou rces valid atorResour ces; | |||||
| 66 | /* * | |||||
| 67 | * The Sprin g web appl ication co ntext. | |||||
| 68 | * / | |||||
| 69 | pr otected We bApplicati onContext webApplica tionContex t; | |||||
| 70 | ||||||
| 71 | @O verride | |||||
| 72 | pr otected vo id doGet(f inal HttpS ervletRequ est reques t, | |||||
| 73 | final HttpServle tResponse response) throws Ser vletExcept ion, | |||||
| 74 | IOExce ption { | |||||
| 75 | try { | |||||
| 76 | this.p rocessRequ est(reques t, respons e); | |||||
| 77 | } ca tch (final Exception ex) { | |||||
| 78 | reques t.getSessi on(false). setAttribu te("except ion", ex); | |||||
| 79 | reques t.getSessi on(false). setAttribu te("except ionTrace", | |||||
| 80 | StackTrace Util.getSt ackTraceUt ilAsString (ex)); | |||||
| 81 | if (Ru ntimeExcep tion.class .isInstanc e(ex)) { | |||||
| 82 | throw (R untimeExce ption) ex; | |||||
| 83 | } else { | |||||
| 84 | throw ne w ServletE xception(e x); | |||||
| 85 | } | |||||
| 86 | } | |||||
| 87 | } | |||||
| 88 | ||||||
| 89 | @O verride | |||||
| 90 | pr otected vo id doPost( final Http ServletReq uest reque st, | |||||
| 91 | final HttpServle tResponse response) throws Ser vletExcept ion, | |||||
| 92 | IOExce ption { | |||||
| 93 | try { | |||||
| 94 | this.p rocessRequ est(reques t, respons e); | |||||
| 95 | } ca tch (final Exception ex) { | |||||
| 96 | reques t.getSessi on(false). setAttribu te("except ion", ex); | |||||
| 97 | reques t.getSessi on(false). setAttribu te("except ionTrace", | |||||
| 98 | StackTrace Util.getSt ackTraceUt ilAsString (ex)); | |||||
| 99 | if (Ru ntimeExcep tion.class .isInstanc e(ex)) { | |||||
| 100 | throw (R untimeExce ption) ex; | |||||
| 101 | } else { | |||||
| 102 | throw ne w ServletE xception(e x); | |||||
| 103 | } | |||||
| 104 | } | |||||
| 105 | } | |||||
| 106 | ||||||
| 107 | /* * | |||||
| 108 | * Call a me thod using reflectio n based on a paramet er name pa ssed in th e | |||||
| 109 | * URL. | |||||
| 110 | * / | |||||
| 111 | pr ivate bool ean execut eMethod(fi nal String parameter Name, | |||||
| 112 | final HttpServle tRequest r equest, fi nal HttpSe rvletRespo nse respon se) | |||||
| 113 | throws ServletEx ception { | |||||
| 114 | try { | |||||
| 115 | final Method met hod = this .getClass( ).getDecla redMethod( | |||||
| 116 | parameterN ame, HttpS ervletRequ est.class, | |||||
| 117 | HttpServle tResponse. class); | |||||
| 118 | method .invoke(th is, reques t, respons e); | |||||
| 119 | return true; | |||||
| 120 | } ca tch (final NoSuchMet hodExcepti on nsme) { | |||||
| 121 | return false; | |||||
| 122 | } ca tch (final Invocatio nTargetExc eption ex) { | |||||
| 123 | throw new Servle tException (ex.getTar getExcepti on()); | |||||
| 124 | } ca tch (final IllegalAc cessExcept ion ex) { | |||||
| 125 | throw new Servle tException (ex); | |||||
| 126 | } | |||||
| 127 | } | |||||
| 128 | ||||||
| 129 | /* * | |||||
| 130 | * Special p arameter n ame when u ploading f iles in ou r GUI. | |||||
| 131 | * / | |||||
| 132 | pr ivate bool ean execut eMethod(fi nal String parameter Name, | |||||
| 133 | final List<FileI tem> fileI tem, final HttpServl etRequest request, | |||||
| 134 | final HttpServle tResponse response) throws Ser vletExcept ion { | |||||
| 135 | try { | |||||
| 136 | final Method met hod = this .getClass( ).getDecla redMethod( | |||||
| 137 | parameterN ame, List. class, Htt pServletRe quest.clas s, | |||||
| 138 | HttpServle tResponse. class); | |||||
| 139 | method .invoke(th is, fileIt em, reques t, respons e); | |||||
| 140 | return true; | |||||
| 141 | } ca tch (final NoSuchMet hodExcepti on nsme) { | |||||
| 142 | return false; | |||||
| 143 | } ca tch (final Invocatio nTargetExc eption ex) { | |||||
| 144 | throw new Servle tException (ex.getTar getExcepti on()); | |||||
| 145 | } ca tch (final IllegalAc cessExcept ion ex) { | |||||
| 146 | throw new Servle tException (ex); | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | ||||||
| 150 | /* * | |||||
| 151 | * If the UR L starts w ith redire ct: then r edirect to a differe nt locatio n | |||||
| 152 | * with the same param eters. | |||||
| 153 | * / | |||||
| 154 | pr otected vo id forward (final Htt pServletRe quest requ est, | |||||
| 155 | final HttpServle tResponse response, final Stri ng actionN ame) | |||||
| 156 | throws IOExcepti on, Servle tException { | |||||
| 157 | Stri ng url = t his.getSer vletConfig ().getInit Parameter( actionName ); | |||||
| 158 | ||||||
| 159 | if ( !NullCheck er.isNullO rEmpty(url )) { | |||||
| 160 | if (ur l.startsWi th("redire ct:")) { | |||||
| 161 | url = ur l.substrin g(url.inde xOf(":") + 1); | |||||
| 162 | final St ring[] par ts = url.s plit(","); | |||||
| 163 | if (part s.length > 1) { | |||||
| 164 | request.se tAttribute ("action", parts[0]) ; | |||||
| 165 | request.se tAttribute ("actionPa rams", | |||||
| 166 | Arra ys.copyOfR ange(parts , 1, parts .length)); | |||||
| 167 | request.ge tRequestDi spatcher(" WEB-INF/we b/redirect .jsp") | |||||
| 168 | .for ward(reque st, respon se); | |||||
| 169 | } else { | |||||
| 170 | response.s endRedirec t(parts[0] ); | |||||
| 171 | } | |||||
| 172 | } else { | |||||
| 173 | request. getRequest Dispatcher (url).forw ard(reques t, respons e); | |||||
| 174 | } | |||||
| 175 | } el se { | |||||
| 176 | throw new Servle tException ("Action, " + action Name | |||||
| 177 | + ", does not exist. Check the servlet's init para meters."); | |||||
| 178 | } | |||||
| 179 | } | |||||
| 180 | ||||||
| 181 | /* * | |||||
| 182 | * Convenien ce method to get the Spring Be an. | |||||
| 183 | * / | |||||
| 184 | pu blic <E> E getBean(f inal Strin g beanID, final Clas s<E> clazz ) { | |||||
| 185 | retu rn clazz.c ast(this.w ebApplicat ionContext .getBean(b eanID)); | |||||
| 186 | } | |||||
| 187 | ||||||
| 188 | @O verride | |||||
| 189 | pu blic void init() thr ows Servle tException { | |||||
| 190 | supe r.init(); | |||||
| 191 | // G et the Spr ing Web ap plication context | |||||
| 192 | this .webApplic ationConte xt = WebAp plicationC ontextUtil s | |||||
| 193 | .getRequ iredWebApp licationCo ntext(this .getServle tContext() ); | |||||
| 194 | // L oad the va lidation f ile | |||||
| 195 | Inpu tStream is =null; | |||||
| 196 | try { | |||||
| 197 | is = this.getSe rvletConte xt() | |||||
| 198 | .getResour ceAsStream ( | |||||
| 199 | Resp onseDispat cherHttpSe rvlet.VALI DATION_FIL E_PATH); | |||||
| 200 | if (is != null) { | |||||
| 201 | this.val idatorReso urces = ne w Validato rResources (is); | |||||
| 202 | } else { | |||||
| 203 | throw ne w RuntimeE xception(" Could not find " | |||||
| 204 | + ResponseDi spatcherHt tpServlet. VALIDATION _FILE_PATH | |||||
| 205 | + "."); | |||||
| 206 | } | |||||
| 207 | ||||||
| 208 | } ca tch (final SAXExcept ion t) { | |||||
| 209 | throw new Servle tException (t); | |||||
| 210 | } ca tch (final IOExcepti on t) { | |||||
| 211 | throw new Servle tException (t); | |||||
| 212 | }fin ally{ | |||||
| 213 | try { | |||||
| 214 | is.close (); | |||||
| 215 | } catc h (IOExcep tion e) { | |||||
| 216 | // TODO Auto-gener ated catch block | |||||
| 217 | e.printS tackTrace( ); | |||||
| 218 | } | |||||
| 219 | } | |||||
| 220 | } | |||||
| 221 | ||||||
| 222 | /* * | |||||
| 223 | * The main entry poin t in this class. Loo ks at the parameter names and uses | |||||
| 224 | * reflectio n to call a method w ith that n ame. | |||||
| 225 | * / | |||||
| 226 | pr otected vo id process Request(fi nal HttpSe rvletReque st request , | |||||
| 227 | final HttpServle tResponse response) throws Ser vletExcept ion, | |||||
| 228 | IOExce ption { | |||||
| 229 | // A utomatical ly call th e method b ased on th e button n ame. | |||||
| 230 | // T he code, l ooks for m ethods wit h the same name spec ified in t he | |||||
| 231 | // s ubmit butt on and exe cutes that method. | |||||
| 232 | ||||||
| 233 | fina l Document Helper hel per = this .getBean(" adapterDoc umentHelpe r", | |||||
| 234 | Document Helper.cla ss); | |||||
| 235 | if ( NullChecke r.isNullOr Empty(requ est.getAtt ribute("fo rmErrors") )) { | |||||
| 236 | boolea n invokedM ethod = fa lse; | |||||
| 237 | if (!S ervletFile Upload.isM ultipartCo ntent(requ est)) { | |||||
| 238 | for (fin al Enumera tion<?> e = request. getParamet erNames(); e | |||||
| 239 | .h asMoreElem ents();) { | |||||
| 240 | final Stri ng paramet erName = ( String) e. nextElemen t(); | |||||
| 241 | invokedMet hod = this .executeMe thod(param eterName, request, | |||||
| 242 | resp onse); | |||||
| 243 | if (invoke dMethod) { | |||||
| 244 | br eak; | |||||
| 245 | } | |||||
| 246 | } | |||||
| 247 | } else { | |||||
| 248 | try { | |||||
| 249 | final Serv letFileUpl oad servle tFileUploa d = new Se rvletFileU pload( | |||||
| 250 | new DiskFileIt emFactory( )); | |||||
| 251 | // Get the MB size f rom Spring propertie s | |||||
| 252 | servletFil eUpload.se tSizeMax(h elper.getM axUploadFi leSize()); | |||||
| 253 | final List <?> fileIt emsList = servletFil eUpload | |||||
| 254 | .par seRequest( request); | |||||
| 255 | if (NullCh ecker.isNo tEmpty(fil eItemsList )) { | |||||
| 256 | fi nal Iterat or<?> it = fileItems List.itera tor(); | |||||
| 257 | wh ile (it.ha sNext()) { | |||||
| 258 | fina l FileItem fileItemT emp = (Fil eItem) it. next(); | |||||
| 259 | // G et the for m fields t o execute a specific method | |||||
| 260 | if ( fileItemTe mp.isFormF ield()) { | |||||
| 261 | final String fie ldName = f ileItemTem p | |||||
| 262 | .getFieldN ame(); | |||||
| 263 | invoke dMethod = this.execu teMethod(f ieldName, | |||||
| 264 | (List<File Item>) fil eItemsList , | |||||
| 265 | request, r esponse); | |||||
| 266 | if (in vokedMetho d) { | |||||
| 267 | break; | |||||
| 268 | } | |||||
| 269 | } el se { | |||||
| 270 | // If there is a file, the n check if its a PDF . | |||||
| 271 | // Onl y PDFs are supported . | |||||
| 272 | if (fi leItemTemp .getSize() > 0) { | |||||
| 273 | if (Null Checker.is Empty(file ItemTemp | |||||
| 274 | .g etContentT ype())) { | |||||
| 275 | throw new RuntimeExc eption( | |||||
| 276 | "The re has to be a conte nt type fo r the file !"); | |||||
| 277 | } | |||||
| 278 | if (Medi aType.isSu pported(fi leItemTemp | |||||
| 279 | .g etContentT ype())) { | |||||
| 280 | // | |||||
| 281 | } else { | |||||
| 282 | throw new ServletExc eption( | |||||
| 283 | "Onl y the foll owing file types " | |||||
| 284 | + MediaT ype | |||||
| 285 | .g etSupporte dTypes() | |||||
| 286 | + " are supported when uploa ding docum ents!"); | |||||
| 287 | } | |||||
| 288 | } | |||||
| 289 | } | |||||
| 290 | } | |||||
| 291 | } | |||||
| 292 | } catch (final Siz eLimitExce ededExcept ion ex) { | |||||
| 293 | throw new ServletExc eption( | |||||
| 294 | "The file size exceeded the allowe d " | |||||
| 295 | + helper .getMaxUpl oadFileSiz e() + " by tes.", | |||||
| 296 | ex); | |||||
| 297 | } catch (final Fil eUploadExc eption ex) { | |||||
| 298 | throw new ServletExc eption(ex) ; | |||||
| 299 | } | |||||
| 300 | } | |||||
| 301 | // If no matchin g method, then just call unspe cified() m ethod | |||||
| 302 | if (!i nvokedMeth od) { | |||||
| 303 | this.uns pecified(r equest, re sponse); | |||||
| 304 | } | |||||
| 305 | } el se { | |||||
| 306 | this.u nspecified (request, response); | |||||
| 307 | } | |||||
| 308 | } | |||||
| 309 | ||||||
| 310 | /* * | |||||
| 311 | * Create a unique req uestId for each requ est. | |||||
| 312 | * / | |||||
| 313 | pr otected vo id setRequ estId(fina l HttpServ letRequest request, | |||||
| 314 | final HttpServle tResponse response) { | |||||
| 315 | fina l HttpSess ion sessio n = reques t.getSessi on(false); | |||||
| 316 | // S et a reque st Id for each reque st. | |||||
| 317 | if ( session != null) { | |||||
| 318 | sessio n.setAttri bute("requ estId", UU ID.randomU UID().toSt ring()); | |||||
| 319 | } | |||||
| 320 | } | |||||
| 321 | ||||||
| 322 | /* * | |||||
| 323 | * All servl ets should implement the unspe cified met hod! | |||||
| 324 | * / | |||||
| 325 | ab stract pro tected voi d unspecif ied(HttpSe rvletReque st request , | |||||
| 326 | HttpSe rvletRespo nse respon se) throws ServletEx ception, I OException ; | |||||
| 327 | ||||||
| 328 | /* * | |||||
| 329 | * Validate the page i f there ar e matching fields in the valid ation.xml | |||||
| 330 | * file. | |||||
| 331 | * / | |||||
| 332 | pr otected bo olean vali date(final HttpServl etRequest request, | |||||
| 333 | final HttpServle tResponse response) throws Ser vletExcept ion { | |||||
| 334 | retu rn this.va lidate(req uest, resp onse, null ); | |||||
| 335 | } | |||||
| 336 | ||||||
| 337 | /* * | |||||
| 338 | * Validate using the apache com mons valid ator engin e. | |||||
| 339 | * / | |||||
| 340 | pr otected bo olean vali date(final HttpServl etRequest request, | |||||
| 341 | final HttpServle tResponse response, final Stri ng subacti on) | |||||
| 342 | throws ServletEx ception { | |||||
| 343 | fina l HashMap< String, St ring> bean = new Has hMap<Strin g, String> (); | |||||
| 344 | for (final Enu meration<? > e = requ est.getPar ameterName s(); e | |||||
| 345 | .hasMore Elements() ;) { | |||||
| 346 | final String key = (String ) e.nextEl ement(); | |||||
| 347 | bean.p ut(key, re quest.getP arameter(k ey)); | |||||
| 348 | } | |||||
| 349 | ||||||
| 350 | retu rn this.va lidate(bea n, request , response , subactio n); | |||||
| 351 | } | |||||
| 352 | ||||||
| 353 | /* * | |||||
| 354 | * Validate using the apache com mons valid ator engin e. | |||||
| 355 | * / | |||||
| 356 | pr otected bo olean vali date(final Map<Strin g, String> bean, | |||||
| 357 | final HttpServle tRequest r equest, | |||||
| 358 | final HttpServle tResponse response, final Stri ng subacti on) | |||||
| 359 | throws ServletEx ception { | |||||
| 360 | try { | |||||
| 361 | final String con textPath = request.g etContextP ath(); | |||||
| 362 | String action = request.ge tRequestUR I(); | |||||
| 363 | if (!N ullChecker .isNullOrE mpty(conte xtPath)) { | |||||
| 364 | action = action.su bstring(co ntextPath. length()); | |||||
| 365 | } | |||||
| 366 | ||||||
| 367 | if (!N ullChecker .isNullOrE mpty(subac tion)) { | |||||
| 368 | action + = ":" + su baction; | |||||
| 369 | } | |||||
| 370 | // Cal l the vali dator with the param ters | |||||
| 371 | final Validator validator = new Vali dator(this .validator Resources, | |||||
| 372 | action); | |||||
| 373 | valida tor.setUse ContextCla ssLoader(t rue); | |||||
| 374 | valida tor.setPar ameter(Val idator.BEA N_PARAM, b ean); | |||||
| 375 | final ArrayList< ?> message s = new Ar rayList(); | |||||
| 376 | valida tor.setPar ameter("ja va.util.Ar rayList", messages); | |||||
| 377 | valida tor.setPar ameter("ja vax.servle t.http.Htt pServletRe quest", | |||||
| 378 | request); | |||||
| 379 | valida tor.setOnl yReturnErr ors(true); | |||||
| 380 | // Val idate | |||||
| 381 | final ValidatorR esults res ults = val idator.val idate(); | |||||
| 382 | reques t.setAttri bute("form Errors", m essages); | |||||
| 383 | return results.i sEmpty(); | |||||
| 384 | } ca tch (final Validator Exception ex) { | |||||
| 385 | throw new Servle tException (ex); | |||||
| 386 | } | |||||
| 387 | } | |||||
| 388 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.