001/* 002 * Download.java 003 * $Id: Download.java 465 2005-03-29 04:52:58Z tgutwin $ 004 * $HeadURL$ 005 * $Revision$ 006 * $LastChangedDate: 2005-03-28 20:52:58 -0800 (Mon, 28 Mar 2005) $ 007 * $LastChangedBy: tgutwin $ 008 * Copyright (c) 2002-2005 Tom B. Gutwin P.Eng. 009 * 010 * This program is free software; you can redistribute it and/or 011 * modify it under the terms of the GNU General Public License 012 * as published by the Free Software Foundation; either version 2 013 * of the License, or any later version. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 018 * GNU General Public License for more details. 019 * 020 * You should have received a copy of the GNU General Public License 021 * along with this program; if not, write to the Free Software 022 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 023 */ 024package ca.bc.webarts.servlet; 025 026import ca.bc.webarts.tools.rainforest.EagleUploader; 027 028import java.io.BufferedReader; 029import java.io.File; 030import java.io.FileNotFoundException; 031import java.io.FileOutputStream; 032import java.io.FileReader; 033import java.io.FileWriter; 034import java.io.FileInputStream; 035import java.io.IOException; 036import java.io.InputStream; 037import java.net.InetAddress; 038import java.net.MalformedURLException; 039import java.net.URL; 040import java.net.UnknownHostException; 041 042import javax.servlet.*; 043import javax.servlet.http.*; 044 045/** 046 * 047 * @author tgutwin 048 * @created August 14, 2014 049 */ 050public class EagleUploaderListener extends HttpServlet 051{ 052 // implements SingleThreadModel 053 054 /** Description of the Field */ 055 private final static String SYSTEM_FILE_SEPERATOR = File.separator; 056 /** Version String. */ 057 private final static String SERVLET_VERSION = "a0.1"; 058 059 /** Build String. (yymmddhhss) */ 060 private final static String BUILD_TAG = "1408141701"; 061 062 private static String webServerHostName_ = "localhost"; 063 064 private EagleUploader eu_ = null; 065 /** 066 * Gets the ServletInfo attribute of the JavaMailServlet object 067 * 068 * @return The ServletInfo value 069 */ 070 public String getServletInfo() 071 { 072 final String methodName = "getServletInfo"; 073 return "WebARTS Design EagleUploaderListener servlet. Version:" + SERVLET_VERSION + 074 " Build:" + BUILD_TAG; 075 } 076 077 078 /** 079 * The one time servlet init stuff goes here. 080 **/ 081 public void init() 082 { 083 System.out.println("Initializing webarts.servlet.EagleUploaderListener"); 084 085 eu_ = new EagleUploader(); 086 // First get our data persitance model started Logger running 087 eu_.initPersister(); 088 089 try 090 { 091 webServerHostName_ = InetAddress.getLocalHost().getHostName(); 092 } 093 catch (UnknownHostException ex) 094 { 095 webServerHostName_ = "localhost"; 096 } 097 } 098 099 100 /** Override to close up the persister * */ 101 public void destroy() 102 { 103 super.destroy(); 104 eu_.closePersister(); 105 } 106 107 108 /** 109 * This method handles the "GET" submission - SHOULD NEVER be called by the Eagle. 110 * 111 * @param req Description of the Parameter 112 * @param res Description of the Parameter 113 * @exception ServletException Description of the Exception 114 * @exception IOException Description of the Exception 115 */ 116 public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 117 { 118 119 } 120 121 122 /** 123 * This method handles the "POST" submission - the default way the Eagle send messages. 124 * 125 * @param req Description of Parameter 126 * @param res Description of Parameter 127 * @exception ServletException Description of Exception 128 * @exception IOException Description of Exception 129 */ 130 public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 131 { 132 StringBuffer postBody = new StringBuffer(""); 133 String line = null; 134 try 135 { 136 BufferedReader reader = req.getReader(); 137 while ((line = reader.readLine()) != null) 138 postBody.append(line+"\n"); 139 140 String euReply = eu_.newMessage(postBody.toString()); 141 142 // send back a reply 143 if (euReply==null || euReply.equals("")) 144 { 145 // send back a 200 with an empty body 146 res.setStatus(HttpServletResponse.SC_OK); 147 res.setContentType("application/xml"); 148 res.setContentLength(0); 149 euReply = ""; 150 } 151 else 152 { 153 // send back the euReply as the body 154 res.setStatus(HttpServletResponse.SC_OK); 155 res.setContentType("application/xml"); 156 res.setContentLength(euReply.length()); 157 } 158 ServletOutputStream out = res.getOutputStream(); 159 out.println("\n"+euReply); 160 } 161 catch (Exception e) 162 { /*report an error*/ } 163 164 } 165}