You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by jo...@apache.org on 2014/08/08 16:26:50 UTC

svn commit: r1616778 - /deltaspike/site/trunk/content/container-control.mdtext

Author: johndament
Date: Fri Aug  8 14:26:50 2014
New Revision: 1616778

URL: http://svn.apache.org/r1616778
Log:
Added docs for Servlet embedded mode.

Modified:
    deltaspike/site/trunk/content/container-control.mdtext

Modified: deltaspike/site/trunk/content/container-control.mdtext
URL: http://svn.apache.org/viewvc/deltaspike/site/trunk/content/container-control.mdtext?rev=1616778&r1=1616777&r2=1616778&view=diff
==============================================================================
--- deltaspike/site/trunk/content/container-control.mdtext (original)
+++ deltaspike/site/trunk/content/container-control.mdtext Fri Aug  8 14:26:50 2014
@@ -24,11 +24,11 @@ Notice:    Licensed to the Apache Softwa
 
 There are basically two parts:
 
-  - The **CdiContainer** interface allows to boot and shutdown the CDI container in SE applications.
-  - The **ContextControl** interface allows to control the life-cycle of the built-in contexts of the CDI container.
+  - The `CdiContainer` interface allows to boot and shutdown the CDI container in SE applications.
+  - The `ContextControl` interface allows to control the life-cycle of the built-in contexts of the CDI container.
 
 ## CdiContainer
-You can use the CdiContainerLoader as a simple factory to gain access to the underlying CdiContainer implementation. This is of little interest for Java EE applications since the CDI Container 
+You can use the `CdiContainerLoader` as a simple factory to gain access to the underlying `CdiContainer` implementation. This is of little interest for Java EE applications since the CDI Container
 already gets properly booted and shut down by the Servlet container integration.
     
 
@@ -37,7 +37,7 @@ already gets properly booted and shut do
     CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
 
     // now we gonna boot the CDI container. This will trigger the classpath scan, etc
-       cdiContainer.boot();
+    cdiContainer.boot();
 
     // and finally we like to start all built-in contexts
     cdiContainer.getContextControl().startContexts();
@@ -123,46 +123,46 @@ The main usecase for this feature is for
 For Jetty, you need to add an `EventListener` which will be your `CdiServletRequestListener`.  The object must be instantiated.  This must be done before the server is started.
 
     :::java
-        Server server = new Server(port);
-        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
-        context.setContextPath("/");
-        server.setHandler(context);
+    Server server = new Server(port);
+    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+    context.setContextPath("/");
+    server.setHandler(context);
 
-        context.addEventListener(new CdiServletRequestListener());
-        context.addServlet(new ServletHolder(new YourServlet()),"/*");
+    context.addEventListener(new CdiServletRequestListener());
+    context.addServlet(new ServletHolder(new YourServlet()),"/*");
 
-        server.start();
+    server.start();
 
 ### Undertow
 For Undertow, you register the `CdiServletRequestListener` via `ListenerInfo` by passing in the class to their builders.  Then you add the `ListenerInfo` to your deployment before starting.
 
     :::java
-        ServletInfo servletInfo = Servlets.servlet("RequestServlet", YourServlet.class).setAsyncSupported(true)
-            .setLoadOnStartup(1).addMapping("/*");
-        ListenerInfo listenerInfo = Servlets.listener(CdiServletRequestListener.class);
-        DeploymentInfo di = new DeploymentInfo()
-                .addListener(listenerInfo)
-                .setContextPath("/")
-                .addServlet(servletInfo).setDeploymentName("CdiSEServlet")
-                .setClassLoader(ClassLoader.getSystemClassLoader());
-        DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(di);
-        deploymentManager.deploy();
-        Undertow server = Undertow.builder()
-                .addHttpListener(port, "localhost")
-                .setHandler(deploymentManager.start())
-                .build();
-        server.start();
+    ServletInfo servletInfo = Servlets.servlet("RequestServlet", YourServlet.class).setAsyncSupported(true)
+        .setLoadOnStartup(1).addMapping("/*");
+    ListenerInfo listenerInfo = Servlets.listener(CdiServletRequestListener.class);
+    DeploymentInfo di = new DeploymentInfo()
+            .addListener(listenerInfo)
+            .setContextPath("/")
+            .addServlet(servletInfo).setDeploymentName("CdiSEServlet")
+            .setClassLoader(ClassLoader.getSystemClassLoader());
+    DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(di);
+    deploymentManager.deploy();
+    Undertow server = Undertow.builder()
+            .addHttpListener(port, "localhost")
+            .setHandler(deploymentManager.start())
+            .build();
+    server.start();
 
 ### Tomcat
 For Tomcat, you need to register the `CdiServletContextListener` instead of the `CdiServletRequestListener`.  It is added as an `ApplicationListener` by passing in the class name as a `String`.
 
     :::java
-        Tomcat tomcat = new Tomcat();
-        tomcat.setPort(port);
-        File base = new File("...");
-        Context ctx = tomcat.addContext("/",base.getAbsolutePath());
-        StandardContext standardContext = (StandardContext)ctx;
-        standardContext.addApplicationListener(CdiServletContextListener.class.getName());
-        Wrapper wrapper = Tomcat.addServlet(ctx,"YourServlet",YourServlet.class.getName());
-        wrapper.addMapping("/*");
-        tomcat.start();
\ No newline at end of file
+    Tomcat tomcat = new Tomcat();
+    tomcat.setPort(port);
+    File base = new File("...");
+    Context ctx = tomcat.addContext("/",base.getAbsolutePath());
+    StandardContext standardContext = (StandardContext)ctx;
+    standardContext.addApplicationListener(CdiServletContextListener.class.getName());
+    Wrapper wrapper = Tomcat.addServlet(ctx,"YourServlet",YourServlet.class.getName());
+    wrapper.addMapping("/*");
+    tomcat.start();
\ No newline at end of file