Java 类javax.servlet.GenericServlet 实例源码

项目:spring4-understanding    文件:FreeMarkerView.java   
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
    if (getConfiguration() != null) {
        this.taglibFactory = new TaglibFactory(servletContext);
    }
    else {
        FreeMarkerConfig config = autodetectConfiguration();
        setConfiguration(config.getConfiguration());
        this.taglibFactory = config.getTaglibFactory();
    }

    GenericServlet servlet = new GenericServletAdapter();
    try {
        servlet.init(new DelegatingServletConfig());
    }
    catch (ServletException ex) {
        throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
    }
    this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
项目:kc-rice    文件:FreeMarkerInlineRenderBootstrap.java   
/**
 * Initialize FreeMarker elements after servlet context and FreeMarker configuration have both
 * been populated.
 */
private static void finishConfig() {
    if (freeMarkerConfig != null && servletContext != null) {
        taglibFactory = new TaglibFactory(servletContext);

        objectWrapper = freeMarkerConfig.getObjectWrapper();
        if (objectWrapper == null) {
            objectWrapper = ObjectWrapper.DEFAULT_WRAPPER;
        }

        GenericServlet servlet = new ServletAdapter();
        try {
            servlet.init(new DelegatingServletConfig());
        } catch (ServletException ex) {
            throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
        }

        servletContextHashModel = new ServletContextHashModel(servlet, ObjectWrapper.DEFAULT_WRAPPER);

        LOG.info("Freemarker configuration complete");
    }
}
项目:class-guard    文件:FreeMarkerView.java   
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
    if (getConfiguration() != null) {
        this.taglibFactory = new TaglibFactory(servletContext);
    }
    else {
        FreeMarkerConfig config = autodetectConfiguration();
        setConfiguration(config.getConfiguration());
        this.taglibFactory = config.getTaglibFactory();
    }

    GenericServlet servlet = new GenericServletAdapter();
    try {
        servlet.init(new DelegatingServletConfig());
    }
    catch (ServletException ex) {
        throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
    }
    this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
项目:g3server    文件:PluginServlet.java   
/**
 * Returns the correct servlet with mapping checks.
 *
 * @param pathInfo the pathinfo to map to the servlet.
 * @return the mapped servlet, or null if no servlet was found.
 */
private GenericServlet getServlet(String pathInfo) {
    pathInfo = pathInfo.substring(1).toLowerCase();

    GenericServlet servlet = servlets.get(pathInfo);
    if (servlet == null) {
        for (String key : servlets.keySet()) {
            int index = key.indexOf("/*");
            String searchkey = key;
            if (index != -1) {
                searchkey = key.substring(0, index);
            }
            if (searchkey.startsWith(pathInfo) || pathInfo.startsWith(searchkey)) {
                servlet = servlets.get(key);
                break;
            }
        }
    }
    return servlet;
}
项目:rice    文件:FreeMarkerInlineRenderBootstrap.java   
/**
 * Initialize FreeMarker elements after servlet context and FreeMarker configuration have both
 * been populated.
 */
private static void finishConfig() {
    if (freeMarkerConfig != null && servletContext != null) {
        taglibFactory = new TaglibFactory(servletContext);

        objectWrapper = freeMarkerConfig.getObjectWrapper();
        if (objectWrapper == null) {
            objectWrapper = ObjectWrapper.DEFAULT_WRAPPER;
        }

        GenericServlet servlet = new ServletAdapter();
        try {
            servlet.init(new DelegatingServletConfig());
        } catch (ServletException ex) {
            throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
        }

        servletContextHashModel = new ServletContextHashModel(servlet, ObjectWrapper.DEFAULT_WRAPPER);

        LOG.info("Freemarker configuration complete");
    }
}
项目:openfire    文件:PluginServlet.java   
/**
 * Returns the correct servlet with mapping checks.
 *
 * @param pathInfo the pathinfo to map to the servlet.
 * @return the mapped servlet, or null if no servlet was found.
 */
private GenericServlet getServlet(String pathInfo) {
    pathInfo = pathInfo.substring(1).toLowerCase();

    GenericServlet servlet = servlets.get(pathInfo);
    if (servlet == null) {
        for (String key : servlets.keySet()) {
            int index = key.indexOf("/*");
            String searchkey = key;
            if (index != -1) {
                searchkey = key.substring(0, index);
            }
            if (searchkey.startsWith(pathInfo) || pathInfo.startsWith(searchkey)) {
                servlet = servlets.get(key);
                break;
            }
        }
    }
    return servlet;
}
项目:gwtutil    文件:Freemarker.java   
private static Configuration getCfg(GenericServlet servlet) throws IOException {
    String localeStr = "default";
    Locale gwtLocale = LocaleProxy.getLocale();
    if (gwtLocale != null) {
        localeStr = gwtLocale.toString();
    }
    Configuration cfg = cfgs.get(localeStr);
    if (cfg == null) {
        cfg = new Configuration(Configuration.getVersion());
        cfg.setDirectoryForTemplateLoading(new File(servlet.getServletContext().getRealPath("/WEB-INF/templates")));
        cfg.setDefaultEncoding("UTF-8");
        if (gwtLocale != null) {
            cfg.setLocale(gwtLocale);
        }
        cfgs.put(localeStr, cfg);
    }
    return cfg;
}
项目:openfire-bespoke    文件:PluginServlet.java   
/**
 * Returns the correct servlet with mapping checks.
 *
 * @param pathInfo the pathinfo to map to the servlet.
 * @return the mapped servlet, or null if no servlet was found.
 */
private GenericServlet getServlet(String pathInfo) {
    pathInfo = pathInfo.substring(1).toLowerCase();

    GenericServlet servlet = servlets.get(pathInfo);
    if (servlet == null) {
        for (String key : servlets.keySet()) {
            int index = key.indexOf("/*");
            String searchkey = key;
            if (index != -1) {
                searchkey = key.substring(0, index);
            }
            if (searchkey.startsWith(pathInfo) || pathInfo.startsWith(searchkey)) {
                servlet = servlets.get(key);
                break;
            }
        }
    }
    return servlet;
}
项目:smart-cache    文件:Utils.java   
public static Boolean getBoolean(GenericServlet servlet, String key) {
    String property = servlet.getInitParameter(key);
    if ("true".equals(property)) {
        return Boolean.TRUE;
    } else if ("false".equals(property)) {
        return Boolean.FALSE;
    }
    return null;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SampleServletApplication.java   
@SuppressWarnings("serial")
@Bean
public Servlet dispatcherServlet() {
    return new GenericServlet() {
        @Override
        public void service(ServletRequest req, ServletResponse res)
                throws ServletException, IOException {
            res.setContentType("text/plain");
            res.getWriter().append("Hello World");
        }
    };
}
项目:spring-boot-concourse    文件:SampleServletApplication.java   
@SuppressWarnings("serial")
@Bean
public Servlet dispatcherServlet() {
    return new GenericServlet() {
        @Override
        public void service(ServletRequest req, ServletResponse res)
                throws ServletException, IOException {
            res.setContentType("text/plain");
            res.getWriter().append("Hello World");
        }
    };
}
项目:methodstats    文件:Utils.java   
public static Boolean getBoolean(GenericServlet servlet, String key) {
    String property = servlet.getInitParameter(key);
    if ("true".equals(property)) {
        return Boolean.TRUE;
    } else if ("false".equals(property)) {
        return Boolean.FALSE;
    }
    return null;
}
项目:contestparser    文件:SampleServletApplication.java   
@SuppressWarnings("serial")
@Bean
public Servlet dispatcherServlet() {
    return new GenericServlet() {
        @Override
        public void service(ServletRequest req, ServletResponse res)
                throws ServletException, IOException {
            res.setContentType("text/plain");
            res.getWriter().append("Hello World");
        }
    };
}
项目:olingo-odata2    文件:ODataServletTest.java   
private void prepareServlet(final GenericServlet servlet) throws Exception {
  // private transient ServletConfig config;
  Field configField = GenericServlet.class.getDeclaredField("config");
  configField.setAccessible(true);
  configField.set(servlet, configMock);

  String factoryClassName = ODataServiceFactoryImpl.class.getName();
  Mockito.when(configMock.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(factoryClassName);
}
项目:g3server    文件:PluginServlet.java   
/**
 * Unregisters all JSP page servlets for a plugin.
 *
 * @param webXML the web.xml file containing JSP page names to servlet class file
 *               mappings.
 */
public static void unregisterServlets(File webXML) {
    if (!webXML.exists()) {
        Log.error("Could not unregister plugin servlets, file " + webXML.getAbsolutePath() +
            " does not exist.");
        return;
    }
    // Find the name of the plugin directory given that the webXML file
    // lives in plugins/[pluginName]/web/web.xml
    String pluginName = webXML.getParentFile().getParentFile().getParentFile().getName();
    try {
        SAXReader saxReader = new SAXReader(false);
        saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
            false);
        Document doc = saxReader.read(webXML);
        // Find all <servelt-mapping> entries to discover name to URL mapping.
        List names = doc.selectNodes("//servlet-mapping");
        for (int i = 0; i < names.size(); i++) {
            Element nameElement = (Element)names.get(i);
            String url = nameElement.element("url-pattern").getTextTrim();
            // Destroy the servlet than remove from servlets map.
            GenericServlet servlet = servlets.get(pluginName + url);
            if (servlet != null) {
                servlet.destroy();
            }
            servlets.remove(pluginName + url);
            servlet = null;
        }
    }
    catch (Throwable e) {
        Log.error(e.getMessage(), e);
    }
}
项目:g3server    文件:PluginServlet.java   
/**
 * Handles a request for a JSP page. It checks to see if a servlet is mapped
 * for the JSP URL. If one is found, request handling is passed to it. If no
 * servlet is found, a 404 error is returned.
 *
 * @param pathInfo the extra path info.
 * @param request  the request object.
 * @param response the response object.
 * @throws ServletException if a servlet exception occurs while handling the request.
 * @throws IOException      if an IOException occurs while handling the request.
 */
private void handleJSP(String pathInfo, HttpServletRequest request,
                       HttpServletResponse response) throws ServletException, IOException {
    // Strip the starting "/" from the path to find the JSP URL.
    String jspURL = pathInfo.substring(1);

    GenericServlet servlet = servlets.get(jspURL);
    if (servlet != null) {
        servlet.service(request, response);
    }
    else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}
项目:g3server    文件:PluginServlet.java   
/**
 * Handles a request for a Servlet. If one is found, request handling is passed to it.
 * If no servlet is found, a 404 error is returned.
 *
 * @param pathInfo the extra path info.
 * @param request  the request object.
 * @param response the response object.
 * @throws ServletException if a servlet exception occurs while handling the request.
 * @throws IOException      if an IOException occurs while handling the request.
 */
private void handleServlet(String pathInfo, HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
    // Strip the starting "/" from the path to find the JSP URL.
    GenericServlet servlet = getServlet(pathInfo);
    if (servlet != null) {
        servlet.service(request, response);
    }
    else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}
项目:openfire    文件:PluginServlet.java   
/**
 * Unregisters all JSP page servlets for a plugin.
 *
 * @param webXML the web.xml file containing JSP page names to servlet class file
 *               mappings.
 */
public static void unregisterServlets(File webXML) {
    if (!webXML.exists()) {
        Log.error("Could not unregister plugin servlets, file " + webXML.getAbsolutePath() +
            " does not exist.");
        return;
    }
    // Find the name of the plugin directory given that the webXML file
    // lives in plugins/[pluginName]/web/web.xml
    String pluginName = webXML.getParentFile().getParentFile().getParentFile().getName();
    try {
        SAXReader saxReader = new SAXReader(false);
        saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
            false);
        Document doc = saxReader.read(webXML);
        // Find all <servelt-mapping> entries to discover name to URL mapping.
        List names = doc.selectNodes("//servlet-mapping");
        for (int i = 0; i < names.size(); i++) {
            Element nameElement = (Element)names.get(i);
            String url = nameElement.element("url-pattern").getTextTrim();
            // Destroy the servlet than remove from servlets map.
            GenericServlet servlet = servlets.get(pluginName + url);
            if (servlet != null) {
                servlet.destroy();
            }
            servlets.remove(pluginName + url);
            servlet = null;
        }
    }
    catch (Throwable e) {
        Log.error(e.getMessage(), e);
    }
}
项目:openfire    文件:PluginServlet.java   
/**
 * Registers a live servlet for a plugin programmatically, does not
 * initialize the servlet.
 * 
 * @param pluginManager the plugin manager
 * @param plugin the owner of the servlet
 * @param servlet the servlet.
 * @param relativeUrl the relative url where the servlet should be bound
 * @return the effective url that can be used to initialize the servlet
 */
public static String registerServlet(PluginManager pluginManager,
        Plugin plugin, GenericServlet servlet, String relativeUrl)
        throws ServletException {

    String pluginName = pluginManager.getPluginDirectory(plugin).getName();
    PluginServlet.pluginManager = pluginManager;
    if (servlet == null) {
        throw new ServletException("Servlet is missing");
    }
    String pluginServletUrl = pluginName + relativeUrl;
    servlets.put(pluginName + relativeUrl, servlet);
    return PLUGINS_WEBROOT + pluginServletUrl;

}
项目:openfire    文件:PluginServlet.java   
/**
 * Unregister a live servlet for a plugin programmatically. Does not call
 * the servlet destroy method.
 * 
 * @param plugin the owner of the servlet
 * @param url the relative url where servlet has been bound
 * @return the unregistered servlet, so that it can be destroyed
 */
public static GenericServlet unregisterServlet(Plugin plugin, String url)
        throws ServletException {
    String pluginName = pluginManager.getPluginDirectory(plugin).getName();
    if (url == null) {
        throw new ServletException("Servlet URL is missing");
    }
    String fullUrl = pluginName + url;
    GenericServlet servlet = servlets.remove(fullUrl);
    return servlet;
}
项目:openfire    文件:PluginServlet.java   
/**
 * Handles a request for a JSP page. It checks to see if a servlet is mapped
 * for the JSP URL. If one is found, request handling is passed to it. If no
 * servlet is found, a 404 error is returned.
 *
 * @param pathInfo the extra path info.
 * @param request  the request object.
 * @param response the response object.
 * @throws ServletException if a servlet exception occurs while handling the request.
 * @throws IOException      if an IOException occurs while handling the request.
 */
private void handleJSP(String pathInfo, HttpServletRequest request,
                       HttpServletResponse response) throws ServletException, IOException {
    // Strip the starting "/" from the path to find the JSP URL.
    String jspURL = pathInfo.substring(1);

    GenericServlet servlet = servlets.get(jspURL);
    if (servlet != null) {
        servlet.service(request, response);
    }
    else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}
项目:openfire    文件:PluginServlet.java   
/**
 * Handles a request for a Servlet. If one is found, request handling is passed to it.
 * If no servlet is found, a 404 error is returned.
 *
 * @param pathInfo the extra path info.
 * @param request  the request object.
 * @param response the response object.
 * @throws ServletException if a servlet exception occurs while handling the request.
 * @throws IOException      if an IOException occurs while handling the request.
 */
private void handleServlet(String pathInfo, HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
    // Strip the starting "/" from the path to find the JSP URL.
    GenericServlet servlet = getServlet(pathInfo);
    if (servlet != null) {
        servlet.service(request, response);
    }
    else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}
项目:gwtutil    文件:Freemarker.java   
public static Template getTemplate(GenericServlet servlet, String templateName) {
    try {
        return getCfg(servlet).getTemplate(templateName);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
项目:openfire-bespoke    文件:PluginServlet.java   
/**
 * Unregisters all JSP page servlets for a plugin.
 *
 * @param webXML the web.xml file containing JSP page names to servlet class file
 *               mappings.
 */
public static void unregisterServlets(File webXML) {
    if (!webXML.exists()) {
        Log.error("Could not unregister plugin servlets, file " + webXML.getAbsolutePath() +
            " does not exist.");
        return;
    }
    // Find the name of the plugin directory given that the webXML file
    // lives in plugins/[pluginName]/web/web.xml
    String pluginName = webXML.getParentFile().getParentFile().getParentFile().getName();
    try {
        SAXReader saxReader = new SAXReader(false);
        saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
            false);
        Document doc = saxReader.read(webXML);
        // Find all <servelt-mapping> entries to discover name to URL mapping.
        List names = doc.selectNodes("//servlet-mapping");
        for (int i = 0; i < names.size(); i++) {
            Element nameElement = (Element)names.get(i);
            String url = nameElement.element("url-pattern").getTextTrim();
            // Destroy the servlet than remove from servlets map.
            GenericServlet servlet = servlets.get(pluginName + url);
            if (servlet != null) {
                servlet.destroy();
            }
            servlets.remove(pluginName + url);
            servlet = null;
        }
    }
    catch (Throwable e) {
        Log.error(e.getMessage(), e);
    }
}
项目:openfire-bespoke    文件:PluginServlet.java   
/**
 * Handles a request for a JSP page. It checks to see if a servlet is mapped
 * for the JSP URL. If one is found, request handling is passed to it. If no
 * servlet is found, a 404 error is returned.
 *
 * @param pathInfo the extra path info.
 * @param request  the request object.
 * @param response the response object.
 * @throws ServletException if a servlet exception occurs while handling the request.
 * @throws IOException      if an IOException occurs while handling the request.
 */
private void handleJSP(String pathInfo, HttpServletRequest request,
                       HttpServletResponse response) throws ServletException, IOException {
    // Strip the starting "/" from the path to find the JSP URL.
    String jspURL = pathInfo.substring(1);

    GenericServlet servlet = servlets.get(jspURL);
    if (servlet != null) {
        servlet.service(request, response);
    }
    else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}
项目:openfire-bespoke    文件:PluginServlet.java   
/**
 * Handles a request for a Servlet. If one is found, request handling is passed to it.
 * If no servlet is found, a 404 error is returned.
 *
 * @param pathInfo the extra path info.
 * @param request  the request object.
 * @param response the response object.
 * @throws ServletException if a servlet exception occurs while handling the request.
 * @throws IOException      if an IOException occurs while handling the request.
 */
private void handleServlet(String pathInfo, HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
    // Strip the starting "/" from the path to find the JSP URL.
    GenericServlet servlet = getServlet(pathInfo);
    if (servlet != null) {
        servlet.service(request, response);
    }
    else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}
项目:gwtutil    文件:Freemarker.java   
public static void processTemplate(GenericServlet servlet, String templateName, Map<String, Object> params, HttpServletResponse resp)
        throws TemplateException, IOException {
    resp.setContentType("text/html; charset=utf-8");
    resp.setHeader("Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
    processTemplate(servlet, templateName, params, resp.getWriter());
}
项目:gwtutil    文件:Freemarker.java   
public static void processTemplate(GenericServlet servlet, String templateName, Map<String, Object> params, Writer writer)
        throws TemplateException, IOException {
    getCfg(servlet).getTemplate(templateName).process(params, writer);
}
项目:brjs-JsTestDriver    文件:RequestHandlersModule.java   
@Provides @Singleton ServletContext provideServletContext(Servlet servlet) {
  return ((GenericServlet) servlet).getServletContext();
}