private FormData parseForm() { if (form == null) { form = NO_FORM; try { String tmpdir = conf.getString("application.tmpdir"); String charset = conf.getString("application.charset"); String value = exchange.getRequestHeaders().getFirst("Content-Type"); if (value != null) { MediaType type = MediaType.valueOf(value); if (MediaType.form.name().equals(type.name())) { blocking.get(); form = new FormEncodedDataDefinition() .setDefaultEncoding(charset) .create(exchange) .parseBlocking(); } else if (MediaType.multipart.name().equals(type.name())) { blocking.get(); form = new MultiPartParserDefinition() .setTempFileLocation(new File(tmpdir).toPath()) .setDefaultEncoding(charset) .create(exchange) .parseBlocking(); } } } catch (IOException x) { } } return form; }
/** * 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); } }
FormDataParser parser = formParserFactory.createParser(exchange); if (parser != null) { FormData formData = parser.parseBlocking(); data = BodyConverter.convert(formData); exchange.putAttachment(REQUEST_BODY, data);
final FormData data = parser.parseBlocking(); final FormData.FormValue jUsername = data.getFirst("j_username"); final FormData.FormValue jPassword = data.getFirst("j_password");
Builder builder = FormParserFactory.builder(); final FormDataParser formDataParser = builder.build().createParser(exchange); if (formDataParser != null) { exchange.startBlocking(); FormData formData = formDataParser.parseBlocking(); for (String data : formData) { for (FormData.FormValue formValue : formData.get(data)) { if (formValue.isFile()) { // process file here: formValue.getFile(); } } } }
@Override public String getFirstParam(String param) { Deque<String> values = exchange.getQueryParameters().get(param); if (values != null && !values.isEmpty()) { return values.getFirst(); } if (formData == null && "post".equalsIgnoreCase(getMethod())) { FormDataParser parser = formParserFactory.createParser(exchange); try { formData = parser.parseBlocking(); } catch (IOException cause) { throw new RuntimeException("Failed to parse form parameters", cause); } } if (formData != null) { Deque<FormValue> formValues = formData.get(param); if (formValues != null && !formValues.isEmpty()) { FormValue firstValue = formValues.getFirst(); if (!firstValue.isFile()) { return firstValue.getValue(); } } } return null; }
@Override public String getFirstParam(String param) { Deque<String> values = exchange.getQueryParameters().get(param); if (values != null && !values.isEmpty()) { return values.getFirst(); } if (formData == null && "post".equalsIgnoreCase(getMethod())) { FormDataParser parser = formParserFactory.createParser(exchange); try { formData = parser.parseBlocking(); } catch (IOException cause) { throw new RuntimeException("Failed to parse form parameters", cause); } } if (formData != null) { Deque<FormValue> formValues = formData.get(param); if (formValues != null && !formValues.isEmpty()) { FormValue firstValue = formValues.getFirst(); if (!firstValue.isFile()) { return firstValue.getValue(); } } } return null; }
private void parseMultipartForm() throws IOException { this.exchange.startBlocking(); final FormDataParser formDataParser = new MultiPartParserDefinition().setTempFileLocation(new File(TMP_DIR).toPath()).setDefaultEncoding(CHARSET).create(this.exchange); if (formDataParser != null) { final FormData formData = formDataParser.parseBlocking(); this.exchange.putAttachment(FormDataParser.FORM_DATA, formData); extractFormParameters(formData); } }
private FormData parseFormData() { if(formParsingException != null) { throw formParsingException; } if (parsedFormData == null) { if (readStarted) { return null; } final ManagedServlet originalServlet = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getCurrentServlet().getManagedServlet(); final FormDataParser parser = originalServlet.getFormParserFactory().createParser(exchange); if (parser == null) { return null; } readStarted = true; try { return parsedFormData = parser.parseBlocking(); } catch (RequestTooBigException | MultiPartParserDefinition.FileTooLargeException e) { throw formParsingException = new IllegalStateException(e); } catch (RuntimeException e) { throw formParsingException = e; } catch (IOException e) { throw formParsingException = new RuntimeException(e); } } return parsedFormData; }
private FormData parseForm() { if (form == null) { form = NO_FORM; try { String tmpdir = conf.getString("application.tmpdir"); String charset = conf.getString("application.charset"); String value = exchange.getRequestHeaders().getFirst("Content-Type"); if (value != null) { MediaType type = MediaType.valueOf(value); if (MediaType.form.name().equals(type.name())) { blocking.get(); form = new FormEncodedDataDefinition() .setDefaultEncoding(charset) .create(exchange) .parseBlocking(); } else if (MediaType.multipart.name().equals(type.name())) { blocking.get(); form = new MultiPartParserDefinition() .setTempFileLocation(new File(tmpdir).toPath()) .setDefaultEncoding(charset) .create(exchange) .parseBlocking(); } } } catch (IOException x) { } } return form; }
@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); } }
/** * 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; }
/** * 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); } }
private void parseEncodedForm() throws IOException { this.exchange.startBlocking(); final FormData formData = new FormEncodedDataDefinition().setDefaultEncoding(this.exchange.getRequestCharset()).create(exchange).parseBlocking(); this.exchange.putAttachment(FormDataParser.FORM_DATA, formData); extractFormParameters(formData); }
@Override public Credential readCredential(HttpServerExchange exchange) throws IOException { if ( !exchange.isBlocking() ) exchange.startBlocking(); Credential credential = null; final FormDataParser parser = formParserFactory.createParser(exchange); final FormData data = parser.parseBlocking(); final FormData.FormValue jUsername = data.getFirst("j_username"); final FormData.FormValue jPassword = data.getFirst("j_password"); if (jUsername != null && jPassword != null) { final String userName = jUsername.getValue(); final String password = jPassword.getValue(); credential = new UsernameAndPasswordCredential(userName, password); } return credential; }
final FormData data = parser.parseBlocking(); final FormData.FormValue jUsername = data.getFirst("j_username"); final FormData.FormValue jPassword = data.getFirst("j_password");
final FormData data = parser.parseBlocking(); final FormData.FormValue jUsername = data.getFirst("j_username"); final FormData.FormValue jPassword = data.getFirst("j_password");
private void getForm(HttpServerExchange exchange) throws IOException { this.form = this.injector.getInstance(Form.class); if (exchange.getRequestMethod().equals(Methods.POST) || exchange.getRequestMethod().equals(Methods.PUT)) { final FormDataParser formDataParser = FormParserFactory.builder().build().createParser(exchange); if (formDataParser != null) { exchange.startBlocking(); FormData formData = formDataParser.parseBlocking(); for (String data : formData) { for (FormData.FormValue formValue : formData.get(data)) { if (formValue.isFile()) { form.addFile(formValue.getFile()); } else { form.add(new HttpString(data).toString(), formValue.getValue()); } } } this.form.setSubmitted(true); } } }