Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure Servlet 3 bridge is compatible with Servlet 4 #21

Closed
flowersinthesand opened this issue Jun 3, 2018 · 1 comment
Closed
Assignees
Milestone

Comments

@flowersinthesand
Copy link
Member

I guess Servlet 4 didn't break backward compatibility so that Servlet 3 bridge should be compatible with Servlet 4. Just to be safe, let's make sure it works.

@flowersinthesand flowersinthesand added this to the 2.0.0-Beta1 milestone Jun 3, 2018
@flowersinthesand
Copy link
Member Author

I tested this with Undertow 2 and confirmed it works. Here's a diff FYI:

Index: bridge-servlet3/src/test/java/io/cettia/asity/bridge/servlet3/ServletServerHttpExchangeTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- bridge-servlet3/src/test/java/io/cettia/asity/bridge/servlet3/ServletServerHttpExchangeTest.java	(date 1528558909000)
+++ bridge-servlet3/src/test/java/io/cettia/asity/bridge/servlet3/ServletServerHttpExchangeTest.java	(date 1528563140075)
@@ -18,18 +18,16 @@
 import io.cettia.asity.action.Action;
 import io.cettia.asity.http.ServerHttpExchange;
 import io.cettia.asity.test.ServerHttpExchangeTestBase;
+import io.undertow.Handlers;
+import io.undertow.Undertow;
+import io.undertow.server.handlers.PathHandler;
+import io.undertow.servlet.Servlets;
+import io.undertow.servlet.api.DeploymentInfo;
+import io.undertow.servlet.api.DeploymentManager;
 import org.eclipse.jetty.client.api.Response;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import javax.servlet.Servlet;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletRegistration;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -38,36 +36,38 @@
  */
 public class ServletServerHttpExchangeTest extends ServerHttpExchangeTestBase {
 
-  private Server server;
+  private static Action<ServerHttpExchange> requestAction;
 
+  private Undertow server;
+
   @Override
-  protected void startServer(int port, final Action<ServerHttpExchange> requestAction) throws
-    Exception {
-    server = new Server();
-    ServerConnector connector = new ServerConnector(server);
-    connector.setPort(port);
-    server.addConnector(connector);
-    ServletContextHandler handler = new ServletContextHandler();
-    handler.addEventListener(new ServletContextListener() {
-      @Override
-      public void contextInitialized(ServletContextEvent event) {
-        ServletContext context = event.getServletContext();
-        Servlet servlet = new AsityServlet().onhttp(requestAction);
-        ServletRegistration.Dynamic reg = context.addServlet(AsityServlet.class.getName(), servlet);
-        reg.setAsyncSupported(true);
-        reg.addMapping(TEST_URI);
-      }
+  protected void startServer(int port, Action<ServerHttpExchange> requestAction) throws Exception {
+    ServletServerHttpExchangeTest.requestAction = requestAction;
+    DeploymentInfo servletBuilder = Servlets.deployment()
+      .setClassLoader(ServletServerHttpExchangeTest.class.getClassLoader())
+      .setContextPath("/")
+      .setDeploymentName("test.war")
+      .addServlets(Servlets.servlet(UndertowAsityServlet.class.getName(), UndertowAsityServlet.class).addMapping(TEST_URI).setAsyncSupported(true));
 
-      @Override
-      public void contextDestroyed(ServletContextEvent sce) {
-      }
-    });
-    server.setHandler(handler);
+    DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
+    manager.deploy();
+    PathHandler path = Handlers.path(manager.start());
+
+    server = Undertow.builder()
+      .addHttpListener(port, "localhost")
+      .setHandler(path)
+      .build();
     server.start();
   }
 
+  private static class UndertowAsityServlet extends AsityServlet {
+    public UndertowAsityServlet() {
+      onhttp(requestAction);
+    }
+  }
+
   @Override
-  protected void stopServer() throws Exception {
+  protected void stopServer() {
     server.stop();
   }
 
Index: bridge-servlet3/pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- bridge-servlet3/pom.xml	(date 1528558909000)
+++ bridge-servlet3/pom.xml	(date 1528562704863)
@@ -51,6 +51,7 @@
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>javax.servlet-api</artifactId>
+      <version>4.0.1</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.jetty</groupId>
@@ -59,6 +60,16 @@
     <dependency>
       <groupId>org.eclipse.jetty.websocket</groupId>
       <artifactId>javax-websocket-server-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.undertow</groupId>
+      <artifactId>undertow-core</artifactId>
+      <version>2.0.1.Final</version>
+    </dependency>
+    <dependency>
+      <groupId>io.undertow</groupId>
+      <artifactId>undertow-servlet</artifactId>
+      <version>2.0.1.Final</version>
     </dependency>
   </dependencies>
 </project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant