use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class WatcherService method registerDirectory.
private WatchKey registerDirectory(final Path directory) {
if (directoryToKey.containsKey(directory)) {
return directoryToKey.get(directory);
}
try {
WatchKey key = directory.register(service, new WatchEvent.Kind[] { ENTRY_MODIFY }, HIGH);
directoryToKey.put(directory, key);
return key;
} catch (IOException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class TemplateResourceReader method readFor.
@Override
public final MessageContent readFor(final Request request) {
if (request == null) {
throw new IllegalStateException("Request is required to render template");
}
MessageContent content = this.template.readFor(request);
try {
Template targetTemplate = createTemplate(content);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(stream);
targetTemplate.process(variables(request), writer);
return content().withContent(stream.toByteArray()).build();
} catch (ParseException e) {
logger.warn("Fail to parse template: {}", content.toString());
throw new MocoException(e);
} catch (IOException | TemplateException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class XmlRequestMatcher method extractDocument.
private Document extractDocument(final InputSource inputSource) {
try {
DocumentBuilder builder = documentBuilder();
Document document = builder.parse(inputSource);
document.normalizeDocument();
trimNode(document);
return document;
} catch (IOException | SAXException e) {
throw new MocoException(e);
}
}
Aggregations