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.
Solved! Go to Solution.
Views
Replies
Total Likes
Very strange.
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?
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.
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 ?
Usually, an OSGI component can't start when a required field is missing. Can you post your servlet signature?
Very strange.
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.
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?
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"?
Please check whether the path used by servlet is registered in "Apache Sling Servlet/Script Resolver and Error Handler" console
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
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:
@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.
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.
@RobertHarperFS then we might need to see the code once. DM me
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.
Views
Replies
Total Likes
Views
Likes
Replies