Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
 package io.undertow.server.handlers.form;
 import java.util.List;
Factory class that can create a form data parser for a given request.

It does this by iterating the available parser definitions, and returning the first parser that is created.

Stuart Douglas
 public class FormParserFactory {
     private static final AttachmentKey<FormDataParserATTACHMENT_KEY = AttachmentKey.create(FormDataParser.class);
     private final ParserDefinition[] parserDefinitions;
     FormParserFactory(final List<ParserDefinitionparserDefinitions) {
         this. = parserDefinitions.toArray(new ParserDefinition[parserDefinitions.size()]);

Creates a form data parser for this request. If a parser has already been created for the request the existing parser will be returned rather than creating a new one.

exchange The exchange
A form data parser, or null if there is no parser registered for the request content type
     public FormDataParser createParser(final HttpServerExchange exchange) {
         FormDataParser existing = exchange.getAttachment();
         if(existing != null) {
             return existing;
         for (int i = 0; i < .; ++i) {
             FormDataParser parser = [i].create(exchange);
             if (parser != null) {
                 return parser;
         return null;
     public interface ParserDefinition {
         FormDataParser create(final HttpServerExchange exchange);
     public static Builder builder() {
         return builder(true);
     public static Builder builder(boolean includeDefault) {
         Builder builder = new Builder();
         if (includeDefault) {
             builder.addParsers(new FormEncodedDataDefinition(), new MultiPartParserDefinition());
         return builder;
     public static class Builder {
         private List<ParserDefinitionparsers = new ArrayList<>();
         public Builder addParser(final ParserDefinition definition) {
             return this;
         public Builder addParsers(final ParserDefinition... definition) {
             return this;
         public Builder addParsers(final List<ParserDefinitiondefinition) {
            return this;
        public FormParserFactory build() {
            return new FormParserFactory();
New to GrepCode? Check out our FAQ X