How to call Servlet/Sling model for Custom Action type in Forms
Hi,
I have created custom form action to invoke third party API after submitting the AEM form container. Now I want to call the Servlet which will have code for the api call. When I select custom action in the form container it asking for the id. Plese help.


and here is my sevlet code
package com.adobe.aem.FormsDemo.core.servlets;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
@Component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=JSON path based servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.paths=" + "/bin/postservletexample" })public class CustomServlet {
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
try {
URL url = new URL("https://mocki.io/v1/8a06b1d3-cda3-4e9e-a767-fdc662311718");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "application/json");
int status = connection.getResponseCode();
System.out.println(status);
if (status!=0){
response.getWriter().write("Success");
}else{
response.getWriter().write("Failed");
}
// response.setStatus(SlingHttpServletResponse.SC_OK);
} catch (IOException e) {
e.printStackTrace();
}
}
}