private List<Session> prepareTargetSessions(Session targetSession) { List<Session> sessions = restoreSessions(this.file); Optional<Session> session = tryFind(sessions, isForRequest(targetSession.getRequest())); if (session.isPresent()) { session.get().setResponse(targetSession.getResponse()); } else { sessions.add(targetSession); } return sessions; }
public void onCompleteResponse(FullHttpRequest request, FullHttpResponse response) { try { ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); Session targetSession = Session.newSession( MessageFactory.createRequest(request), MessageFactory.createResponse(response)); writer.writeValue(this.file, prepareTargetSessions(targetSession)); } catch (IOException e) { throw new RuntimeException(e); } }