package com.***.core.servlets;
@Component(service = { Servlet.class })
@SlingServletResourceTypes(resourceTypes = "dcp/servlet/assets-locked", methods = HttpConstants.METHOD_GET, extensions = "json")
public class DCPLockedAssetsRequestServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
response.setContentType("application/json");
LOG.info("Forwarding POST request to author instance with Basic Authentication.");
CloseableHttpClient httpClient = HttpClients.createDefault();
// Adapt session and validate user
Session session = request.getResourceResolver().adaptTo(Session.class);
String userId = session.getUserID();
UserManager userManager = request.getResourceResolver().adaptTo(UserManager.class);
Map<String, String> payloadMap = new HashMap<String, String>();
currentUser = userManager.getAuthorizable(userId);
payloadMap.put("assetsPath", assetPath);
payloadMap.put("userId", userId);
payloadMap.put("userPath", currentUser.getPath().toString());
payloadMap.put("principalName", currentUser.getPrincipal().getName());
String authorServiceURL = techCredentialService.getAuthorServletURL();
// Prepare HTTP POST request to author
HttpPost postRequest = new HttpPost(authorServiceURL);
token = dcpUpdateUserService.getToken();
postRequest.setHeader("Authorization", "Bearer " + token);
postRequest.setHeader(***Constants.CONTENT_TYPE, ***Constants.CONTENT_TYPE_JSON);
postRequest.setEntity(new StringEntity(new Gson().toJson(payloadMap)));
// Execute the HTTP request
org.apache.http.HttpResponse authorResponse = httpClient.execute(postRequest);
if (statusCode == 200) {
String responseContent = EntityUtils.toString(authorResponse.getEntity());
JsonObject jsonResponse = new JsonObject();
jsonResponse.addProperty(***Constants.STATUS, "success");
jsonResponse.addProperty(***Constants.MESSAGE, "Workflow triggered successfully.");
response.getWriter().write(jsonResponse.toString());
}}
i am hitting this servlet from publisher,
through this servlet when i hit the author path i.e