1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.servlet;
24
25 import java.io.IOException;
26 import java.io.PrintWriter;
27 import java.util.Enumeration;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import javax.servlet.ServletConfig;
32 import javax.servlet.ServletException;
33 import javax.servlet.ServletOutputStream;
34 import javax.servlet.http.HttpServlet;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37
38 import de.bea.domingo.DNotesException;
39 import de.bea.domingo.DNotesFactory;
40 import de.bea.domingo.DSession;
41 import de.bea.domingo.server.DomingoServer;
42
43
44 /***
45 * TODO.
46 *
47 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
48 */
49 public final class DomingoServlet extends HttpServlet {
50
51 /*** serial version ID for serialization. */
52 private static final long serialVersionUID = -4964947433973323738L;
53
54 /*** Reference to a domingo session associated with this servlet. */
55 private DSession session;
56
57 /*** Reference to the domingo factory. */
58 private DNotesFactory fFactory;
59
60 /***
61 * {@inheritDoc}
62 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
63 */
64 public void init(final ServletConfig config) throws ServletException {
65 super.init(config);
66 fFactory = DNotesFactory.getInstance();
67 session = fFactory.getSession();
68
69 }
70
71 /***
72 * @see javax.servlet.Servlet#destroy()
73 */
74 public void destroy() {
75 fFactory.disposeInstance();
76 super.destroy();
77 }
78
79 /***
80 * {@inheritDoc}
81 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
82 */
83 protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
84 IOException {
85 final Map parameters = new HashMap();
86 final Enumeration enumeration = request.getParameterNames();
87 while (enumeration.hasMoreElements()) {
88 final String name = (String) enumeration.nextElement();
89 parameters.put(name, request.getParameterValues(name));
90 }
91 final DomingoServer server = new DomingoServer();
92 final ServletOutputStream stream = response.getOutputStream();
93 final PrintWriter printWriter = new PrintWriter(stream);
94 try {
95 server.execute(session, parameters, printWriter);
96 } catch (UnsupportedOperationException e) {
97 e.printStackTrace();
98 } catch (DNotesException e) {
99 e.printStackTrace();
100 } catch (IOException e) {
101 e.printStackTrace();
102 }
103 }
104
105 /***
106 * {@inheritDoc}
107 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
108 */
109 protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
110 IOException {
111
112 super.doPost(request, response);
113 }
114 }