This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
Hi,
do you have any tutorial on how to create servlet and call it from react?
I did this, I create one servlet like that
and I call it in react like that
and I got this error in console
How can I solve it?
Views
Replies
Total Likes
I hope you're trying to call the servlet from AEM itself, did you try by removing localhost:4502 and just use something like post('/bin/login', fromData) and see how it works.
I tried to change it to get method, it works fine
any idea way post not work?
You can try steps as mentioned by @Anmol_Bhardwaj
Also for more details:
If you are testing from an HTTP Client such as postman, you will need to configure the "Apache Sling Referrer Filter" and "Adobe Granite CSRF Filter". Otherwise, if your AEM page is making an HTTP Post request, it should be working as expected with only the "Apache Sling Referrer Filter" configured without the CSRF Filter.
Can you try this and see if it works:
If your requests are getting blocked, this should fix it.
- Please check if you have implemented SlingHttpSafeServlet or AllMethodServlet in your servlet.
- Try to call the same servlet through Postman and see if it is working fine
So you're getting the same error in Postman, after allowing empty in the Sling?
The filter code looks good, but what about the servlet code? Is it implementing SlingAllMethodServlet?
Also, if the request doesn't get blocked, even if the servlet doesn't have a doPost method, it is not blocked, rather it just does nothing and sends 200.
So, I'm guessing the issue lies with blocking of the request.
Try to first send the request and get a 200 through Postman. This should help you get better clarity on the underlying issue.
yes I tried on Postman and I got same
Here is the response from Postman
################################################################
################################################################
The request to /bin/login is served using OOTB servlet and not your custom servlet.
2294 TIMER_END{11,ServletResolution} URI=/bin/login handled by Servlet=com.day.cq.auth.impl.LoginServlet
com.day.cq.auth.impl.LoginServlet - OOTB servlet registered with path - /bin/login and it overrides GET method alone and hence the error, POST is not allowed (405)
Suggest to change the path specific to your project (say, /bin/exampleproject/login) or register the servlet with resourceType.
Hi,
I tried your change, but still not work
it give me 500 (server error)
and in postman a message unable to create node at /bin/my
#################################################
######### Logs from Adobe Console ##################
#################################################
0 TIMER_START{Request Processing}
6 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>
17 LOG Method=POST, PathInfo=null
21 TIMER_START{handleSecurity}
2725 TIMER_END{2701,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@1c918f96 returns true
3293 TIMER_START{ResourceResolution}
3581 TIMER_END{285,ResourceResolution} URI=/bin/my/login resolves to Resource=NonExistingResource, path=/bin/my/login
3597 LOG Resource Path Info: SlingRequestPathInfo: path='/bin/my/login', selectorString='null', extension='null', suffix='null'
3598 TIMER_START{ServletResolution}
3605 TIMER_START{resolveServlet(/bin/my/login)}
5260 LOG {0}: no servlet found
5278 TIMER_END{1669,resolveServlet(/bin/my/login)} Using servlet org.apache.sling.servlets.post.impl.SlingPostServlet
5289 TIMER_END{1689,ServletResolution} URI=/bin/my/login handled by Servlet=org.apache.sling.servlets.post.impl.SlingPostServlet
5300 LOG Applying Requestfilters
5310 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl
5324 LOG Calling filter: org.apache.sling.security.impl.ContentDispositionFilter
5332 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
5338 LOG Calling filter: com.adobe.granite.httpcache.impl.InnerCacheFilter
5355 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
5360 LOG Calling filter: com.adobe.cq.mcm.campaign.servlets.CampaignCopyTracker
5367 LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter
5723 LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
5744 LOG Calling filter: com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet
5754 LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter
5763 LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
5768 LOG Calling filter: com.adobe.cq.social.commons.cors.CORSAuthenticationFilter
5774 LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
5778 LOG Calling filter: com.aem.core.filters.LoggingFilter
5786 LOG Calling filter: com.aem.geeks.core.filters.LoggingFilter
5792 LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
5798 LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl
5984 LOG Calling filter: com.adobe.granite.csrf.impl.CSRFFilter
5993 LOG Calling filter: com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter
5998 LOG Calling filter: com.adobe.granite.requests.logging.impl.RequestLoggerImpl
6010 LOG Calling filter: com.adobe.granite.rest.impl.servlet.ApiResourceFilter
6059 LOG Calling filter: com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler
6065 LOG Calling filter: com.day.cq.dam.core.impl.servlet.ActivityRecordHandler
6091 LOG Calling filter: com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet
6101 LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter
6116 LOG Applying Componentfilters
6119 LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter
6123 LOG Calling filter: com.day.cq.wcm.core.impl.page.PageLockFilter
6133 LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
6166 LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
6185 TIMER_START{org.apache.sling.servlets.post.impl.SlingPostServlet#0}
6314 LOG Calling PostOperation: org.apache.sling.servlets.post.impl.operations.ModifyOperation
10117 TIMER_END{3928,org.apache.sling.servlets.post.impl.SlingPostServlet#0}
10158 LOG Filter timing: filter=com.day.cq.wcm.core.impl.WCMDebugFilter, inner=4, total=4, outer=0
10164 LOG Filter timing: filter=com.day.cq.wcm.core.impl.WCMComponentFilter, inner=4, total=4, outer=0
10167 LOG Filter timing: filter=com.day.cq.wcm.core.impl.page.PageLockFilter, inner=4, total=4, outer=0
10177 TIMER_END{10176,Request Processing} Request Processing
10186 LOG Filter timing: filter=com.adobe.cq.dtm.reactor.impl.servlets.ClientLibraryFilter, inner=0, total=4, outer=4
10189 LOG Filter timing: filter=com.adobe.cq.dam.webdav.impl.io.DamWebdavRequestFilter, inner=4, total=4, outer=0
10192 LOG Filter timing: filter=com.day.cq.wcm.core.impl.warp.TimeWarpFilter, inner=4, total=4, outer=0
10194 LOG Filter timing: filter=com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet, inner=4, total=4, outer=0
10197 LOG Filter timing: filter=com.adobe.cq.dtm.impl.servlets.DTMLibraryCompatibilityFilter, inner=4, total=4, outer=0
10200 LOG Filter timing: filter=com.day.cq.dam.core.impl.servlet.DamContentDispositionFilter, inner=4, total=4, outer=0
10202 LOG Filter timing: filter=com.day.cq.dam.core.impl.servlet.ActivityRecordHandler, inner=4, total=4, outer=0
10205 LOG Filter timing: filter=com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler, inner=4, total=4, outer=0
10208 LOG Filter timing: filter=com.adobe.granite.rest.impl.servlet.ApiResourceFilter, inner=4, total=4, outer=0
10210 LOG Filter timing: filter=com.adobe.granite.requests.logging.impl.RequestLoggerImpl, inner=4, total=4, outer=0
10213 LOG Filter timing: filter=com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter, inner=4, total=4, outer=0
10215 LOG Filter timing: filter=com.adobe.granite.csrf.impl.CSRFFilter, inner=4, total=4, outer=0
10218 LOG Filter timing: filter=com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl, inner=4, total=4, outer=0
10220 LOG Filter timing: filter=com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter, inner=4, total=4, outer=0
10223 LOG Filter timing: filter=com.aem.geeks.core.filters.LoggingFilter, inner=4, total=4, outer=0
10226 LOG Filter timing: filter=com.aem.core.filters.LoggingFilter, inner=4, total=4, outer=0
10228 LOG Filter timing: filter=org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter, inner=4, total=4, outer=0
10231 LOG Filter timing: filter=com.adobe.cq.social.commons.cors.CORSAuthenticationFilter, inner=4, total=4, outer=0
10233 LOG Filter timing: filter=com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet, inner=4, total=4, outer=0
10235 LOG Filter timing: filter=com.adobe.granite.optout.impl.OptOutFilter, inner=4, total=4, outer=0
10238 LOG Filter timing: filter=com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet, inner=4, total=4, outer=0
10241 LOG Filter timing: filter=com.day.cq.wcm.core.impl.WCMRequestFilter, inner=4, total=4, outer=0
10243 LOG Filter timing: filter=com.adobe.cq.history.impl.HistoryRequestFilter, inner=4, total=5, outer=1
10246 LOG Filter timing: filter=com.adobe.cq.mcm.campaign.servlets.CampaignCopyTracker, inner=5, total=5, outer=0
10248 LOG Filter timing: filter=org.apache.sling.rewriter.impl.RewriterFilter, inner=5, total=5, outer=0
10250 LOG Filter timing: filter=com.adobe.granite.httpcache.impl.InnerCacheFilter, inner=5, total=5, outer=0
10253 LOG Filter timing: filter=org.apache.sling.i18n.impl.I18NFilter, inner=5, total=5, outer=0
10255 LOG Filter timing: filter=org.apache.sling.security.impl.ContentDispositionFilter, inner=5, total=5, outer=0
10258 LOG Filter timing: filter=org.apache.sling.distribution.servlet.DistributionAgentCreationFilter, inner=5, total=5, outer=0
Looks like your servlet is not available in the instance at first place.
3581 TIMER_END{285,ResourceResolution} URI=/bin/my/login resolves to Resource=NonExistingResource, path=/bin/my/login
3597 LOG Resource Path Info: SlingRequestPathInfo: path='/bin/my/login', selectorString='null', extension='null', suffix='null'
3598 TIMER_START{ServletResolution}
3605 TIMER_START{resolveServlet(/bin/my/login)}
5260 LOG {0}: no servlet foundCross check the deployment and see if you are able to see the servlet in
http://localhost:4502/system/console/components and is active
or
http://localhost:4502/system/console/servletresolver Enter the servlet path and choose the method to be POST and see if it resolves to your servlet.
This means your bundle (that contains the servlet code) is not deployed to the AEM instance.
How are you deploying your code ?
using command
mvn clean install -PautoInstallPackage
Since it is your local instance, delete the bundle manually from this path - /apps/yourproject/install/yourproject.core-0.0.1-SNAPSHOT.jar in CRXDE and then trigger the deployment again.
(Provided core module is enabled and bundle is getting created successfully as part of the build process)
I tried that not solved.
I found the below error on bundle console
and the project in install state not active
Just dealing with the same error here, I came around this article that may be helpful:
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Like
Replies