Search in sources :

Example 66 with ServletContext

use of javax.servlet.ServletContext in project ratpack by ratpack.

the class Template method thymeleafTemplate.

public static Template thymeleafTemplate(Map<String, ?> model, String name, String contentType, IFragmentSpec fragmentSpec) {
    HttpServletRequest request = new ThymeleafHttpServletRequestAdapter();
    HttpServletResponse response = new ThymeleafHttpServletResponseAdapter();
    ServletContext servletContext = new ThymeleafServletContextAdapter();
    WebContext context = new WebContext(request, response, servletContext);
    if (model != null) {
        context.setVariables(model);
    }
    return new Template(name, context, contentType, fragmentSpec);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ThymeleafServletContextAdapter(ratpack.thymeleaf.internal.ThymeleafServletContextAdapter) ThymeleafHttpServletResponseAdapter(ratpack.thymeleaf.internal.ThymeleafHttpServletResponseAdapter) WebContext(org.thymeleaf.context.WebContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) ThymeleafHttpServletRequestAdapter(ratpack.thymeleaf.internal.ThymeleafHttpServletRequestAdapter)

Example 67 with ServletContext

use of javax.servlet.ServletContext in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method rootServletContextResource.

@Test
public void rootServletContextResource() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    final AtomicReference<URL> rootResource = new AtomicReference<>();
    this.webServer = factory.getWebServer(new ServletContextInitializer() {

        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            try {
                rootResource.set(servletContext.getResource("/"));
            } catch (MalformedURLException ex) {
                throw new ServletException(ex);
            }
        }
    });
    this.webServer.start();
    assertThat(rootResource.get()).isNotNull();
}
Also used : ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) ServletContext(javax.servlet.ServletContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) URL(java.net.URL) ServletContextInitializer(org.springframework.boot.web.servlet.ServletContextInitializer) Test(org.junit.Test)

Example 68 with ServletContext

use of javax.servlet.ServletContext in project bigbluebutton by bigbluebutton.

the class HttpTunnelStreamController method getSessionManager.

private ISessionManagerGateway getSessionManager() {
    //Get the servlet context
    ServletContext ctx = getServletContext();
    //Grab a reference to the application context
    ApplicationContext appCtx = (ApplicationContext) ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    //Get the bean holding the parameter
    ISessionManagerGateway manager = (ISessionManagerGateway) appCtx.getBean("sessionManagerGateway");
    if (manager != null) {
        System.out.println("****Got the SessionManager context: *****");
    }
    return manager;
}
Also used : ISessionManagerGateway(org.bigbluebutton.deskshare.server.session.ISessionManagerGateway) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ServletContext(javax.servlet.ServletContext)

Example 69 with ServletContext

use of javax.servlet.ServletContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method onDifferentPortInWebServer.

@Test
public void onDifferentPortInWebServer() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    ServletContext servletContext = mock(ServletContext.class);
    given(servletContext.getInitParameterNames()).willReturn(new Vector<String>().elements());
    given(servletContext.getAttributeNames()).willReturn(new Vector<String>().elements());
    this.applicationContext.setServletContext(servletContext);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().management, null);
    assertContent("/endpoint", ports.get().management, null);
}
Also used : ServletContext(javax.servlet.ServletContext) Vector(java.util.Vector) Test(org.junit.Test)

Example 70 with ServletContext

use of javax.servlet.ServletContext in project eweb4j-framework by laiweiwei.

the class EWebServlet method initContext.

/**
	 * 初始化
	 * 
	 * @param req
	 * @param res
	 * @throws Exception
	 */
private Context initContext(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html");
    Context context = new Context(servletContext, request, response, null, null, null, null);
    // 将request的请求参数转到另外一个map中去
    Map<String, String[]> qpMap = new HashMap<String, String[]>();
    qpMap.putAll(ParamUtil.copyReqParams(context.getRequest()));
    context.setQueryParamMap(qpMap);
    //将上传的表单元素注入到context中
    UploadUtil.handleUpload(context);
    return context;
}
Also used : ServletContext(javax.servlet.ServletContext) HashMap(java.util.HashMap)

Aggregations

ServletContext (javax.servlet.ServletContext)1059 Test (org.junit.Test)231 HttpServletRequest (javax.servlet.http.HttpServletRequest)171 IOException (java.io.IOException)138 HttpServletResponse (javax.servlet.http.HttpServletResponse)127 ServletException (javax.servlet.ServletException)95 File (java.io.File)75 ServletConfig (javax.servlet.ServletConfig)68 FilterConfig (javax.servlet.FilterConfig)65 HashMap (java.util.HashMap)63 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)49 URL (java.net.URL)47 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)38 PrintWriter (java.io.PrintWriter)32 List (java.util.List)32 RequestDispatcher (javax.servlet.RequestDispatcher)30 WebApplicationContext (org.springframework.web.context.WebApplicationContext)28