test_class.declarator: log = LoggerFactory.getLogger(TransformServletTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger log = LoggerFactory.getLogger(TransformServletTest.class);
test_class.type: Logger
test_class.var_name: log
test_class.declarator: ts = new TransformServlet()
test_class.modifier: private
test_class.original_string: private TransformServlet ts = new TransformServlet();
test_class.type: TransformServlet
test_class.var_name: ts
test_class.declarator: context = new SlingContext()
test_class.modifier: @Rule
      public final
test_class.original_string: @Rule
      public final SlingContext context = new SlingContext();
test_class.type: SlingContext
test_class.var_name: context
test_class.file: transformer/src/test/java/org/apache/sling/cms/transformer/internal/TransformServletTest.java
test_class.identifier: TransformServletTest
test_case.body: @Test
      public void testInvalid() throws IOException, ServletException {
          log.info("testContentTypes");
  
          context.currentResource("/content/apache/sling-apache-org/index/apache.png");
          context.requestPathInfo().setSuffix("/test2.png");
          context.requestPathInfo().setExtension("transform");
  
          ts.doGet(context.request(), context.response());
  
          assertEquals(400, context.response().getStatus());
      }
test_case.class_method_signature: TransformServletTest.testInvalid()
test_case.full_signature: @Test public void testInvalid()
test_case.identifier: testInvalid
test_case.invocations: info currentResource setSuffix requestPathInfo setExtension requestPathInfo doGet request response assertEquals getStatus response
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInvalid()
focal_class.declarator: log = LoggerFactory.getLogger(TransformServlet.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(TransformServlet.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: serialVersionUID = -1513067546618762171L
focal_class.modifier: private static final
focal_class.original_string: private static final long serialVersionUID = -1513067546618762171L;
focal_class.type: long
focal_class.var_name: serialVersionUID
focal_class.declarator: SERVICE_USER = "sling-cms-transformer"
focal_class.modifier: public static final
focal_class.original_string: public static final String SERVICE_USER = "sling-cms-transformer";
focal_class.type: String
focal_class.var_name: SERVICE_USER
focal_class.declarator: transformationServiceUser
focal_class.modifier: private transient
focal_class.original_string: private transient TransformationServiceUser transformationServiceUser;
focal_class.type: TransformationServiceUser
focal_class.var_name: transformationServiceUser
focal_class.declarator: transformer
focal_class.modifier: private transient
focal_class.original_string: private transient Transformer transformer;
focal_class.type: Transformer
focal_class.var_name: transformer
focal_class.declarator: config
focal_class.modifier: private transient
focal_class.original_string: private transient TransformServletConfig config;
focal_class.type: TransformServletConfig
focal_class.var_name: config
focal_class.file: transformer/src/main/java/org/apache/sling/cms/transformer/internal/TransformServlet.java
focal_class.identifier: TransformServlet
focal_class.class_method_signature: TransformServlet.activate(TransformServletConfig config)
focal_class.full_signature: @Activate public void activate(TransformServletConfig config)
focal_class.identifier: activate
focal_class.modifiers: @Activate public
focal_class.parameters: (TransformServletConfig config)
focal_class.return: void
focal_class.signature: void activate(TransformServletConfig config)
focal_class.class_method_signature: TransformServlet.doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_class.full_signature: @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_class.identifier: doGet
focal_class.modifiers: @Override protected
focal_class.parameters: (SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_class.return: void
focal_class.signature: void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_class.class_method_signature: TransformServlet.findTransformation(ResourceResolver serviceResolver, String name)
focal_class.full_signature: protected Transformation findTransformation(ResourceResolver serviceResolver, String name)
focal_class.identifier: findTransformation
focal_class.modifiers: protected
focal_class.parameters: (ResourceResolver serviceResolver, String name)
focal_class.return: Transformation
focal_class.signature: Transformation findTransformation(ResourceResolver serviceResolver, String name)
focal_class.class_method_signature: TransformServlet.setTransformationServiceUser(TransformationServiceUser transformationServiceUser)
focal_class.full_signature: @Reference public void setTransformationServiceUser(TransformationServiceUser transformationServiceUser)
focal_class.identifier: setTransformationServiceUser
focal_class.modifiers: @Reference public
focal_class.parameters: (TransformationServiceUser transformationServiceUser)
focal_class.return: void
focal_class.signature: void setTransformationServiceUser(TransformationServiceUser transformationServiceUser)
focal_class.class_method_signature: TransformServlet.setTransformer(Transformer transformer)
focal_class.full_signature: @Reference public void setTransformer(Transformer transformer)
focal_class.identifier: setTransformer
focal_class.modifiers: @Reference public
focal_class.parameters: (Transformer transformer)
focal_class.return: void
focal_class.signature: void setTransformer(Transformer transformer)
focal_class.superclass: extends SlingSafeMethodsServlet
focal_method.body: @Override
      protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
              throws ServletException, IOException {
          log.trace("doGet");
  
          String name = StringUtils.substringBeforeLast(request.getRequestPathInfo().getSuffix(), ".");
          response.setHeader("Content-Disposition", "filename=" + request.getResource().getName());
          String format = StringUtils.substringAfterLast(request.getRequestPathInfo().getSuffix(), ".");
          log.debug("Transforming resource: {} with transformation: {} to {}", request.getResource(), name, format);
          String original = response.getContentType();
          try (ResourceResolver serviceResolver = transformationServiceUser.getTransformationServiceUser()) {
              Transformation transformation = findTransformation(serviceResolver, name);
              if (transformation != null) {
                  response.setContentType(OutputFileFormat.forRequest(request).getMimeType());
                  String expectedPath = "jcr:content/renditions/" + name + "." + format;
                  Resource rendition = request.getResource().getChild(expectedPath);
                  if (rendition != null) {
                      log.debug("Using existing rendition {}", name);
                      IOUtils.copy(rendition.adaptTo(InputStream.class), response.getOutputStream());
                  } else {
                      log.debug("Creating new rendition {}", name);
                      ByteArrayOutputStream baos = new ByteArrayOutputStream();
                      transformer.transform(request.getResource(), transformation,
                              OutputFileFormat.valueOf(format.toUpperCase()), baos);
                      IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
                      if (CMSConstants.NT_FILE.equals(request.getResource().getResourceType())) {
                          Resource file = ResourceUtil.getOrCreateResource(serviceResolver,
                                  request.getResource().getPath() + "/" + expectedPath,
                                  Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_FILE),
                                  JcrConstants.NT_UNSTRUCTURED, false);
                          Map<String, Object> properties = new HashMap<>();
                          properties.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
                          properties.put(JcrConstants.JCR_DATA, new ByteArrayInputStream(baos.toByteArray()));
                          ResourceUtil.getOrCreateResource(serviceResolver,
                                  file.getPath() + "/" + JcrConstants.JCR_CONTENT, properties,
                                  JcrConstants.NT_UNSTRUCTURED, true);
                      }
  
                  }
              } else {
                  log.error("Exception transforming image: {} with transformation: {}", request.getResource(), name);
                  response.setContentType(original);
                  response.sendError(400, "Could not transform image with transformation: " + name);
              }
          } catch (Exception e) {
              log.error("Exception rendering transformed resource", e);
              response.setStatus(500);
              RequestDispatcherOptions op = new RequestDispatcherOptions();
              op.setReplaceSuffix(config.errorSuffix());
              op.setReplaceSelectors("transform");
              RequestDispatcher disp = request.getRequestDispatcher(config.errorResourcePath(), op);
              disp.forward(request, response);
  
          }
      }
focal_method.class_method_signature: TransformServlet.doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_method.full_signature: @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_method.identifier: doGet
focal_method.invocations: trace substringBeforeLast getSuffix getRequestPathInfo setHeader getName getResource substringAfterLast getSuffix getRequestPathInfo debug getResource getContentType getTransformationServiceUser findTransformation setContentType getMimeType forRequest getChild getResource debug copy adaptTo getOutputStream debug transform getResource valueOf toUpperCase copy toByteArray getOutputStream equals getResourceType getResource getOrCreateResource getPath getResource singletonMap put put toByteArray getOrCreateResource getPath error getResource setContentType sendError error setStatus setReplaceSuffix errorSuffix setReplaceSelectors getRequestDispatcher errorResourcePath forward
focal_method.modifiers: @Override protected
focal_method.parameters: (SlingHttpServletRequest request, SlingHttpServletResponse response)
focal_method.return: void
focal_method.signature: void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)