@@ -0,0 +1,3047 @@
+/*%0A * JBoss, Home of Professional Open Source.%0A * Copyright 2012 Red Hat, Inc., and individual contributors%0A * as indicated by the @author tags.%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 */%0A%0Apackage io.undertow.server.handlers.form;%0A%0Aimport io.undertow.UndertowLogger;%0Aimport io.undertow.server.HttpCompletionHandler;%0Aimport io.undertow.server.HttpHandler;%0Aimport io.undertow.server.HttpServerExchange;%0Aimport io.undertow.server.handlers.HttpHandlers;%0Aimport io.undertow.server.handlers.ResponseCodeHandler;%0Aimport org.xnio.IoFuture;%0Aimport org.xnio.IoUtils;%0A%0A/**%0A * Handler that eagerly parses form data. The request chain will pause while the data is being read,%0A * and then continue when the form data is fully passed.%0A * %3Cp/%3E%0A *%0A * NOTE: This is not strictly compatible with servlet, as it removes the option for the user to%0A * parse the request themselves, however in practice this requirement is probably rare, and%0A * using this handler gives a significant performance advantage in that a thread is not blocked%0A * for the duration of the upload.%0A *%0A * @author Stuart Douglas%0A */%0Apublic class EagerFormParsingHandler implements HttpHandler %7B%0A%0A    private volatile HttpHandler next = ResponseCodeHandler.HANDLE_404;%0A%0A    @Override%0A    public void handleRequest(final HttpServerExchange exchange, final HttpCompletionHandler completionHandler) %7B%0A        FormDataParser parser = exchange.getAttachment(FormDataParser.ATTACHMENT_KEY);%0A        if(parser == null) %7B%0A            HttpHandlers.executeHandler(next, exchange, completionHandler);%0A            return;%0A        %7D%0A        final IoFuture%3CFormData%3E future = parser.parse();%0A        future.addNotifier(new IoFuture.Notifier%3CFormData, Object%3E() %7B%0A            @Override%0A            public void notify(final IoFuture%3C? extends FormData%3E ioFuture, final Object attachment) %7B%0A                if(ioFuture.getStatus() == IoFuture.Status.DONE) %7B%0A                    HttpHandlers.executeHandler(next, exchange, completionHandler);%0A                %7D else if(ioFuture.getStatus() == IoFuture.Status.FAILED) %7B%0A                    UndertowLogger.REQUEST_LOGGER.ioExceptionReadingFromChannel(ioFuture.getException());%0A                    IoUtils.safeClose(exchange.getRequestChannel());%0A                    completionHandler.handleComplete();%0A                %7D%0A            %7D%0A        %7D, null);%0A    %7D%0A%0A    public HttpHandler getNext() %7B%0A        return next;%0A    %7D%0A%0A    public void setNext(final HttpHandler next) %7B%0A        HttpHandlers.handlerNotNull(next);%0A        this.next = next;%0A    %7D%0A%7D%0A

Add handler to allow eager parsing of form data using async IO