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();
}
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
@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.
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;
}
Hi @Vijendra1 we hv tried this but its failing in cloud .
Is the issue happening for only for this servlet or all servlets?
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/advance...
I hope this helps.
@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!
Views
Replies
Total Likes
Views
Likes
Replies