I am using the Observable
and Observer
classes from java.util
package.
I have the following in my Observable
class
public class IfxHistoryObservable extends Observable {
public void inputHistoryUpdate(
SomeDto inputHistoryDto,
String type) {
JSONObject data = new JSONObject();
data.put("changeType", type);
data.put("changedData", inputHistoryDto);
setChanged();
notifyObservers(data);
}
}
Observer class
public class IfxHistoryObserver implements Observer {
@Override
public void update(Observable o, Object param) {
JSONObject data = (JSONObject)param;
SomeDto dto = data.get("changedData")
ifxSecurityService.filterDataBasedOnUserSession(dto) //query regarding this line
}
}
whenever any dto is added or updated, I want to notify all the users. However, before I notify I want it to pass through a security service where it checks if the user has the authority to view.
We are using Spring in Java. When I call the security function to check for authority, I get the following error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.ifxSecurityService': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
The scope for ifxSecurityService
bean is request and it can't be changed.
I checked that the user session information is not available inside the observer. What is the correct way to implement this?