View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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          // TODO allow config: either use local session or remote session
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         // TODO Auto-generated method stub
112         super.doPost(request, response);
113     }
114 }