When an adoc file cannot be found the complete lesson crashed, made it failsafe with a logging statement.

This commit is contained in:
Nanne Baars
2017-11-17 07:08:24 +01:00
parent 75d0405da1
commit 5eed385d5d

View File

@ -32,6 +32,7 @@ package org.owasp.webgoat;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.asciidoctor.Asciidoctor; import org.asciidoctor.Asciidoctor;
import org.owasp.webgoat.i18n.Language; import org.owasp.webgoat.i18n.Language;
import org.thymeleaf.TemplateProcessingParameters; import org.thymeleaf.TemplateProcessingParameters;
@ -50,6 +51,7 @@ import static org.asciidoctor.Asciidoctor.Factory.create;
* <div th:replace="doc:AccessControlMatrix_plan.adoc"></div> * <div th:replace="doc:AccessControlMatrix_plan.adoc"></div>
* </code> * </code>
*/ */
@Slf4j
public class AsciiDoctorTemplateResolver extends TemplateResolver { public class AsciiDoctorTemplateResolver extends TemplateResolver {
private static final Asciidoctor asciidoctor = create(); private static final Asciidoctor asciidoctor = create();
@ -73,11 +75,15 @@ public class AsciiDoctorTemplateResolver extends TemplateResolver {
@Override @Override
public InputStream getResourceAsStream(TemplateProcessingParameters params, String resourceName) { public InputStream getResourceAsStream(TemplateProcessingParameters params, String resourceName) {
InputStream is = readInputStreamOrFallbackToEnglish(resourceName, language); try (InputStream is = readInputStreamOrFallbackToEnglish(resourceName, language)) {
try { if (is == null) {
StringWriter writer = new StringWriter(); log.warn("Resource name: {} not found, did you add the adoc file?", resourceName);
asciidoctor.convert(new InputStreamReader(is), writer, createAttributes()); return new ByteArrayInputStream(new byte[0]);
return new ByteArrayInputStream(writer.getBuffer().toString().getBytes()); } else {
StringWriter writer = new StringWriter();
asciidoctor.convert(new InputStreamReader(is), writer, createAttributes());
return new ByteArrayInputStream(writer.getBuffer().toString().getBytes());
}
} catch (IOException e) { } catch (IOException e) {
//no html yet //no html yet
return new ByteArrayInputStream(new byte[0]); return new ByteArrayInputStream(new byte[0]);