use of com.github.dreamhead.moco.MocoException 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);
}
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class MocoClient method run.
public final void run(final String host, final int port, final ChannelHandler pipelineFactory) {
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class).remoteAddress(host, port).option(ChannelOption.TCP_NODELAY, true).handler(pipelineFactory);
try {
Channel channel = bootstrap.connect().sync().channel();
ChannelFuture future = channel.closeFuture().sync();
future.addListener(ChannelFutureListener.CLOSE);
} catch (InterruptedException e) {
throw new MocoException(e);
} finally {
group.shutdownGracefully();
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class XmlRequestMatcher method documentBuilder.
private DocumentBuilder documentBuilder() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setCoalescing(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setIgnoringComments(true);
try {
return dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class MocoSocketHandler method channelRead0.
@Override
protected void channelRead0(final ChannelHandlerContext ctx, final ByteBuf msg) {
MessageContent content = content().withContent(new ByteBufInputStream(msg)).build();
SocketRequest request = new DefaultSocketRequest(content);
SessionContext context = new SessionContext(request, new DefaultSocketResponse());
Optional<Response> response = server.getResponse(context);
Response actual = response.orElseThrow(() -> new MocoException(format("No handler found for request: %s", context.getRequest().getContent())));
ctx.write(ByteBufs.toByteBuf(actual.getContent().getContent()));
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class FileResourceReader method doReadFor.
@Override
protected byte[] doReadFor(final Request request) {
String pathname = targetFileName(request);
Path path = Paths.get(pathname);
if (!Files.exists(path)) {
throw new IllegalArgumentException(format("%s does not exist", path.getFileName().toString()));
}
try {
return Files.readAllBytes(path);
} catch (IOException e) {
throw new MocoException(e);
}
}
Aggregations