public static Builder builder(boolean includeDefault) { Builder builder = new Builder(); if (includeDefault) { builder.addParsers(new FormEncodedDataDefinition(), new MultiPartParserDefinition()); } return builder; }
public FormParserFactory build() { if(defaultCharset != null) { for (ParserDefinition parser : parsers) { parser.setDefaultEncoding(defaultCharset); } } return new FormParserFactory(parsers); }
MCMPHandler(MCMPConfig config, ModCluster modCluster, HttpHandler next) { this.config = config; this.next = next; this.modCluster = modCluster; this.container = modCluster.getContainer(); this.parserFactory = FormParserFactory.builder(false).addParser(new FormEncodedDataDefinition().setForceCreation(true)).build(); UndertowLogger.ROOT_LOGGER.mcmpHandlerCreated(); }
/** * Transform the form data into an intermediate request data which can me used * by the web manager * * @param exchange the http server exchange * @return * @throws IOException */ RequestData parseFormData(final HttpServerExchange exchange) throws IOException { // Read post parameters final FormDataParser parser = parserFactory.createParser(exchange); final FormData formData = parser.parseBlocking(); final RequestData data = new RequestData(); for (String name : formData) { final HttpString key = new HttpString(name); data.add(key, formData.get(name)); } return data; }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { FormDataParser parser = formParserFactory.createParser(exchange); if (parser == null) { next.handleRequest(exchange); return; } if(exchange.isBlocking()) { exchange.putAttachment(FormDataParser.FORM_DATA, parser.parseBlocking()); next.handleRequest(exchange); } else { parser.parse(next); } }
public static Builder builder() { return builder(true); }
@Override public HttpHandler wrap(HttpHandler handler) { return new EagerFormParsingHandler(handler); } };
@Override public Path getPath() { if (fileItem == null) { throw UndertowMessages.MESSAGES.formValueIsAString(); } if (fileItem.isInMemory()) { throw UndertowMessages.MESSAGES.formValueIsInMemoryFile(); } return fileItem.getFile(); }
@Override public File file() throws IOException { return value.getPath().toFile(); }
@Override public String name() { return value.getFileName(); }
public void write(Path target) throws IOException { if (file != null) { try { Files.move(file, target); return; } catch (IOException e) { // ignore and let the Files.copy, outside // this if block, take over and attempt to copy it } } try (InputStream is = getInputStream()) { Files.copy(is, target); } } }
FormValueImpl(Path file, final String fileName, HeaderMap headers) { this.fileItem = new FileItem(file); this.headers = headers; this.fileName = fileName; this.value = null; }
@Override public boolean isFile() { return fileItem != null && !fileItem.isInMemory(); }
public void add(String name, String value) { add(name, value, null); }
@Override public File getFile() { return getPath().toFile(); }
FormValueImpl(byte[] data, String fileName, HeaderMap headers) { this.fileItem = new FileItem(data); this.fileName = fileName; this.headers = headers; this.value = null; }
public long getFileSize() throws IOException { if (isInMemory()) { return content.length; } else { return Files.size(file); } }