Search in sources :

Example 1 with Session

use of com.github.dreamhead.moco.model.Session in project moco by dreamhead.

the class DefaultFailoverExecutor method restoreSessions.

private ImmutableList<Session> restoreSessions(final File file) {
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
        List<Session> sessions = Jsons.toObject(inputStream, new TypeReference<List<Session>>() {
        });
        return copyOf(sessions);
    } catch (MocoException me) {
        logger.error("exception found", me);
        return of();
    } catch (IOException e) {
        throw new MocoException(e);
    } finally {
        if (inputStream != null) {
            Closeables.closeQuietly(inputStream);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MocoException(com.github.dreamhead.moco.MocoException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Session(com.github.dreamhead.moco.model.Session)

Example 2 with Session

use of com.github.dreamhead.moco.model.Session in project moco by dreamhead.

the class DefaultFailoverExecutor method onCompleteResponse.

@Override
public void onCompleteResponse(final HttpRequest request, final HttpResponse httpResponse) {
    try {
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        Session targetSession = Session.newSession(request, httpResponse);
        writer.writeValue(this.file, prepareTargetSessions(targetSession));
    } catch (IOException e) {
        throw new MocoException(e);
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) MocoException(com.github.dreamhead.moco.MocoException) Session(com.github.dreamhead.moco.model.Session)

Aggregations

MocoException (com.github.dreamhead.moco.MocoException)2 Session (com.github.dreamhead.moco.model.Session)2 IOException (java.io.IOException)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 ImmutableList (com.google.common.collect.ImmutableList)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1