use of org.apache.stanbol.enhancer.benchmark.Benchmark in project stanbol by apache.
the class BenchmarkServlet method doPost.
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final String content = request.getParameter(PARAM_CONTENT);
if (content == null) {
throw new ServletException("Missing " + PARAM_CONTENT + " parameter");
}
String chainName = request.getParameter(PARAM_CHAIN);
final Template t = AccessController.doPrivileged(new PrivilegedAction<Template>() {
@Override
public Template run() {
return getTemplate("/velocity/benchmark-results.html");
}
});
final VelocityContext ctx = getVelocityContext(request, "Benchmark Results");
ctx.put("contentItemFactory", ciFactory);
ctx.put("jobManager", jobManager);
List<? extends Benchmark> benchmarks = parser.parse(new StringReader(content));
if (chainName != null && !chainName.isEmpty()) {
Chain chain = chainManager.getChain(chainName);
if (chain == null) {
response.setStatus(404);
PrintWriter w = response.getWriter();
w.println("Unable to perform benchmark on EnhancementChain '" + StringEscapeUtils.escapeHtml(chainName) + "' because no chain with that name is active!");
IOUtils.closeQuietly(w);
return;
}
for (Benchmark benchmark : benchmarks) {
benchmark.setChain(chain);
}
}
ctx.put("benchmarks", benchmarks);
ctx.put("graphFormatter", new GraphFormatter(graphSerializer));
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws IOException {
t.merge(ctx, response.getWriter());
return null;
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof IOException) {
throw (IOException) e;
} else {
throw RuntimeException.class.cast(e);
}
}
}
Aggregations