Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Can not access a servlet via Ajax from dispatcher (404 - not found)

Avatar

Level 2

Hi everyone, I'm facing an issue when accessing a servlet (POST) via ajax from dispatcher.

Everything works well in my local and author mode.I've removed POST method in "com.adobe.granite.csrf.impl.CSRFFilter.cfg" as well as allowed the path in filters.any.

Here's my config: 

Ajax call

luongpham1994_2-1664095463207.png

Servlet

luongpham1994_3-1664095490665.png

filters.any

luongpham1994_0-1664095400224.png

CSRFFilter

luongpham1994_1-1664095422146.png

Do you guys have any idea for this issue? Please correct me if i'm wrong in any step.

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi everyone, My issue has been resolved, The code is correct at all. I just forgot to uncheck ignore web tier configuration on a pipeline configuration. So the dispatcher wasn't deployed

 
 
 
 

 

View solution in original post

1 Reply

Avatar

Level 2

As you have already confirmed it works fine in local publisher (it means you have enabled post method in servlet class and felix config also). I believe your servlet path is /bin/pdf/view and in filters.any it is allowing only GET method in your screenshot. Just allow post method for the same path.

Avatar

Level 2

Thanks, @shashi_c .You probably misunderstood something. I registered the sling servlet that I mentioned above as resourceType with selector = 'dataForm' and extension = 'json'. the path bin/pdf/view is another servlet.

Avatar

Employee

Test the following:

1. Test your servlet on publisher directly, you can use postman for it.

If the servlet is working fine on the publisher, then

2. Check dispatcher logs for any error for your servlet path

3. Also, you can try updating your rule 0107 by adding /method "POST"

 

Avatar

Level 2

Hi @Mohit_KBansal .

I tested the servlet on postman and it returned the same issue as dispatcher. (404 not found)

luongpham1994_0-1664172762161.png

 

Avatar

Level 2

I just set a dispatcher up on local and i worked well. Not sure how it didn't work on server 😞

Avatar

Level 4

Hi @luongpham1994 

In Filter.any file have you allowed the Post servlet that you have registered through resourceType. Can't see it in attached screen print.

Avatar

Level 2

Yes, I did. 

I tested it on the local dispatcher, When committed to the allowed path, The path is not found, and it worked again when uncommented. So I think the filters is working correctly

luongpham1994_0-1664191986704.png

 

Avatar

Correct answer by
Level 2

Hi everyone, My issue has been resolved, The code is correct at all. I just forgot to uncheck ignore web tier configuration on a pipeline configuration. So the dispatcher wasn't deployed