Expand my Community achievements bar.

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

Avatar

Level 4

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;

@component(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);

@reference
private ResourceResolverFactory resourceResolverFactory;
@Override
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();
}
}
}
}

6 Replies

Avatar

Employee

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;

 

Avatar

Employee

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

Avatar

Employee

@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/advance... 

 

I hope this helps.

Avatar

Administrator

@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