Expand my Community achievements bar.

SOLVED

Servlet path not resolving

Avatar

Level 4

I have a project that has path based several servlets. For some, the path resolves and for some others, not.

Using the path in the Sling Servlet Resolver, the path is not resolved to the servlet configured to handle the request.

Checking the system/console/components page, I can locate the servlet. When I open up the details for the servlet, it states that it is resolved, the sling.servlet.paths setting shows the correct path for the servlet. I also see the sling.servlet.methods is set with the GET method that the servlet supports.

 

Any ideas of what I need to do in order to resolve this issue? I'm assuming if I solve for one, I can solve for others.

1 Accepted Solution

Avatar

Correct answer by
Level 4
  • It is resolved. I don't see any errors in the log other than there is an error when the request comes in for that path.
  • I look in the component list and I can find the servlet listed. Opening the detail, it shows that it is active, the sling.servlet.paths has the path in question listed.
  • Switching to the Sling Servlet Resolver page and copying the path from the component detail page, clearly showing the path configured in the code, then switching to the POST method that the servlet is listening for, and the resolver cannot find a servlet to support that path.

Very strange.

View solution in original post

15 Replies

Avatar

Community Advisor

More insights for your review:

1. You are hitting the servlets directly in an author instance? publish? Is there a chance that some of the servlets are specific to a run mode? (REQUIRED) 

2. Which type of annotations are you using? OSGI R6? R7? Can you post the signature of how the servlet is being declared? Maybe that can provide more insight into what's going on

3. Do you have other candidates when you use the sling servlet resolver? Can this be an issue related to the ranking option?

4. Did you compare the servlets which are working vs the servlets which are working? Is there any outstanding difference?



Esteban Bustamante

Avatar

Level 4

Right now, the request is made when editing pages on my local instance. There is no run mode assignment.

This is from old code that was running in 6.2 and the annotations are from the felix project. That shouldn't be the issue because there are other servlets using the same annotations that are resolving. I haven't been able to determine the patter of why one resolves when another does not. There aren't any path conflicts. For each servlet, the paths are unique. 

Avatar

Community Advisor

The state of your servlet should be active, that is clearly the problem, Is there any error logging out if you try to reload or start the component from the /system/console/components/xxx ? 

Esteban666_0-1686679656777.png

Usually, an OSGI component can't start when a required field is missing. Can you post your servlet signature?



Esteban Bustamante

Avatar

Correct answer by
Level 4
  • It is resolved. I don't see any errors in the log other than there is an error when the request comes in for that path.
  • I look in the component list and I can find the servlet listed. Opening the detail, it shows that it is active, the sling.servlet.paths has the path in question listed.
  • Switching to the Sling Servlet Resolver page and copying the path from the component detail page, clearly showing the path configured in the code, then switching to the POST method that the servlet is listening for, and the resolver cannot find a servlet to support that path.

Very strange.

Avatar

Level 4

So I'll add this in case it helps someone else.

Most of the issues were fixe by adding the servlet and service packages to the <Export-Package> section of the POM files.

I still would not see errors in the log files when starting the bundles. How I discovered the issues with the remaining servlets that weren't starting was to open the /system/console/components page, finding the servlets that were marked as "satisfied" but were not active. I would then disable the servlet and then enable it and I saw that they were failing because of ClassNotFound errors. I'd resolve them, usually by refactoring the code, and then updating the bundles and the servlets would become active.

I hope this may help someone else come to a quicker resolution if they have the same issue.

Avatar

Community Advisor

Can you add a logger to your servlet and then try to enable/disable the servlet via /system/console/components URL?

If you get a log printed, it will give you some idea about the condition of your servlet.

 

Also, could you try to pick one servlet, remove all the code, and just put the log to see if it is getting called when it needs to be triggered?

Avatar

Community Advisor

Also, yes if your status of servlet is not "Active", then this means that you may have some dependencies to resolve. Can you verify if all bundles are "Active"? 

Avatar

Community Advisor

@RobertHarperFS 

 

Please check whether the path used by servlet is registered in "Apache Sling Servlet/Script Resolver and Error Handler" console

Ganthimathi_R_0-1686714953027.png

 

If youre using path other than /bin please make sure to register that path say for example if your using path as http://localhost:4502/xyz in that case resigter it as http://localhost:4502/xyz.servlet mention same in "Apache Sling Servlet/Script Resolver and Error Handler" as /xyz.servlet.

 

Hope this helps in resolving it.

 

Regards

 

Avatar

Community Advisor

Hello @RobertHarperFS 

 

1. You have mentioned that on visiting the component/servlet via http://localhost:4502/system/console/components , the status is "Active".

That should mean that dependencies are resolved.

 

2.  We need to check is executable paths are configured. Please update "Apache Sling Servlet/Script Resolver and Error Handler", as @Ganthimathi_R suggested.

 

3.  Next, we need to check, if the POST operation is blocked. For that, add a dummy GET method to servlet and make a call. Repeat the same action for POST servlet as well.

If the GET is successful, then the POST operation is blocked. 

Please check for any errors related to CSRF. Please refer to:

https://sourcedcode.com/blog/video-tutorial/how-to-make-simple-http-post-methods-in-aem-with-a-http-...

 

 

 

 


Aanchal Sikka

Avatar

Community Advisor

@RobertHarperFS  if you check the bundle and you can see that your servlet should show as "unsatisfied" state.

 

And as suggested by @rawvarun  can you add more logs and see if your servlet is even getting called. and you should  resigter it as http://localhost:4502/xyz.servlet mention same in "Apache Sling Servlet/Script Resolver and Error Handler" as /xyz.servlet.

The servlet in question, and others, show the state as resolved. If I stop and start the servlet in the components page, there are errors not seen when the bundle starts stating the implementation class cannot be found. When I look at the detail for the bundle that the servlet is part of, I see that it is being exported but that the state is only resolved. There isn't any detail as to why it isn't activating other than the implementation class could not be loaded. There isn't any more detail than that.

Avatar

Level 4
  1. Logs aren't showing what the problem is. No stack traces based on the resolution.
  2. It looks like the issue is with the OSGI configuration classes. They are being resolved but not transitioning to the "active" state so I'm sure this is the root issue.
  3. Adding log messages to the servlet or the configuration service aren't of any help. I think the issue is before any of the code in the classes is being executed.

Avatar

Level 4

One of my coworkers found an issue with the POM file. It looks like the package for the configuration classes wasn't included in the export list. I could see them in the bundle so I thought they should resolve.

Avatar

Level 1

I know this issue is resolved, but we had a similar issue that was caused by a service dependency that failed to start because of missing OSGi configurations. 

Servlet: OK

Service: OK

Service OSGi factory configurations: Missing (a side effect of a migration)

Therefore service wouldn't start, which cascaded to the Servlet not registering.

 

Posted in case anyone else comes across this post and this might help.