Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Sling servlet blocked on rde but working on local

Avatar

Level 5

hi all,

 

need little help with this issue - my sling servlet is working correctly on local but throwing blocked error on rde.

my local is also an SDK with same version as rde hence should not have been an issue.

 

my sling servlet is capturing data from couple of fields and sending it to servlet.

the ajax call is written as below -

$.ajax({
type: "GET",
url: "/bin/ACL/lookup.json",
data: {
cgn: cgn.toString(),
cgi: cgi.toString(),
name: name
},
success: function(resp) {
console.log("Response is " + JSON.stringify(resp));
location.reload(true);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus);
alert("Error: " + errorThrown);
}
});

the data object is valid and forming correctly. the success function is not executing ofcourse and the error function is just displaying pop up with Status: Error

the servlet is registered by path and in the logs there are loggers for the get method but they are not being logged on rde.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Try removing the <form> tag if present or add event.preventDefault() on the click of submit button. This will ensure that the form submit action and ajax URL redirection do not conflict with each other. 

NS_BINDING_ABORTED error is suggestive of ajax's URL and form submit's action both running and cancelling ajax request action.

View solution in original post

11 Replies

Avatar

Community Advisor

It's probably because your local AEM runs on localhost:4502, and your rapid development environment runs on localhost:8080. Take a look at the network tab, and it is probably a CORS error. Take a look at the network tab, what do you see?

You need to configure your Configure Apache Sling Referrer Filter to allow all hosts names.

The Apache Sling Referrer Filter is a security feature that helps prevent Cross-Site Request Forgery (CSRF) attacks by checking the HTTP Referer header of incoming requests. When the filter is active, it ensures that requests to AEM's localhost:4502 only come from trusted sources (e.g., the AEM site itself) and not from unauthorized external domains.

If your local:8080 needs to make AJAX requests to the AEM environment running on localhost:4502, the Referrer Filter might block those requests, resulting in CORS issues.  

 

Although this tutorial mentioned about how to enable "POST" from postman to your local AEM environment, I think it should give you more insight on how to setup the referrer filter, https://sourcedcode.com/blog/aem/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client

 

Avatar

Level 5

@BrianKasingli- the RDE doesn't run on my localhost:8080 - It is a dedicated environment on the cloud and has program id as well as environment id. I am deploying the servlet via code and in the configuration json it is present in the project bundle. the servlet should run irrespective of the environment as we are not sending request from 8080 to 4502.

 

Avatar

Community Advisor

Can you share your request headers?

A screenshot from the Network tab will help.

 

Avatar

Level 5

the request headers are empty as well as response headers. on Firefox the request is shown as aborted while on chrome the request is shown as blocked.

 

Avatar

Community Advisor

Is there any subsequent call in network trace post the servlet call? Or the page getting refreshed post the servlet execution?

One of the reasons I can think of is trigger of another request before the servlet request could complete. A screenshot of the network trace will help in this case.

Avatar

Level 5

there's a call to the same page occurring with query params which is getting 200 ok and always following the servlet call.

on firefox the call is getting aborted by ns binding aborted error, this is due to another req aborting the first req. How can I resolve this?

 

 

Avatar

Correct answer by
Community Advisor

Try removing the <form> tag if present or add event.preventDefault() on the click of submit button. This will ensure that the form submit action and ajax URL redirection do not conflict with each other. 

NS_BINDING_ABORTED error is suggestive of ajax's URL and form submit's action both running and cancelling ajax request action.

Avatar

Administrator

@aem_noob We hope you found the AEM community valuable. We anticipate your return as either a learner or a contributor. The community benefits from SMEs like you. Please ask your AEM peers to join and contribute. Happy AEM learning!



Kautuk Sahni

Avatar

Community Advisor

@aem_noob can you post the error you are seeing in the browser console? Did you check if the Servlet was successfully installed/resolved? did you try to call it from Postman or any other external source?



Esteban Bustamante

Avatar

Level 5

the servlet was successfully resolved yes. We are calling it from our local machine to validate its working fine. It is on RDE the issue is present.