📄 crmservlet.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * CRMServlet.java * * Created on 24 March 2003, 01:58 */package crms.servlet;import java.io.*;import java.net.*;import javax.servlet.*;import javax.servlet.http.*;import org.w3c.dom.*;import javax.xml.parsers.*;import crms.dao.*;import crms.form.*;import org.apache.log4j.*;import crms.module.*;import crms.util.*;import java.beans.*;import java.util.*;/** * * @author dmurphy */public class CRMServlet extends HttpServlet { static Logger logger = Logger.getLogger(CRMServlet.class); public static String ARG_MODE = "mode"; public static String ARG_SUB_MODE = "submode"; public static String ARG_DATA = "data"; public DAOFactory factory = null; /** Initializes the servlet. */ public void init() throws ServletException { ServletConfig config = getServletConfig(); if (config == null) { System.out.println("Servlet config is null."); } if (config.getServletContext() == null) { System.out.println("Servlet context is null..."); } else { System.out.println( "Context: " + config.getServletContext().getServletContextName()); } logger.debug("Initialising..."); // Create the instance of the DAOFactory factory = DAOFactory.getInstance(); factory.registerDatabase(getInitParameter("db-server"), getInitParameter("db-name"), getInitParameter("db-user"), getInitParameter("db-password"), getInitParameter("db-init-conn"), getInitParameter("db-max-conn") ); logger.debug("Complete."); LDAPDAOFactory ldapFactory = LDAPDAOFactory.getInstance(getInitParameter("ldap-url"), getInitParameter("ldap-basedn"), getInitParameter("ldap-userou")); logger.debug("Initialised ldapFactory with url: " + getInitParameter("ldap-url")); String formDir = getInitParameter("form-dir"); String realFormPath = getServletContext().getRealPath(formDir); FormFactory.getInstance().setFormDirectory(new File(realFormPath)); } /** Destroys the servlet. */ public void destroy() { factory.cleanup(); } /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/xml"); PrintWriter out = response.getWriter(); String command = URLDecoder.decode(request.getParameter("command"), "UTF-8"); // This is pretty big output... :-) //logger.debug("CRMS Request command XML: " + command); StringBuffer buf = new StringBuffer(); ServerCommand serverCommand = null; ServerResponse sr = null; if (command != null) { // This is the new form of command passing to the server // it comes in as an XML 'command object' // First, convert the XML back into a ServerCommand object try { ByteArrayInputStream bIn = new ByteArrayInputStream(command.getBytes()); XMLDecoder decoder = new XMLDecoder(bIn); serverCommand = (ServerCommand) decoder.readObject(); decoder.close(); logger.debug("Got command:"); logger.debug(serverCommand.getKey()); if (serverCommand.getKey().equals("system.ping")) { sr = new ServerResponse(); sr.addPart("ping", "ping"); } else if (serverCommand.getKey().toLowerCase().startsWith(CallModule.PREFIX)) { logger.debug("Processing CallModule command..."); CallModule module = new CallModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(CompanyModule.PREFIX)) { logger.debug("Processing CompanyModule command..."); CompanyModule module = new CompanyModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(ContactModule.PREFIX)) { logger.debug("Processing ContactModule command..."); ContactModule module = new ContactModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(ReminderModule.PREFIX)) { logger.debug("Processing ReminderModule command..."); ReminderModule module = new ReminderModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(NoteModule.PREFIX)) { logger.debug("Processing NoteModule command..."); NoteModule module = new NoteModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(StaffModule.PREFIX)) { logger.debug("Processing StaffModule command..."); StaffModule module = new StaffModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(LastContactModule.PREFIX)) { logger.debug("Processing LastContactModule command..."); LastContactModule module = new LastContactModule(); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(FileAttachmentModule.PREFIX)) { logger.debug("Processing FileAttachmentModule command..."); FileAttachmentModule module = new FileAttachmentModule(getServletConfig().getInitParameter(FileUploadServlet.PARAM_FILE_LOCATION)); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith(PermissionModule.PREFIX)) { logger.debug("Processing PermissionModule command..."); PermissionModule module = new PermissionModule(); logger.debug("command is: " + serverCommand.getKey() ); sr = module.processCommand(serverCommand); } else if (serverCommand.getKey().toLowerCase().startsWith("report.")) { logger.debug("Processing ReportModule command.."); ReportModule module = new ReportModule(); sr = module.processCommand(serverCommand); } } catch (Exception ex) { ex.printStackTrace(); logger.error("Exception processing request from " + request.getRemoteHost() + ": command=[" + serverCommand.getKey() +"]"); logger.fatal(ex); } } else { logger.error("Unknown request from " + request.getRemoteHost() ); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); // XMLEncoder sysout = new XMLEncoder(System.out);// sysout.writeObject(sr);// sysout.flush();// sysout.close(); XMLEncoder encoder = new XMLEncoder(bout); encoder.writeObject(sr); encoder.flush(); encoder.close(); buf.append(bout.toString()); out.write(buf.toString()); out.flush(); out.close(); } /** Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Returns a short description of the servlet. */ public String getServletInfo() { return "Short description"; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -