Search in sources :

Example 1 with EmbeddedServletOptions

use of org.apache.jasper.EmbeddedServletOptions in project spring-boot by spring-projects.

the class LocalDevToolsAutoConfigurationTests method devToolsSwitchesJspServletToDevelopmentMode.

@Test
public void devToolsSwitchesJspServletToDevelopmentMode() {
    this.context = initializeAndRun(Config.class);
    TomcatWebServer tomcatContainer = (TomcatWebServer) ((ServletWebServerApplicationContext) this.context).getWebServer();
    Container context = tomcatContainer.getTomcat().getHost().findChildren()[0];
    StandardWrapper jspServletWrapper = (StandardWrapper) context.findChild("jsp");
    EmbeddedServletOptions options = (EmbeddedServletOptions) ReflectionTestUtils.getField(jspServletWrapper.getServlet(), "options");
    assertThat(options.getDevelopment()).isEqualTo(true);
}
Also used : Container(org.apache.catalina.Container) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) EmbeddedServletOptions(org.apache.jasper.EmbeddedServletOptions) StandardWrapper(org.apache.catalina.core.StandardWrapper) Test(org.junit.Test)

Example 2 with EmbeddedServletOptions

use of org.apache.jasper.EmbeddedServletOptions in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method jspServletIsNotInDevelopmentModeByDefault.

@Test
public void jspServletIsNotInDevelopmentModeByDefault() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    this.webServer = factory.getWebServer();
    Assume.assumeThat(getJspServlet(), notNullValue());
    JspServlet jspServlet = getJspServlet();
    EmbeddedServletOptions options = (EmbeddedServletOptions) ReflectionTestUtils.getField(jspServlet, "options");
    assertThat(options.getDevelopment()).isEqualTo(false);
}
Also used : JspServlet(org.apache.jasper.servlet.JspServlet) EmbeddedServletOptions(org.apache.jasper.EmbeddedServletOptions) Test(org.junit.Test)

Example 3 with EmbeddedServletOptions

use of org.apache.jasper.EmbeddedServletOptions in project tomcat by apache.

the class JspServlet method init.

/*
     * Initializes this JspServlet.
     */
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    this.config = config;
    this.context = config.getServletContext();
    // Initialize the JSP Runtime Context
    // Check for a custom Options implementation
    String engineOptionsName = config.getInitParameter("engineOptionsClass");
    if (Constants.IS_SECURITY_ENABLED && engineOptionsName != null) {
        log.info(Localizer.getMessage("jsp.info.ignoreSetting", "engineOptionsClass", engineOptionsName));
        engineOptionsName = null;
    }
    if (engineOptionsName != null) {
        // Instantiate the indicated Options implementation
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class<?> engineOptionsClass = loader.loadClass(engineOptionsName);
            Class<?>[] ctorSig = { ServletConfig.class, ServletContext.class };
            Constructor<?> ctor = engineOptionsClass.getConstructor(ctorSig);
            Object[] args = { config, context };
            options = (Options) ctor.newInstance(args);
        } catch (Throwable e) {
            e = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(e);
            // Need to localize this.
            log.warn("Failed to load engineOptionsClass", e);
            // Use the default Options implementation
            options = new EmbeddedServletOptions(config, context);
        }
    } else {
        // Use the default Options implementation
        options = new EmbeddedServletOptions(config, context);
    }
    rctxt = new JspRuntimeContext(context, options);
    if (config.getInitParameter("jspFile") != null) {
        jspFile = config.getInitParameter("jspFile");
        try {
            if (null == context.getResource(jspFile)) {
                return;
            }
        } catch (MalformedURLException e) {
            throw new ServletException("cannot locate jsp file", e);
        }
        try {
            if (SecurityUtil.isPackageProtectionEnabled()) {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                    @Override
                    public Object run() throws IOException, ServletException {
                        serviceJspFile(null, null, jspFile, true);
                        return null;
                    }
                });
            } else {
                serviceJspFile(null, null, jspFile, true);
            }
        } catch (IOException e) {
            throw new ServletException("Could not precompile jsp: " + jspFile, e);
        } catch (PrivilegedActionException e) {
            Throwable t = e.getCause();
            if (t instanceof ServletException)
                throw (ServletException) t;
            throw new ServletException("Could not precompile jsp: " + jspFile, e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString()));
        log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) JspRuntimeContext(org.apache.jasper.compiler.JspRuntimeContext) EmbeddedServletOptions(org.apache.jasper.EmbeddedServletOptions)

Aggregations

EmbeddedServletOptions (org.apache.jasper.EmbeddedServletOptions)3 Test (org.junit.Test)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ServletException (javax.servlet.ServletException)1 Container (org.apache.catalina.Container)1 StandardWrapper (org.apache.catalina.core.StandardWrapper)1 JspRuntimeContext (org.apache.jasper.compiler.JspRuntimeContext)1 JspServlet (org.apache.jasper.servlet.JspServlet)1 TomcatWebServer (org.springframework.boot.web.embedded.tomcat.TomcatWebServer)1