test_class.declarator: rootDirectory
test_class.original_string: File rootDirectory;
test_class.type: File
test_class.var_name: rootDirectory
test_class.file: server/src/test/java/com/cloud/servlet/StaticResourceServletTest.java
test_class.identifier: StaticResourceServletTest
test_case.body: @Test
      public void testNoSuchFile() throws ServletException, IOException {
          final StaticResourceServlet servlet = Mockito
                  .mock(StaticResourceServlet.class);
          Mockito.doCallRealMethod()
                  .when(servlet)
                  .doGet(Matchers.any(HttpServletRequest.class),
                          Matchers.any(HttpServletResponse.class));
          final ServletContext servletContext = Mockito
                  .mock(ServletContext.class);
          Mockito.when(servletContext.getRealPath("notexisting.css")).thenReturn(
                  new File(rootDirectory, "notexisting.css").getAbsolutePath());
          Mockito.when(servlet.getServletContext()).thenReturn(servletContext);
  
          final HttpServletRequest request = Mockito
                  .mock(HttpServletRequest.class);
          Mockito.when(request.getServletPath()).thenReturn("notexisting.css");
          final HttpServletResponse response = Mockito
                  .mock(HttpServletResponse.class);
          servlet.doGet(request, response);
          Mockito.verify(response).setStatus(HttpServletResponse.SC_NOT_FOUND);
      }
test_case.class_method_signature: StaticResourceServletTest.testNoSuchFile()
test_case.full_signature: @Test public void testNoSuchFile()
test_case.identifier: testNoSuchFile
test_case.invocations: mock doGet when doCallRealMethod any any mock thenReturn when getRealPath getAbsolutePath thenReturn when getServletContext mock thenReturn when getServletPath mock doGet setStatus verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testNoSuchFile()
focal_class.declarator: serialVersionUID = -8833228931973461812L
focal_class.modifier: private static final
focal_class.original_string: private static final long serialVersionUID = -8833228931973461812L;
focal_class.type: long
focal_class.var_name: serialVersionUID
focal_class.declarator: contentTypes = Collections
              .unmodifiableMap(new HashMap<String, String>() {
                  {
                      put("css", "text/css");
                      put("svg", "image/svg+xml");
                      put("js", "application/javascript");
                      put("htm", "text/html");
                      put("html", "text/html");
                      put("txt", "text/plain");
                      put("xml", "text/xml");
                  }
              })
focal_class.modifier: @SuppressWarnings("serial")
      static final
focal_class.original_string: @SuppressWarnings("serial")
      static final Map<String, String> contentTypes = Collections
              .unmodifiableMap(new HashMap<String, String>() {
                  {
                      put("css", "text/css");
                      put("svg", "image/svg+xml");
                      put("js", "application/javascript");
                      put("htm", "text/html");
                      put("html", "text/html");
                      put("txt", "text/plain");
                      put("xml", "text/xml");
                  }
              });
focal_class.type: Map<String, String>
focal_class.var_name: contentTypes
focal_class.file: server/src/main/java/com/cloud/servlet/StaticResourceServlet.java
focal_class.identifier: StaticResourceServlet
focal_class.class_method_signature: StaticResourceServlet.getRequestedFile(final HttpServletRequest req)
focal_class.full_signature: private File getRequestedFile(final HttpServletRequest req)
focal_class.identifier: getRequestedFile
focal_class.modifiers: private
focal_class.parameters: (final HttpServletRequest req)
focal_class.return: File
focal_class.signature: File getRequestedFile(final HttpServletRequest req)
focal_class.class_method_signature: StaticResourceServlet.doGet(final HttpServletRequest req,
              final HttpServletResponse resp)
focal_class.full_signature: @Override protected void doGet(final HttpServletRequest req,
              final HttpServletResponse resp)
focal_class.identifier: doGet
focal_class.modifiers: @Override protected
focal_class.parameters: (final HttpServletRequest req,
              final HttpServletResponse resp)
focal_class.return: void
focal_class.signature: void doGet(final HttpServletRequest req,
              final HttpServletResponse resp)
focal_class.class_method_signature: StaticResourceServlet.getContentType(final String fileName)
focal_class.full_signature: static String getContentType(final String fileName)
focal_class.identifier: getContentType
focal_class.modifiers: static
focal_class.parameters: (final String fileName)
focal_class.return: String
focal_class.signature: String getContentType(final String fileName)
focal_class.class_method_signature: StaticResourceServlet.getCompressedVersion(final File requestedFile)
focal_class.full_signature: static File getCompressedVersion(final File requestedFile)
focal_class.identifier: getCompressedVersion
focal_class.modifiers: static
focal_class.parameters: (final File requestedFile)
focal_class.return: File
focal_class.signature: File getCompressedVersion(final File requestedFile)
focal_class.class_method_signature: StaticResourceServlet.isClientCompressionSupported(final HttpServletRequest req)
focal_class.full_signature: static boolean isClientCompressionSupported(final HttpServletRequest req)
focal_class.identifier: isClientCompressionSupported
focal_class.modifiers: static
focal_class.parameters: (final HttpServletRequest req)
focal_class.return: boolean
focal_class.signature: boolean isClientCompressionSupported(final HttpServletRequest req)
focal_class.class_method_signature: StaticResourceServlet.getEtag(final File resource)
focal_class.full_signature: static String getEtag(final File resource)
focal_class.identifier: getEtag
focal_class.modifiers: static
focal_class.parameters: (final File resource)
focal_class.return: String
focal_class.signature: String getEtag(final File resource)
focal_class.superclass: extends HttpServlet
focal_method.body: @Override
      protected void doGet(final HttpServletRequest req,
              final HttpServletResponse resp) throws ServletException,
              IOException {
          final File requestedFile = getRequestedFile(req);
          if (!requestedFile.exists() || !requestedFile.isFile()) {
              resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
              return;
          }
          final String etag = getEtag(requestedFile);
          if (etag.equals(req.getHeader("If-None-Match"))) {
              resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
              return;
          }
          // have to send data, either compressed or the original
          final File compressedStatic = getCompressedVersion(requestedFile);
          InputStream fileContent = null;
          try {
              resp.setContentType(getContentType(requestedFile.getName()));
              resp.setHeader("ETag", etag);
              resp.setStatus(HttpServletResponse.SC_OK);
              if (isClientCompressionSupported(req) && compressedStatic.exists()) {
                  // gzip compressed
                  resp.setHeader("Content-Encoding", "gzip");
                  resp.setContentLength((int) compressedStatic.length());
                  fileContent = new FileInputStream(compressedStatic);
              } else {
                  // uncompressed
                  resp.setContentLength((int) requestedFile.length());
                  fileContent = new FileInputStream(requestedFile);
              }
              IOUtils.copy(fileContent, resp.getOutputStream());
          } finally {
              IOUtils.closeQuietly(fileContent);
          }
      }
focal_method.class_method_signature: StaticResourceServlet.doGet(final HttpServletRequest req,
              final HttpServletResponse resp)
focal_method.full_signature: @Override protected void doGet(final HttpServletRequest req,
              final HttpServletResponse resp)
focal_method.identifier: doGet
focal_method.invocations: getRequestedFile exists isFile setStatus getEtag equals getHeader setStatus getCompressedVersion setContentType getContentType getName setHeader setStatus isClientCompressionSupported exists setHeader setContentLength length setContentLength length copy getOutputStream closeQuietly
focal_method.modifiers: @Override protected
focal_method.parameters: (final HttpServletRequest req,
              final HttpServletResponse resp)
focal_method.return: void
focal_method.signature: void doGet(final HttpServletRequest req,
              final HttpServletResponse resp)