Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

AEM Custom Servlet Post Working in HTTP but not HTTPs

Avatar

Level 2

Hi everyone,

I have a custom servlet which I am using to return folder information. I am able to return the information when I attempting to hit the servlet directly with HTTP and specifying the port number. However, we are setting AEM to be SSL by Default and I am unable to get the same information to be returned through HTTPS and when I do not specify the port which is the case I want. I'm assuming it has to do with the mapping I have in place but I am unsure.

 

I have updated the Apache Felix Jetty Based Http Service to enable HTTPS and messed around with the Sling Mapping but am getting nowhere. I have added error log information and some configuration information below when I attempt to hit the servlet from Postman.

Any help would be awesome.

 

Error Log Information

0 TIMER_START{Request Processing}
      2 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>
     12 LOG Method=POST, PathInfo=null
     16 TIMER_START{handleSecurity}
   2016 TIMER_END{1996,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@576d3546 returns true
   2298 TIMER_START{ResourceResolution}
   6162 TIMER_END{3862,ResourceResolution} URI=/api/assets/v1/jobFolderInfo resolves to Resource=NonExistingResource, path=/api/assets/v1/jobFolderInfo
   6175 LOG Resource Path Info: SlingRequestPathInfo: path='/api/assets/v1/jobFolderInfo', selectorString='null', extension='null', suffix='null'
   6176 TIMER_START{ServletResolution}
   6182 TIMER_START{resolveServlet(/api/assets/v1/jobFolderInfo)}
   8231 LOG {0}: no servlet found
   8245 TIMER_END{2061,resolveServlet(/api/assets/v1/jobFolderInfo)} Using servlet org.apache.sling.servlets.post.impl.SlingPostServlet
   8251 TIMER_END{2074,ServletResolution} URI=/api/assets/v1/jobFolderInfo handled by Servlet=org.apache.sling.servlets.post.impl.SlingPostServlet
   8259 LOG Applying Requestfilters
   8265 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl
   8274 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter

Sling Mapping

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Mapping"
sling:internalRedirect="/content/dam/site.$1.json"
sling:match="aem.site.com.4502/api/assets/v1/(.*)" />

Servlet Information

/**
* Servlet for creating folder using DAM assets APIs.
*/
@Component(service = Servlet.class,
property = {
Constants.SERVICE_DESCRIPTION + "=Get Job Folder Info API",
"sling.servlet.methods=" + HttpConstants.METHOD_POST,
"sling.servlet.resourceTypes=" + "sling/servlet/default",
"sling.servlet.selectors=" + "jobFolderInfo",
"sling.servlet.extensions=" + APIConstants.JSON_EXTENSION_TYPE
})
public class JobFolderInfoServlet extends SlingAllMethodsServlet {

 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

I was able resolve my issues because I figured out that I was missing a sling mapping file for https where I included a mapping which excluded the port number as part of the URL.

View solution in original post

3 Replies

Avatar

Community Advisor

Hello,

I don't think you can make a sling:internalRedirect with servlets; as this property causes the current path to be modified internally to continue with resource resolution; not script resolution. Documentation: https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html

Intern Solution:
Apache Redirects:

RewriteRule ^/api/assets/v1/(.*)$ /content/dam/site.$1.json [PT,L]

Documentation: https://sourcedcode.com/sugar-coating-servlet-scripts-and-paths

Hope this helps.

Avatar

Level 2
Thank you for getting back to me. I was able resolve my issues because I figured out that I was missing a sling mapping file for https where I included a mapping which excluded the port number as part of the URL.

Avatar

Correct answer by
Level 2

I was able resolve my issues because I figured out that I was missing a sling mapping file for https where I included a mapping which excluded the port number as part of the URL.