Expand my Community achievements bar.

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

Cannot Access the Servlet

Avatar

Level 2

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

 

Please find below the below codeScreenshot 2024-05-02 at 10.19.47 PM.png

 

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


Topics

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

9 Replies

Avatar

Community Advisor

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

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

 

Avatar

Community Advisor

@Punitha77 Open /system/console/configMgr and search for "Apache Sling Servlet/Script Resolver and Error Handler" and add "/geeks/" under execution path and test it. 

Saravanan_Dharmaraj_0-1714744121546.png

Also verify if the /bin/executeworkflow path works in servlet resolver

 

https://www.youtube.com/watch?v=VNXGF6p0zdM&t=393s

 

 

 

Avatar

Level 2

@Saravanan_Dharmaraj  I have tried to add to /geeksdemo/ and even /geeks/ as you said to "Apache Sling Servlet/Script Resolver and Error Handler"

 

Screenshot 2024-05-05 at 6.45.23 PM.png

Screenshot 2024-05-05 at 6.45.58 PM.png

 

 

Trying to access-http://localhost:4504/bin/executeworkflow?page=content/geeksdemo/us/my-practice-page

Error Message

Resource at '/bin/executeworkflow' not found: No resource found

Cannot serve request to /bin/executeworkflow in /libs/sling/servlet/errorhandler/404.jsp

Request Progress:

      0 TIMER_START{Request Processing}
      3 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>
     16 LOG Method=GET, PathInfo=null
     21 TIMER_START{handleSecurity}
   2339 TIMER_END{2316,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@28ef7bac returns true
   2652 TIMER_START{ResourceResolution}
   2840 TIMER_END{186,ResourceResolution} URI=/bin/executeworkflow resolves to Resource=NonExistingResource, path=/bin/executeworkflow
   2851 LOG Resource Path Info: SlingRequestPathInfo: path='/bin/executeworkflow', selectorString='null', extension='null', suffix='null'
   2852 TIMER_START{ServletResolution}
   2855 TIMER_START{resolveServlet(/bin/executeworkflow)}
   4130 LOG {0}: no servlet found
   4143 TIMER_END{1286,resolveServlet(/bin/executeworkflow)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet
   4148 TIMER_END{1295,ServletResolution} URI=/bin/executeworkflow handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet
   4159 LOG Applying Requestfilters

 

 

Screenshot 2024-05-05 at 6.46.30 PM.png

Avatar

Community Advisor

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

Avatar

Community Advisor

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

Avatar

Level 2

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

Avatar

Community Advisor

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



Esteban Bustamante

Avatar

Administrator

@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