Expand my Community achievements bar.

Making post requests to external API in AEM author

Avatar

Level 4

We're trying to connect to a new external API for a custom servlet in AEM author but we're getting the following error:
Response: {"error":{"code":"404","message": "Resource not found"}}

 

We've added the excluded path to the Adobe Granite CRSF Filter and the allowed host to the Apache Sling Referrer Filter. Also we can make post requests to the API using Postman without any issues. Thanks for any advice.

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

5 Replies

Avatar

Community Advisor

Do you see any error in console or error log? Did you try with GET method also, is that working?

can you please provide your Servlet class definition (how you defined) and how you are calling in HTL

 

above configurations are looking good

CSRF Filter and Referrer Filter

Add the servlet path /bin/mycustompost to the Adobe Granite CSRF Filter's excluded paths.

Add the external API host to the Apache Sling Referrer Filter's allowed hosts.

 

@Component(service = Servlet.class,
property = {
ServletResolverConstants.SLING_SERVLET_PATHS + "=/bin/mycustompost",
ServletResolverConstants.SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_POST
})
public class CustomPostServlet extends SlingAllMethodsServlet {


<form id="customPostForm">
<input type="text" name="key" placeholder="Enter value" required>
<button type="submit">Submit</button>
</form

<script>
document.getElementById('customPostForm').addEventListener('submit', function(event) {
event.preventDefault();
var formData = new FormData(this);
fetch('/bin/mycustompost', {
method: 'POST',
body: formData
})
.then(response => response.json())

----

Avatar

Community Advisor

Hi @stiegjo22 ,

Which error you are getting when you try aem servlet endpoint(post) request from postman?

There may be following reason for 404-

  • Check if any typo in the url of external Api getting used in servlet.
  • Most probably you may be configuring the endpoint in configuration and using in servlet, if that is the case check the configuration value.
  • Servlet might be not getting registered so check the annotation and imports

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/servlet-in-satisfied-statu...

Thanks

Avatar

Level 4

Now I'm seeing an error related to SSL certificate validation. The PKIX path building failed error indicates that the Java runtime is unable to find a valid certification path to the requested target, which means the SSL certificate of the target server is not trusted by the Java truststore.

 

11.10.2024 11:52:59.734 *ERROR* Error generating description: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Avatar

Administrator

@stiegjo22 Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni