Source:
private Response buildResponse( @Nonnull final String patientId, @Nonnull final String server, final int offset, final int limit, final boolean newRequest, final int reqNo) { try { final Patient patient = this.repository.get(patientId); if (patient == null) { this.logger.error("Patient with ID: could not be found.", patientId); return Response.status(Response.Status.BAD_REQUEST).build(); } final OutgoingMatchRequest remoteResponse = newRequest ? this.matchingService.sendRequest(patientId, server, 5) : this.matchingService.getLastRequestSent(patientId, server); if (remoteResponse == null) { this.logger.warn("Remote match request was never initiated."); return Response.status(Response.Status.NO_CONTENT).build(); } if (!remoteResponse.gotValidReply()) { this.logger.error("The response received from remote server was not valid: {}", remoteResponse.getRequestStatusCode(), remoteResponse.getRequestJSON()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return buildMatches(patient, remoteResponse, offset, limit, reqNo); } catch (final SecurityException e) { this.logger.error("Failed to retrieve patient with ID [{}]: {}", patientId, e.getMessage()); return Response.status(Response.Status.UNAUTHORIZED).build(); } catch (final IndexOutOfBoundsException | IllegalArgumentException e) { this.logger.error("The requested offset is out of bounds", offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.logger.error("Unexpected exception while generating remote matches: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }

Target:
private Response buildResponse( @Nonnull final String patientId, @Nonnull final String server, final int offset, final int limit, final boolean newRequest, final int reqNo) { try { final Patient patient = this.repository.get(patientId); if (patient == null) { this.logger.error("Patient with ID: could not be found.", patientId); return Response.status(Response.Status.BAD_REQUEST).build(); } final OutgoingMatchRequest remoteResponse = newRequest ? this.matchingService.sendRequest(patientId, server, 0) : this.matchingService.getLastRequestSent(patientId, server); if (remoteResponse == null) { this.logger.warn("Remote match request was never initiated."); return Response.status(Response.Status.NO_CONTENT).build(); } if (!remoteResponse.gotValidReply()) { this.logger.error("The response received from remote server was not valid: {}", remoteResponse.getRequestStatusCode(), remoteResponse.getRequestJSON()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return buildMatches(patient, remoteResponse, offset, limit, reqNo); } catch (final SecurityException e) { this.logger.error("Failed to retrieve patient with ID [{}]: {}", patientId, e.getMessage()); return Response.status(Response.Status.UNAUTHORIZED).build(); } catch (final IndexOutOfBoundsException | IllegalArgumentException e) { this.logger.error("The requested offset is out of bounds", offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.logger.error("Unexpected exception while generating remote matches: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }