1 package com.dotmarketing.servlets; 2 3 import java.io.File ; 4 import java.io.FileNotFoundException ; 5 import java.io.IOException ; 6 import java.io.PrintWriter ; 7 import java.net.HttpURLConnection ; 8 import java.net.URL ; 9 10 import javax.servlet.ServletConfig ; 11 import javax.servlet.ServletException ; 12 import javax.servlet.http.HttpServlet ; 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 16 import com.bitmechanic.spindle.Spider; 17 import com.dotmarketing.beans.Host; 18 import com.dotmarketing.factories.HostFactory; 19 import com.dotmarketing.util.Config; 20 import com.dotmarketing.util.Logger; 21 22 28 29 public class BuildSearchServlet extends HttpServlet { 30 31 private static final long serialVersionUID = 1L; 32 33 final static boolean VERBOSE = false; 34 35 public void init(ServletConfig config) throws ServletException { 36 37 } 38 39 44 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 45 46 PrintWriter out = response.getWriter(); 47 response.setContentType("text/plain"); 48 49 Host h = HostFactory.getCurrentHost(request); 50 51 String _serverName = h.getHostname(); 52 53 55 File testDirectory = new File (com.dotmarketing.util.Config.CONTEXT.getRealPath("/WEB-INF/spindle/" + _serverName)); 56 testDirectory.mkdirs(); 57 58 Logger.info(this, "Running spindle indexing"); 59 Logger.info(this, "\tUsing HostFactory.getCurrentHost(request) to get servername\n\ttry different url virtual host if this is wrong"); 60 61 Logger.info(this, "\n\n\n\n\ncom.dotmarketing.util.Config.CONTEXT.getRealPath(\"/WEB-INF/spindle\")=" 62 + com.dotmarketing.util.Config.CONTEXT.getRealPath("/WEB-INF/spindle")); 63 Logger.info(this, "Indexing: " + "http://" + _serverName + Config.getStringProperty("SPINDLE_PATH_TO_INDEX")); 64 65 String [] argv = new String [] { "-d", testDirectory.getAbsolutePath(), "-u", 67 "http://" + _serverName + Config.getStringProperty("SPINDLE_PATH_TO_INDEX"), "-dt", "p", "-dt", "h1", "-dt", "h2", "-dt", "h3", "-e", 68 "/c/", "-e", "/calendar/", "-e", "/dot/", "-v" }; 69 70 try { 71 URL u = new URL ("http://" + _serverName + Config.getStringProperty("SPINDLE_PATH_TO_INDEX")); 72 HttpURLConnection uc; 73 String ct = ""; 74 uc = (HttpURLConnection ) u.openConnection(); 75 uc.setAllowUserInteraction(false); 76 ct = uc.getContentType(); 77 Logger.info("Detected content type for " + "http://" + _serverName + "/" + ": '" + ct + "'"); 78 } catch (FileNotFoundException e) { 79 } 80 81 try { 82 Spider s = new Spider(argv); 83 s.go(); 84 } catch (Exception e) { 85 out.println("Exception Searching: " + e); 86 out.println(e.getStackTrace()); 87 } 88 89 for (int i = 0; i < argv.length; i++) { 90 out.println(argv[i]); 91 } 92 out.println("------------------------------------------"); 93 out.println("SEARCHING"); 94 out.println("------------------------------------------"); 95 96 out.flush(); 97 out.close(); 98 99 } 100 101 } 102 | Popular Tags |