Hi,
I have a use case where there is an already a servlet providing data of certain nodes in json format.
Now: There is a workflow which needs same json data to be pushed AWS S3 storage.
Trial 1: Is it possible to get a sling request in a workflow process step ?
I tried to common out all the reusable code out of servlet, but still there are references to request object.
Trial2: Used Apache HTTP Client api to make a call to servlet url and got anonymous user access not allowed, unauthorized.
Trial3: Used below code, even though servlet sending back all the response, bytearrayoutputstram does NOT have all the response.
String requestPath = "/srvpub/topnav.consumer.json " // servlet path
/* Setup request */
HttpServletRequest req = requestResponseFactory.createRequest("GET", requestPath);
WCMMode.DISABLED.toRequest(req);
/* Setup response */
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse resp = requestResponseFactory.createResponse(out);
/* Process request through Sling */
requestProcessor.processRequest(req, resp, request.getResourceResolver());
String html = out.toString();
Any help or ideas on what I am missing or working ways to solve this use case.
Thanks,
Sri
Solved! Go to Solution.
Views
Replies
Total Likes
Are you making the jcr query within servlet to get the node data and create json ? if so, I would recommend to move the the logic of querying the node data and getting a json to a service and your servlet should just call that service method to respond to the http request.
If you have this solution in place, then you can refer the same service and call the respective method within your workflow process aswell.
Basically, I would keep any logical processing in a service and make servlet as a delegate class. This would keep your implementation clean and make it more re-usable.
In your HTTP API Code that invokes the servlet to perform a GET- modify it so it authenticates - that will solve your issue.
Views
Replies
Total Likes
Are you making the jcr query within servlet to get the node data and create json ? if so, I would recommend to move the the logic of querying the node data and getting a json to a service and your servlet should just call that service method to respond to the http request.
If you have this solution in place, then you can refer the same service and call the respective method within your workflow process aswell.
Basically, I would keep any logical processing in a service and make servlet as a delegate class. This would keep your implementation clean and make it more re-usable.
Thanks,
Is it possible to get service user : user name , password from resource resolver?
or
Should I need to hard code a user name, password ?
Thanks again.
Views
Replies
Total Likes
you should be able to get the service user to login in your service.
how about accessing a servlet with resource resolver with service user ?
Views
Replies
Total Likes
I have never tried to access a Sling Servlet in this manner. You can try and see if it works. I have successfully used HTTP API code to invoke a servlet - which works fine.
You can try to test your code at 1st by hard-coding authentication. Then once that works - you can try to figure out a better way to get authentication information. Maybe place it in a deep node in the JCR which would be secure.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies