@@ -0,0 +1,1971 @@
+/*%0A * Copyright 2013-2014 Donghwan Kim%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage io.github.flowersinthesand.wes.servlet;%0A%0Aimport io.github.flowersinthesand.wes.Action;%0Aimport io.github.flowersinthesand.wes.Actions;%0Aimport io.github.flowersinthesand.wes.ServerHttpExchange;%0Aimport io.github.flowersinthesand.wes.SimpleActions;%0A%0Aimport java.util.UUID;%0A%0Aimport javax.servlet.Servlet;%0Aimport javax.servlet.ServletContext;%0Aimport javax.servlet.ServletRegistration;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/**%0A * Convenient class to install Servlet bridge.%0A * %0A * @author Donghwan Kim%0A */%0Apublic class ServletBridge %7B%0A%0A%09private Actions%3CServerHttpExchange%3E httpActions = new SimpleActions%3C%3E();%0A%0A%09public ServletBridge(ServletContext context, String path) %7B%0A%09%09@SuppressWarnings(%22serial%22)%0A%09%09Servlet servlet = new HttpServlet() %7B%0A%09%09%09@Override%0A%09%09%09protected void service(HttpServletRequest req, HttpServletResponse resp) %7B%0A%09%09%09%09httpActions.fire(new ServletServerHttpExchange(req, resp));%0A%09%09%09%7D%0A%09%09%7D;%0A%09%09ServletRegistration.Dynamic reg = context.addServlet(%22wes#%22 + UUID.randomUUID(), servlet);%0A%09%09reg.setAsyncSupported(true);%0A%09%09reg.addMapping(path);%0A%09%7D%0A%0A%09/**%0A%09 * Adds an action to be called on HTTP request with%0A%09 * %7B@link ServerHttpExchange%7D.%0A%09 */%0A%09public ServletBridge httpAction(Action%3CServerHttpExchange%3E action) %7B%0A%09%09httpActions.add(action);%0A%09%09return this;%0A%09%7D%0A%0A%7D%0A

Add ServletBridge