use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class AbstractStandardUpgradeStrategy method getContainer.
protected ServerContainer getContainer(HttpServletRequest request) {
ServletContext servletContext = request.getServletContext();
String attrName = "jakarta.websocket.server.ServerContainer";
ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName);
Assert.notNull(container, "No 'jakarta.websocket.server.ServerContainer' ServletContext attribute. " + "Are you running in a Servlet container that supports JSR-356?");
return container;
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class WebApplicationObjectSupport method getTempDir.
/**
* Return the temporary directory for the current web application,
* as provided by the servlet container.
* @return the File representing the temporary directory
* @throws IllegalStateException if not running within a ServletContext
* @see org.springframework.web.util.WebUtils#getTempDir(jakarta.servlet.ServletContext)
*/
protected final File getTempDir() throws IllegalStateException {
ServletContext servletContext = getServletContext();
Assert.state(servletContext != null, "ServletContext is required");
return WebUtils.getTempDir(servletContext);
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithServletContext.
@Test
public void servletContextAwareWithServletContext() {
ServletContext servletContext = new MockServletContext();
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext);
ServletContextAwareBean bean = new ServletContextAwareBean();
assertThat(bean.getServletContext()).isNull();
processor.postProcessBeforeInitialization(bean, "testBean");
assertThat(bean.getServletContext()).as("ServletContext should have been set").isNotNull();
assertThat(bean.getServletContext()).isEqualTo(servletContext);
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithNonNullServletContextAndNullServletConfig.
@Test
public void servletContextAwareWithNonNullServletContextAndNullServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, null);
ServletContextAwareBean bean = new ServletContextAwareBean();
assertThat(bean.getServletContext()).isNull();
processor.postProcessBeforeInitialization(bean, "testBean");
assertThat(bean.getServletContext()).as("ServletContext should have been set").isNotNull();
assertThat(bean.getServletContext()).isEqualTo(servletContext);
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletConfigAwareWithServletConfig.
@Test
public void servletConfigAwareWithServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletConfig servletConfig = new MockServletConfig(servletContext);
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletConfig);
ServletConfigAwareBean bean = new ServletConfigAwareBean();
assertThat(bean.getServletConfig()).isNull();
processor.postProcessBeforeInitialization(bean, "testBean");
assertThat(bean.getServletConfig()).as("ServletConfig should have been set").isNotNull();
assertThat(bean.getServletConfig()).isEqualTo(servletConfig);
}
Aggregations