2 * WebConfig - a web administration interface for the Funambol DS Server.
3 * Copyright (C) 2008 Mathew McBride
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net
.bionicmessage
.funambol
.webconfig
;
20 import com
.funambol
.framework
.tools
.beans
.BeanException
;
21 import com
.funambol
.server
.config
.Configuration
;
22 import com
.google
.gson
.Gson
;
23 import com
.google
.gson
.reflect
.TypeToken
;
24 import java
.io
.IOException
;
25 import java
.io
.PrintWriter
;
26 import java
.util
.HashMap
;
28 import javax
.servlet
.ServletException
;
29 import javax
.servlet
.http
.HttpServlet
;
30 import javax
.servlet
.http
.HttpServletRequest
;
31 import javax
.servlet
.http
.HttpServletResponse
;
32 import javax
.servlet
.http
.HttpSession
;
33 import net
.bionicmessage
.funambol
.clickatell
.ClickatellSender
;
39 public class smsconfig
extends HttpServlet
{
41 private static final String CONFIGURED_BEAN
= "smsnotify/bmclickatell/bmclickatell.xml";
42 private static final String EXAMPLE_BEAN
= "smsnotify/bmclickatell/bmclickatell.example.xml";
44 protected ClickatellSender
getBean(Configuration conf
) throws BeanException
{
45 ClickatellSender sender
= null;
47 sender
= (ClickatellSender
) conf
.getBeanInstanceByName(CONFIGURED_BEAN
, false);
49 } catch (Exception e
) {
52 return (ClickatellSender
) conf
.getBeanInstanceByName(EXAMPLE_BEAN
, false);
56 * Handles the HTTP <code>GET</code> method.
57 * @param request servlet request
58 * @param response servlet response
60 protected void doGet(HttpServletRequest request
, HttpServletResponse response
)
61 throws ServletException
, IOException
{
62 HttpSession session
= request
.getSession();
63 PrintWriter out
= response
.getWriter();
65 if (session
.getAttribute("isadministrator") == null) {
66 throw new Exception("Not logged in as administrator");
68 Configuration c
= Configuration
.getConfiguration();
69 ClickatellSender sender
= getBean(c
);
70 Map values
= new HashMap();
71 values
.put("httpaddr", sender
.getClickatellURL());
72 values
.put("smsuser", sender
.getClickatellUser());
73 values
.put("smsid", sender
.getClickatellID());
74 Gson gson
= new Gson();
75 out
.println(gson
.toJson(values
, new TypeToken
<Map
<String
, String
>>() {
77 response
.setContentType("application/json;charset=utf-8");
78 } catch (Exception e
) {
79 response
.setContentType("text/plain;charset=utf-8");
80 response
.setStatus(500);
81 e
.printStackTrace(out
);
88 * Handles the HTTP <code>POST</code> method.
89 * @param request servlet request
90 * @param response servlet response
92 protected void doPost(HttpServletRequest request
, HttpServletResponse response
)
93 throws ServletException
, IOException
{
94 HttpSession session
= request
.getSession();
95 PrintWriter out
= response
.getWriter();
96 boolean isAdministrator
= (session
.getAttribute("isadministrator") != null);
98 Configuration c
= Configuration
.getConfiguration();
99 ClickatellSender sender
= getBean(c
);
100 String httpaddr
= request
.getParameter("httpaddr");
101 String smsuser
= request
.getParameter("smsuser");
102 String smspass
= request
.getParameter("smspass");
103 String smsid
= request
.getParameter("smsid");
104 sender
.setClickatellURL(httpaddr
);
105 sender
.setClickatellUser(smsuser
);
106 if (smspass
.length() > 0) {
107 sender
.setClickatellPass(smspass
);
109 sender
.setClickatellID(smsid
);
110 c
.setBeanInstance(CONFIGURED_BEAN
, sender
);
111 out
.println("Success");
112 response
.setContentType("text/plain;charset=utf-8");
113 } catch (Exception e
) {
114 e
.printStackTrace(out
);
115 response
.setContentType("text/plain;charset=utf-8");
122 * Returns a short description of the servlet.
124 public String
getServletInfo() {
125 return "SMS sender configuration";