Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Calling Servlet through dispatcher loses Body payload data

Avatar

Level 2

I'm calling a servlet through POST method and passing data. When i tried to hit the author/publish instance directly, its working as expected.

Whereas when I'm hitting the servlet through dispatcher, the request payload data is coming as EMPTY.

 

Please share your inputs on the same

16 Replies

Avatar

Employee Advisor

Hi @vijaymanoharan 

Are you sure that the payload is empty and you are not getting a 404.
You get a 404 on dispatcher if servlet path is not allowed in the PUBLISH-FILTERS.

Can you please analyse the requests in network tab of dev-tools and post relevant screeenshots, so that we can guide further.

Thanks.

Avatar

Level 2

Hi @milind_bachani , the payload is coming as empty whereas the payload is a JSON which i'm passing.

 

Note: Im trying to hit the servlet through external server. 

Avatar

Employee Advisor

Hi @vijaymanoharan 

Since you are hitting from external server, I suspect few things :

 

  • Are clientheaders set in dispatcher config under /clientheaders
  • Are you explicitly handling CORS ? - You can test that using CORS chrome extension and hit the servlet and check
  • Since the request is coming from external server, the body might be sent as plain-text instead of application/json but since your servlet was expecting JSON it comes up empty
  • Lastly, can you please hit <dispatcher_domain>/bin/notification POST using postman or any other api platform and check the behaviour.
    • If it works fine on postman with body you are sending, then possibly you need to check the external server configuration.
    • If NOT, then it has something to do with dispatcher config. By doing this activity, we can actually figure out the root-cause and the server responsible for bringing up such issue.

Thanks.

Avatar

Level 2

@milind_bachani , 

 

1.I have added clientheaders in dispatcher.

 

2.The request comes in from Adobe IO and the request looks like following,

Request URL: dispatcherURL/bin/notification

Request method: POST

Content-type: application/json; charset=utf-8

accept-encoding: deflate,compress,identity

user-agent: Adobe/1.0

x-adobe-delivery-id: xxx-xxx-xxxxx-xxxxxxx

x-adobe-event-code: pipeline_execution_start

x-adobe-event-id: xxx-xxx-xxxxx-xxxxxxx

x-adobe-provider: cloudmanager

x-adobe-retry-count: 86

x-adobe-signature: xxxxxxxxxxxxxxxxxxxxxxx

 

3. Tried hitting request through postman, getting 404 error for dispatcher and working fine with Author instance.

 

 

Avatar

Employee Advisor

@vijaymanoharan 
for #3, Can you also try hitting <publisher_url>/bin/notfication in Postman and check the response, or it also gives a 404 ?

Avatar

Level 2

Its giving 404 error and i have placed the trace of dispatcher below

 

[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Found farm publishfarm for project.dev
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] checking [/bin/notification]
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] request URL has no extension: /bin/notification
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] cache-action for [/bin/notification]: NONE
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] Filter rule entry /005 allowed 'POST /bin/notification HTTP/1.1'
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Reusing connection: 10.44.1.98:4503
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Connected to backend 0 (10.44.1.98:4503)
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.uri = "/bin/notification"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Content-Type] = "application/json; charset=utf-8"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Via] = "1.1 project.dev (dispatcher)"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[X-Forwarded-For] = "10.44.1.98"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Server-Agent] = "Communique-Dispatcher"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Host] = "10.44.1.98:4503"
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Sending request body to remote server
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Request body sent to remote server
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] No socket reuse: neither GET nor HEAD
[Fri Jan 07 08:25:11 2022] [I] [pid 6550] "POST /bin/notification" 500 none [publishfarm/0] 8ms
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Found farm publishfarm for project.dev

Avatar

Employee Advisor

hi @vijaymanoharan 

I would further like you to check that your servlet code has been deployed to publisher and you are able to resolve the servlet at :
<publisher_url>/system/console/servletresolver 
add path /bin/notification choose method as POST and click on resolve and check what candidates say.

Also, I presume that you have added /bin path to execution paths in Apache Sling Servlet/Script Resolver and Error Handler config (in /system/console/configMgr)

Avatar

Level 2

The servlet path is resolving in servletresolver and /bin path is available under that particular config.

Avatar

Employee Advisor

@vijaymanoharan Strange, it gets resolved on publisher but gives 404 on dispatcher - Is the dispatcher rendered from correct publisher ?
Check /renders on your dispatcher config. 

Avatar

Community Advisor

Hi @vijaymanoharan 

 

What does the servlet url look like?

Can you please check the dispatcher any file for '/filter' section 

For Eg: For /bin/test/myservlet
/0001 { /type "allow" /url "/bin/test/myservlet*" }

Also we can check the dispatcher debug and trace logs if any information regarding this is noted.

 

Thanks

 

Avatar

Level 2

Hi @Shubham_borole ,

 

The dispatcher filter file allows the particular path.

 

The dispatcher.log shows the trace as follow

 

[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Found farm publishfarm for project.dev
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] checking [/bin/notification]
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] request URL has no extension: /bin/notification
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] cache-action for [/bin/notification]: NONE
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] Filter rule entry /005 allowed 'POST /bin/notification HTTP/1.1'
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Reusing connection: 10.44.1.98:4503
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Connected to backend 0 (10.44.1.98:4503)
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.uri = "/bin/notification"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Content-Type] = "application/json; charset=utf-8"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Via] = "1.1 project.dev (dispatcher)"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[X-Forwarded-For] = "10.44.1.98"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Server-Agent] = "Communique-Dispatcher"
[Fri Jan 07 08:25:11 2022] [T] [pid 6550] request.headers[Host] = "10.44.1.98:4503"
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Sending request body to remote server
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Request body sent to remote server
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] No socket reuse: neither GET nor HEAD
[Fri Jan 07 08:25:11 2022] [I] [pid 6550] "POST /bin/notification" 500 none [publishfarm/0] 8ms
[Fri Jan 07 08:25:11 2022] [D] [pid 6550] Found farm publishfarm for project.dev

 

Note: I'm trying to hit the servlet from external server

Avatar

Community Advisor

Do you have any other servlets that use the /bin based servlet resolutions and are working?

Avatar

Level 2

Yeah, they are working.

Even the same servlet works for GET Method.

 

I'm assuming is this something to do with the firewall which is blocking the data 

Avatar

Level 3

Hi @vijaymanoharan - The dispatcher log shows 500 as the response code, are you sure that you see 404(not found) as response code? In case of 500, you need to look into error.log of your publish instance. 

 

 

Avatar

Level 2

The error code 500 is coming because im trying to do operations with the payload data. due to which, 500 error code comes in @harish_malineni 

Avatar

Level 3

@vijaymanoharan - OK!!

URL rewrite happens on the request before it get passed to dispatcher module. And this redirection will not carry the payload data. Please check, in browser console or using redirect trace(Chrome plugin) or in Apache redirect.log, whether the /bin/notification underwent any redirection. I suspect either of the below two redirects might have applied,

1. SSL force redirection, like below

ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]

2. A default passthrough (highly unlikely)

RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [PT,L]

 

If none the above and the scenarios mentioned by @milind_bachani is causing the issue then try changing the servlet path. Or rather than path try registering the servlet with resourceType.