class TemplatedHttpHandler extends HttpResource {

   @Override
   public FullHttpResponse respond(FullHttpRequest req, ChannelHandlerContext ctx) throws Exception {
      HttpResponseStatus responseStatus = HttpResponseStatus.OK;
      Optional<String> response = Optional.empty();

      try {
         TemplatedResponse handlerResponse = doHandle(req, ctx);
         if (handlerResponse.sectionId.isPresent()) {
            Map<String, String> multiResponse = templateService.renderMultipart(handlerResponse.templateId.get(), handlerResponse.context);
            response = Optional.of(multiResponse.get(handlerResponse.sectionId.get()));
         } else if (handlerResponse.templateId.isPresent()){
            response = Optional.of(templateService.render(handlerResponse.templateId.get(), handlerResponse.context));
         }

         if(!response.isPresent()){
            responseStatus=HttpResponseStatus.NO_CONTENT;
         }

         if(handlerResponse.responseStatus.isPresent()){
            responseStatus=handlerResponse.responseStatus.get();
         }
         

      } catch (Throwable th) {
         LOGGER.error("Error responding to TemplatedRequestHandler", th);
         responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
      }
      
      FullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, responseStatus, Unpooled.copiedBuffer(response.orElse("").getBytes()));
      httpResponse.headers().set(HttpHeaders.Names.CONTENT_TYPE, getContentType());
      return httpResponse;
   }

   public  TemplatedHttpHandler(AlwaysAllow alwaysAllow, HttpSender httpSender, TemplateService templateService);

}