1
|
package eu.etaxonomy.cdm.vaadin.servlet;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import javax.servlet.ServletException;
|
6
|
|
7
|
import org.apache.log4j.Logger;
|
8
|
|
9
|
import com.vaadin.server.ServiceException;
|
10
|
import com.vaadin.server.SessionDestroyEvent;
|
11
|
import com.vaadin.server.SessionDestroyListener;
|
12
|
import com.vaadin.server.SessionInitEvent;
|
13
|
import com.vaadin.server.SessionInitListener;
|
14
|
import com.vaadin.server.VaadinServlet;
|
15
|
import com.vaadin.server.VaadinSession;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
19
|
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
|
20
|
|
21
|
|
22
|
public class CdmVaadinConversationalServlet extends VaadinServlet implements SessionInitListener, SessionDestroyListener {
|
23
|
|
24
|
private static final Logger logger = Logger.getLogger(CdmVaadinConversationalServlet.class);
|
25
|
|
26
|
private static final long serialVersionUID = -2973231251266766766L;
|
27
|
|
28
|
private ConversationHolder conversation;
|
29
|
|
30
|
|
31
|
@Override
|
32
|
protected void servletInitialized() throws ServletException {
|
33
|
super.servletInitialized();
|
34
|
getService().addSessionInitListener(this);
|
35
|
getService().addSessionDestroyListener(this);
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
public void sessionInit(SessionInitEvent event)
|
40
|
throws ServiceException {
|
41
|
conversation = (ConversationHolder) CdmSpringContextHelper.getCurrent().getBean("conversationHolder");
|
42
|
conversation.bind();
|
43
|
VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_CONVERSATION, conversation);
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public void sessionDestroy(SessionDestroyEvent event) {
|
48
|
conversation.close();
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
protected void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException, IOException {
|
53
|
if(conversation != null) {
|
54
|
logger.info("Servlet Service call - Binding Vaadin Session Conversation : " + conversation);
|
55
|
conversation.bind();
|
56
|
}
|
57
|
|
58
|
super.service(request, response);
|
59
|
}
|
60
|
|
61
|
|
62
|
}
|