1 19 20 package org.netbeans.modules.httpserver; 21 22 import java.io.IOException ; 23 import java.util.HashSet ; 24 import java.net.InetAddress ; 25 import java.util.Set ; 26 import javax.servlet.*; 27 import javax.servlet.http.*; 28 29 import org.openide.util.NbBundle; 30 import org.openide.ErrorManager; 31 import org.openide.util.SharedClassObject; 32 33 38 public abstract class NbBaseServlet extends HttpServlet { 39 40 41 public void init() throws ServletException { 42 } 43 44 48 protected abstract void processRequest(HttpServletRequest request, HttpServletResponse response) 49 throws ServletException, java.io.IOException ; 50 51 55 protected void doGet(HttpServletRequest request, HttpServletResponse response) 56 throws ServletException, java.io.IOException { 57 processRequest(request, response); 58 } 59 60 64 protected void doPost(HttpServletRequest request, HttpServletResponse response) 65 throws ServletException, java.io.IOException { 66 processRequest(request, response); 67 } 68 69 72 public String getServletInfo() { 73 return NbBundle.getBundle(NbBaseServlet.class).getString("MSG_BaseServletDescr"); 74 } 75 76 80 protected boolean checkAccess(HttpServletRequest request) throws IOException { 81 82 HttpServerSettings settings = HttpServerSettings.getDefault(); 83 if (settings == null) 84 return false; 85 86 if (settings.getHostProperty ().getHost ().equals(HttpServerSettings.ANYHOST)) 87 return true; 88 89 Set hs = settings.getGrantedAddressesSet(); 90 91 if (hs.contains(request.getRemoteAddr().trim())) 92 return true; 93 94 String pathI = request.getPathInfo(); 95 if (pathI == null) 96 pathI = ""; try { 99 String address = request.getRemoteAddr().trim(); 100 if (settings.allowAccess(InetAddress.getByName(address), pathI)) return true; 101 } catch (Exception ex) { 102 ErrorManager.getDefault().notify(ex); 103 return false; 104 } 105 106 return false; 107 } 108 109 } 110 | Popular Tags |