示例#1
0
 @Override
 public void destroy() {
   try {
     ThreadSafeStaticBRJSAccessor.destroy();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
示例#2
0
  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    servletContext = config.getServletContext();

    try {
      File brjsDir = new File(servletContext.getRealPath("/"));
      ThreadSafeStaticBRJSAccessor.initializeModel(brjsDir, brjsDir);
    } catch (InvalidSdkDirectoryException e) {
      throw new ServletException(e);
    }

    try {
      brjs = ThreadSafeStaticBRJSAccessor.aquireModel();
      app = BRJSServletUtils.localeAppForContext(brjs, servletContext);
    } finally {
      ThreadSafeStaticBRJSAccessor.releaseModel();
    }
  }
示例#3
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String requestPath =
        request
            .getRequestURI()
            .replaceFirst("^" + request.getContextPath() + request.getServletPath() + "/", "");

    if (!requestPath.endsWith("/")) {
      String fileName =
          (requestPath.contains("/"))
              ? StringUtils.substringAfterLast(requestPath, "/")
              : requestPath;
      String mimeType = servletContext.getMimeType(fileName);
      if (mimeType != null) {
        response.setHeader(CONTENT_TYPE, mimeType);
      }
    }

    ThreadSafeStaticBRJSAccessor.aquireModel();
    UrlContentAccessor contentAccessor =
        new ServletContentAccessor(app, servletContext, request, response);
    try (ResponseContent content =
        app.requestHandler()
            .handleLogicalRequest(requestPath, contentAccessor, RequestMode.Dev); ) {
      if (!response
          .isCommitted()) { // check the ServletContentAccessor hasnt been used to handle a request
                            // and sent headers
        content.write(response.getOutputStream());
      }
    } catch (MalformedRequestException e) {
      response.sendError(400, e.getMessage());
    } catch (ResourceNotFoundException e) {
      response.sendError(404, e.getMessage());
    } catch (ContentProcessingException e) {
      response.sendError(500, e.getMessage());
    } catch (ModelOperationException e) {
      throw new ServletException(e);
    } finally {
      ThreadSafeStaticBRJSAccessor.releaseModel();
    }
  }