Cannot Access the Servlet | Community
Skip to main content
Level 2
May 2, 2024

Cannot Access the Servlet

  • May 2, 2024
  • 4 replies
  • 1764 views

I have tried to Launch the workflow through code  and got the below error

 

Please find below the below code

 

package com.geeks.demo.core.servlets;

import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.model.WorkflowModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletPaths;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;

@Component(service = Servlet.class)
@SlingServletPaths(
value={"/bin/executeworkflow","/geeksdemo/executeworkflow"}
)

public class ExecuteWorkflow extends SlingSafeMethodsServlet {
private static final Logger LOG = LoggerFactory.getLogger(ExecuteWorkflow.class);

@Override
protected void doGet(final SlingHttpServletRequest req, SlingHttpServletResponse res) throws ServletException, IOException{
String status ="Workflow Executing";
final ResourceResolver resourceResolver = req.getResourceResolver();

String payload=req.getRequestParameter("page").getString();
try {
if (StringUtils.isNotBlank(payload)) {
WorkflowSession workflowSession = resourceResolver.adaptTo(WorkflowSession.class);

WorkflowModel workflowModel = workflowSession.getModel("/var/workflow/models/practice-creation-version-");
WorkflowData workflowData = workflowSession.newWorkflowData("JCR_PATH", payload);
workflowSession.startWorkflow(workflowModel, workflowData);
}
} catch(Exception e){
LOG.info("/n Error in Workflow{}", e.getMessage());
}
}



}


Steps Tried
1. Added /geeksdemo/ in the execution path of Apache Sling servlet/ Script Resolver and Error Handler
2. Added -/content/geeksdemo/um in Apache Sling Authentication Service

Please share your suggestion

Thanks,
Punitha


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

4 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
May 2, 2024

@punitha77 Could you please check servlet url in servlet resolver and see how its resolving?

http://localhost:4502/system/console/servletresolver

 

Punitha77Author
Level 2
May 3, 2024

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 6, 2024

Hi, 

Did you check if the bundle is activated? And then if the servlet is registered and exported? The code looks ok, so double-check that the code is installed correctly. You could try to remove all the bundle and reinstall it again, to make sure the latest code is being deployed.

 

Hope this helps

Esteban Bustamante
diksha_mishra
Community Advisor
Community Advisor
May 7, 2024

@punitha77 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Punitha77Author
Level 2
May 8, 2024

@diksha_mishra I tried both it didn't work for me. Still trying to figure out the issue

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 8, 2024

If you go to your bundle, can you check if your servlet is correctly exported?, can you provide a sc?

Esteban Bustamante
kautuk_sahni
Community Manager
Community Manager
May 16, 2024

@punitha77 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni