Hi All,
SlingHttpServletRequest object is null when i am passing it from WCMuse class to an OSGI service . why it will behave like that. Also when we do an getRequest in WCMUse class it returns an org.apache.sling.scripting.core.impl.helper.OnDemandReaderRequest object instead of org.apache.sling.api.SlingHttpServletRequest object. Sample code is as below
public class MyWrapperClass extends WCMUse {
private SlingHttpServletRequest request;
@Override
public void activate() {
request = getRequest(); //here the request object is returning org.apache.sling.scripting.core.impl.helper.OnDemandReaderRequest how we can get org.apache.sling.api.SlingHttpServletRequest
String str = getSlingScriptHelper().getService(MyService.class).myMethod(request);
}
}
@Component (immediate=true, enabled=true)
@Service (value = MyInterface.class)
public class MyService implements MyInterface {
@Override
public String myMethodyMethod(SlingHttpServletRequest request){
request.setAttribute("example","example");// here the request object is coming as null
return "true";
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
Why do you need to pass the request object to OSGI service? It is better not to pass the request object to the backend components and rather pass the information in the request to the backend component using POJO objects or standard data types. You should not couple your services code with the front end code by using the request object.
You can get the SlingHttpServletRequest object by calling the following method-
request = getRequest().getSlingRequest();
Views
Replies
Total Likes
You are re-check on your project and make sure you are using below dependencies for Sightly.
<
<
<
<
<
</
<
<
<
<
<
</
And, it seems to know that you are referencing to sling
Jitendra
Views
Replies
Total Likes
Why do you need to pass the request object to OSGI service? It is better not to pass the request object to the backend components and rather pass the information in the request to the backend component using POJO objects or standard data types. You should not couple your services code with the front end code by using the request object.
You can get the SlingHttpServletRequest object by calling the following method-
request = getRequest().getSlingRequest();
Views
Replies
Total Likes
Agree with kunal23 - get the request object in the Sling Servlet using method in the servlet - do not pass it to a servlet. Also - most times - people use servlets to perform tasks in Java. For example - use the AEM Java AssetManager API. What you are trying to do in the servlet that you cannot perform in the Sightly Java class?
Views
Replies
Total Likes
Yes, I also agree with kunal's comment. Its better to pass the information using POJO classes from backend components. Do not pass the request objects to OSGI Service.
We have many community articles that contains use cases in this link: https://helpx.adobe.com/marketing-cloud/experience-manager.html
Thanks,
Ratna Kumar.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies