Java Code Examples for io.undertow.util.URLUtils#decode()

The following examples show how to use io.undertow.util.URLUtils#decode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SikulixServer.java    From SikuliX1 with MIT License 6 votes vote down vote up
private String[] getScriptArgs(final HttpServerExchange exchange) {
  String[] args = {};
  Optional<String> argsString = Optional.empty();
  String queryString = exchange.getQueryString();
  if (queryString != null) {
    Matcher matcher = PATTERN_QUERY_ARGS.matcher(queryString);
    if (matcher.find()) {
      argsString = Optional.of(matcher.group("args"));
    }
  }
  if (exchange.getRequestMethod().equals(Methods.POST)) {
    FormData form = exchange.getAttachment(FormDataParser.FORM_DATA);
    if (form != null) {
      argsString = Optional.ofNullable(form.getLast("args")).map(fVal -> fVal.getValue());
    }
  }
  if (argsString.isPresent()) {
    StringBuilder buf = new StringBuilder();
    String[] tokens = argsString.get().split(";");
    args = new String[tokens.length];
    for (int i=0; i<tokens.length; i++) {
      args[i] = URLUtils.decode(tokens[i], "UTF-8", true, buf);
    }
  }
  return args;
}
 
Example 2
Source File: AjpRequestParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String decode(String url, final boolean containsUrlCharacters) throws UnsupportedEncodingException {
    if (doDecode && containsUrlCharacters) {
        try {
            if(decodeBuffer == null) {
                decodeBuffer = new StringBuilder();
            }
            return URLUtils.decode(url, this.encoding, allowEncodedSlash, false, decodeBuffer);
        } catch (Exception e) {
            throw UndertowMessages.MESSAGES.failedToDecodeURL(url, encoding, e);
        }
    }
    return url;
}
 
Example 3
Source File: HttpRequestParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String decode(final String value, boolean urlDecodeRequired, ParseState state, final boolean allowEncodedSlash, final boolean formEncoded) {
    if (urlDecodeRequired) {
        return URLUtils.decode(value, charset, allowEncodedSlash, formEncoded, state.decodeBuffer);
    } else {
        return value;
    }
}
 
Example 4
Source File: FormEncodedDataDefinition.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
private void doParse(ByteBuf buffer) {
    try {
        if (buffer != null) {
            while (buffer.isReadable()) {
                byte n = buffer.readByte();
                switch (state) {
                    case 0: {
                        if (n == '=') {
                            name = builder.toString();
                            builder.setLength(0);
                            state = 2;
                        } else if (n == '&') {
                            data.add(builder.toString(), "");
                            builder.setLength(0);
                            state = 0;
                        } else if (n == '%' || n == '+') {
                            state = 1;
                            builder.append((char) n);
                        } else {
                            builder.append((char) n);
                        }
                        break;
                    }
                    case 1: {
                        if (n == '=') {
                            name = URLUtils.decode(builder.toString(), charset, true, new StringBuilder());
                            builder.setLength(0);
                            state = 2;
                        } else if (n == '&') {
                            data.add(URLUtils.decode(builder.toString(), charset, true, new StringBuilder()), "");
                            builder.setLength(0);
                            state = 0;
                        } else {
                            builder.append((char) n);
                        }
                        break;
                    }
                    case 2: {
                        if (n == '&') {
                            data.add(name, builder.toString());
                            builder.setLength(0);
                            state = 0;
                        } else if (n == '%' || n == '+') {
                            state = 3;
                            builder.append((char) n);
                        } else {
                            builder.append((char) n);
                        }
                        break;
                    }
                    case 3: {
                        if (n == '&') {
                            data.add(name, URLUtils.decode(builder.toString(), charset, true, new StringBuilder()));
                            builder.setLength(0);
                            state = 0;
                        } else {
                            builder.append((char) n);
                        }
                        break;
                    }
                }
            }
        } else {
            if (state == 2) {
                data.add(name, builder.toString());
            } else if (state == 3) {
                data.add(name, URLUtils.decode(builder.toString(), charset, true, new StringBuilder()));
            } else if (builder.length() > 0) {
                if (state == 1) {
                    data.add(URLUtils.decode(builder.toString(), charset, true, new StringBuilder()), "");
                } else {
                    data.add(builder.toString(), "");
                }
            }
            state = 4;
            exchange.putAttachment(FORM_DATA, data);
        }
    } finally {
        if (buffer != null) {
            buffer.release();
        }
    }
}
 
Example 5
Source File: FormEncodedDataDefinition.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void doParse(final StreamSourceChannel channel) throws IOException {
    int c = 0;
    final PooledByteBuffer pooled = exchange.getConnection().getByteBufferPool().allocate();
    try {
        final ByteBuffer buffer = pooled.getBuffer();
        do {
            buffer.clear();
            c = channel.read(buffer);
            if (c > 0) {
                buffer.flip();
                while (buffer.hasRemaining()) {
                    byte n = buffer.get();
                    switch (state) {
                        case 0: {
                            if (n == '=') {
                                name = builder.toString();
                                builder.setLength(0);
                                state = 2;
                            } else if (n == '&') {
                                data.add(builder.toString(), "");
                                builder.setLength(0);
                                state = 0;
                            } else if (n == '%' || n == '+') {
                                state = 1;
                                builder.append((char) n);
                            } else {
                                builder.append((char) n);
                            }
                            break;
                        }
                        case 1: {
                            if (n == '=') {
                                name = URLUtils.decode(builder.toString(), charset, true, new StringBuilder());
                                builder.setLength(0);
                                state = 2;
                            } else if (n == '&') {
                                data.add(URLUtils.decode(builder.toString(), charset, true, new StringBuilder()), "");
                                builder.setLength(0);
                                state = 0;
                            } else {
                                builder.append((char) n);
                            }
                            break;
                        }
                        case 2: {
                            if (n == '&') {
                                data.add(name, builder.toString());
                                builder.setLength(0);
                                state = 0;
                            } else if (n == '%' || n == '+') {
                                state = 3;
                                builder.append((char) n);
                            } else {
                                builder.append((char) n);
                            }
                            break;
                        }
                        case 3: {
                            if (n == '&') {
                                data.add(name, URLUtils.decode(builder.toString(), charset, true, new StringBuilder()));
                                builder.setLength(0);
                                state = 0;
                            } else {
                                builder.append((char) n);
                            }
                            break;
                        }
                    }
                }
            }
        } while (c > 0);
        if (c == -1) {
            if (state == 2) {
                data.add(name, builder.toString());
            } else if (state == 3) {
                data.add(name, URLUtils.decode(builder.toString(), charset, true, new StringBuilder()));
            } else if(builder.length() > 0) {
                if(state == 1) {
                    data.add(URLUtils.decode(builder.toString(), charset, true, new StringBuilder()), "");
                } else {
                    data.add(builder.toString(), "");
                }
            }
            state = 4;
            exchange.putAttachment(FORM_DATA, data);
        }
    } finally {
        pooled.close();
    }
}