GuidesApiException occured: Unable to get resourceResolverFactory services. Check whether bundle has been ininitialised correctly | Community
Skip to main content
djohn98390536
Level 4
August 6, 2024
Solved

GuidesApiException occured: Unable to get resourceResolverFactory services. Check whether bundle has been ininitialised correctly

  • August 6, 2024
  • 2 replies
  • 1261 views

We have created a API which creates baseline following is the servlet code . We are also using a service user for resource resolver and the servlet is a path based servlet. This code works fine in local but when deployed to AEM cloud throwing below error .

 

GuidesApiException occured: Unable to get resourceResolverFactory services. Check whether bundle has been ininitialised correctly.

 

Servlet code

import com.adobe.fmdita.api.baselines.BaselineUtils;
import com.adobe.fmdita.api.exception.GuidesApiException;

@8220494(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=Baseline Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_POST, "sling.servlet.paths=" + "/bin/createBaseline" })
public class BaselineServlet extends SlingAllMethodsServlet {

private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(BaselineServlet.class);

@3214626
private ResourceResolverFactory resourceResolverFactory;
@9944223
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {

String baselineTitle = request.getParameter("baselineName");
String sourcePath = request.getParameter("mapPapth");
String label = request.getParameter("label");
LinkedHashMap<String, Object> directContext = new LinkedHashMap<>();
LinkedHashMap<String, Object> indirectContext = new LinkedHashMap<>();
ResourceResolver resolver = ResourceUtil.getServiceResourceResolver(resourceResolverFactory);
Session session = null;
try {
session = resolver.adaptTo(Session.class);
String baselineDetails = BaselineUtils.createBaseline(session, sourcePath, baselineTitle, label,
directContext, indirectContext);
response.setContentType(application/json);
logger.info("Baseline Created Successfully with Name:{}", baselineDetails);


}
} catch (GuidesApiException e) {
logger.error("GuidesApiException occured: {}", e.getMessage());
response.setContentType(application/json);
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write("{\"status\": \"error\", \"message\": \"Unable to create basleline\"}");
} finally {
if (session != null) {
session.logout();
}
if (resolver.isLive()) {
resolver.close();
}
}
}
}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by DivrajSingh

for this servlet only


@djohn98390536 : can you check the bundle symbolic name and match it with the service user mapping. Generally this error is logged when the custom code is deployed to the server. You must also be getting this when you deploy it through build job on your local SDK.

For more details you can check this tutorial: https://experienceleague.adobe.com/en/docs/experience-manager-learn/cloud-service/developing/advanced/service-users 

 

I hope this helps.

2 replies

Vijendra1
Adobe Employee
Adobe Employee
August 6, 2024

Try this, you can define the constant for OOB fmdita service user in custom constant file.

 

try (ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(CustomConstants.FMDITA_SERVICE_USER_PARAMS)) {
if (resourceResolver == null) {
LOGGER.error("ResourceResolver is null");
response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
return;

 

djohn98390536
Level 4
August 6, 2024

Hi @vijendra1 we hv tried this but its failing in cloud .

djohn98390536
Level 4
August 6, 2024

Is the issue happening for only for this servlet or all servlets?


for this servlet only

kautuk_sahni
Community Manager
Community Manager
August 21, 2024

@djohn98390536 Did you find the suggestions from users helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni