@@ -179,7 +179,8 @@ public Response checkFilingForReview(
179179 @ Context SecurityContext security ,
180180 @ Context HttpHeaders httpHeaders ,
181181 @ PathParam ("court_id" ) String courtId ,
182- String allVars ) {
182+ String allVars )
183+ throws Exception {
183184 MDC .put (MDCWrappers .OPERATION , "FilingReviewService.checkFilingForReview" );
184185 MediaType mediaType = httpHeaders .getMediaType ();
185186 if (mediaType == null ) {
@@ -194,19 +195,20 @@ public Response checkFilingForReview(
194195 if (tylerUser .isEmpty ()) {
195196 return Response .status (401 ).entity ("Not logged in to file with " + courtId ).build ();
196197 }
198+ if (!converterMap .containsKey (mediaType .toString ())) {
199+ return Response .status (415 ).entity ("We only support " + converterMap .keySet ()).build ();
200+ }
197201 Result <CodesParser , Response > maybeParser = makeParser (courtId , tylerUser .get ().creds (), filer );
198202 if (maybeParser .isErr ()) {
199203 return maybeParser .unwrapErrOrElseThrow ();
200204 }
201205 var parser = maybeParser .unwrapOrElseThrow ();
202- if (!converterMap .containsKey (mediaType .toString ())) {
203- return Response .status (415 ).entity ("We only support " + converterMap .keySet ()).build ();
204- }
205206 InfoCollector collector = new NeverSubmitCollector ();
206207 Result <FilingInformation , FilingError > res =
207208 converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
208209 if (res .isErr ()) {
209210 log .error ("Error on traverseInterview: {}" , res .toString ());
211+ parser .close ();
210212 return Response .status (400 ).entity (collector .jsonSummary ()).build ();
211213 }
212214 FilingInformation info = res .unwrapOrElseThrow ();
@@ -215,8 +217,10 @@ public Response checkFilingForReview(
215217 filer .checkFiling (info , tylerUser .get ().creds (), collector );
216218 if (resEfm .isErr ()) {
217219 log .error ("Error on checkFiling: {}" , resEfm .toString ());
220+ parser .close ();
218221 return Response .ok (collector .jsonSummary ()).build ();
219222 }
223+ parser .close ();
220224 return Response .ok (collector .jsonSummary ()).build ();
221225 }
222226
@@ -227,7 +231,8 @@ public Response calculateFilingFees(
227231 @ Context SecurityContext security ,
228232 @ Context HttpHeaders httpHeaders ,
229233 @ PathParam ("court_id" ) String courtId ,
230- String allVars ) {
234+ String allVars )
235+ throws Exception {
231236 MDC .put (MDCWrappers .OPERATION , "FilingReviewService.calculateFilingFees" );
232237 MediaType mediaType = httpHeaders .getMediaType ();
233238 if (mediaType == null ) {
@@ -242,25 +247,27 @@ public Response calculateFilingFees(
242247 if (tylerUser .isEmpty ()) {
243248 return Response .status (401 ).entity ("Not logged in to file with " + courtId ).build ();
244249 }
250+ if (!converterMap .containsKey (mediaType .toString ())) {
251+ return Response .status (415 ).entity ("We only support " + converterMap .keySet ()).build ();
252+ }
245253 Result <CodesParser , Response > maybeParser = makeParser (courtId , tylerUser .get ().creds (), filer );
246254 if (maybeParser .isErr ()) {
247255 return maybeParser .unwrapErrOrElseThrow ();
248256 }
249257 var parser = maybeParser .unwrapOrElseThrow ();
250- if (!converterMap .containsKey (mediaType .toString ())) {
251- return Response .status (415 ).entity ("We only support " + converterMap .keySet ()).build ();
252- }
253258 log .trace ("Court id: {}" , courtId );
254259 InfoCollector collector = new FailFastCollector ();
255260 Result <FilingInformation , FilingError > res =
256261 converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
257262 if (res .isErr ()) {
258263 log .error ("Error when calculating filing fees: {}" , res .toString ());
264+ parser .close ();
259265 return Response .status (400 ).entity (collector .jsonSummary ()).build ();
260266 }
261267 FilingInformation info = res .unwrapOrElseThrow ();
262268 info .setCourtLocation (courtId );
263269 Result <Response , FilingError > fees = filer .getFilingFees (info , tylerUser .get ().creds ());
270+ parser .close ();
264271 return fees .match (err -> Response .status (400 ).entity (err .toJson ()).build (), respon -> respon );
265272 }
266273
@@ -271,7 +278,8 @@ public Response getServiceTypes(
271278 @ Context SecurityContext security ,
272279 @ Context HttpHeaders httpHeaders ,
273280 @ PathParam ("court_id" ) String courtId ,
274- String allVars ) {
281+ String allVars )
282+ throws Exception {
275283 MDC .put (MDCWrappers .OPERATION , "FilingReviewService.getServiceTypes" );
276284 MediaType mediaType = httpHeaders .getMediaType ();
277285 if (mediaType == null ) {
@@ -287,23 +295,25 @@ public Response getServiceTypes(
287295 if (tylerUser .isEmpty ()) {
288296 return Response .status (401 ).entity ("Not logged in to file with " + courtId ).build ();
289297 }
298+ if (!converterMap .containsKey (mediaType .toString ())) {
299+ return Response .status (415 ).entity ("We only support " + converterMap .keySet ()).build ();
300+ }
290301 Result <CodesParser , Response > maybeParser = makeParser (courtId , tylerUser .get ().creds (), filer );
291302 if (maybeParser .isErr ()) {
292303 return maybeParser .unwrapErrOrElseThrow ();
293304 }
294305 var parser = maybeParser .unwrapOrElseThrow ();
295- if (!converterMap .containsKey (mediaType .toString ())) {
296- return Response .status (415 ).entity ("We only support " + converterMap .keySet ()).build ();
297- }
298306 InfoCollector collector = new FailFastCollector ();
299307 Result <FilingInformation , FilingError > res =
300308 converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
301309 if (res .isErr ()) {
310+ parser .close ();
302311 return Response .status (400 ).entity (collector .jsonSummary ()).build ();
303312 }
304313 FilingInformation info = res .unwrapOrElseThrow ();
305314 info .setCourtLocation (courtId );
306315 Result <Response , FilingError > fees = filer .getServiceTypes (info , tylerUser .get ().creds ());
316+ parser .close ();
307317 return fees .match (err -> Response .status (400 ).entity (err .toJson ()).build (), respon -> respon );
308318 }
309319
@@ -484,11 +494,21 @@ private Result<FilingInformation, Response> parseFiling(
484494 Result <FilingInformation , FilingError > maybeInfo =
485495 converterMap .get (mediaType .toString ()).extractInformation (allVars , parser );
486496 if (maybeInfo .isErr ()) {
497+ try {
498+ parser .close ();
499+ } catch (Exception ex ) {
500+ log .warn ("Couldn't close parser" , ex );
501+ }
487502 return Result .err (
488503 Response .status (400 ).entity (maybeInfo .unwrapErrOrElseThrow ().toJson ()).build ());
489504 }
490505 FilingInformation info = maybeInfo .unwrapOrElseThrow ();
491506 info .setCourtLocation (courtId );
507+ try {
508+ parser .close ();
509+ } catch (Exception ex ) {
510+ log .warn ("Couldn't close parser" , ex );
511+ }
492512 return Result .ok (info );
493513 }
494514
0 commit comments