I have a servlet method where i need to pass a json object. This json object will be created in one of the managed bean(JSF). I just tried injecting the bean into the servlet to get the json object, but i am getting runtime exception, may be it is not possible that way. So i want to call the servlet from JSF bean. Any ideas how to call from the bean?
Servlet
private static final long serialVersionUID = 1L;
TopicController topicController;
TopicBean topicBean;
List<JsonTopicObj> jsonTopicList;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
// here code for subscription
Meteor mateor = Meteor.build(req).addListener(
new MyAtmosphereResourceEventListener());
boolean isLongPolling = true;
if (mateor.transport() == LONG_POLLING) {
isLongPolling = true;
} else {
isLongPolling = false;
}
System.out.println(" Now in the Get method of Atmosphere");
// create the broadcaster for the particular topic
String topicId = "default"; // for all users right now
Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup(
topicId, true);
//set that broeadcaster
mateor.setBroadcaster(broadcaster);
mateor = mateor.resumeOnBroadcast(isLongPolling);
mateor.suspend(-1);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {}
JSF BEAN
@ManagedBean(name = "testController")
@RequestScoped
public void listAllTopics() {
JsonTopicObj jsonTopicObj;
StringWriter out = new StringWriter();
JsonFactory jfactory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper();
jsonTopicList = new ArrayList<JsonTopicObj>();
for (int i = 0; i < topicBean.getTopicVOArray().length; i++) {
jsonTopicObj = new JsonTopicObj();
......................
}
mapper.writeValue(out, jsonTopicList);
now i need to call the servlet dopost method and send "out.toString()"