com.blade.mvc.http.Request.parameters() - java examples

Here are the examples of the java api com.blade.mvc.http.Request.parameters() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

17 View Complete Implementation : RouteActionArguments.java
Copyright Apache License 2.0
Author : lets-blade
private static Object getQueryParam(ParamStruct paramStruct) {
    Param param = paramStruct.param;
    String paramName = paramStruct.paramName;
    Type argType = paramStruct.argType;
    Request request = paramStruct.request;
    if (null == param) {
        return null;
    }
    String name = StringKit.isBlank(param.name()) ? paramName : param.name();
    if (ReflectKit.isBasicType(argType) || argType.equals(Date.clreplaced) || argType.equals(BigDecimal.clreplaced) || argType.equals(LocalDate.clreplaced) || argType.equals(LocalDateTime.clreplaced) || (argType instanceof Clreplaced && ((Clreplaced) argType).isEnum())) {
        String value = request.query(name).orElseGet(() -> getDefaultValue(param.defaultValue(), argType));
        return ReflectKit.convert(argType, value);
    } else {
        if (ParameterizedType.clreplaced.isInstance(argType)) {
            List<String> values = request.parameters().get(param.name());
            return getParameterizedTypeValues(values, argType);
        }
        return parseModel(ReflectKit.typeToClreplaced(argType), request, param.name());
    }
}

16 View Complete Implementation : ThemeController.java
Copyright MIT License
Author : tfssweb
/**
 * 保存主题配置项
 *
 * @param request
 * @return
 */
@PostRoute(value = "setting")
@JSON
public RestResponse saveSetting(Request request) {
    try {
        Map<String, List<String>> query = request.parameters();
        // theme_milk_options => {  }
        String currentTheme = Commons.site_theme();
        String key = "theme_" + currentTheme + "_options";
        Map<String, String> options = new HashMap<>();
        query.forEach((k, v) -> options.put(k, v.get(0)));
        optionsService.saveOption(key, JsonKit.toString(options));
        TaleConst.OPTIONS = Environment.of(optionsService.getOptions());
        new Logs(LogActions.THEME_SETTING, JsonKit.toString(query), request.address(), this.getUid()).save();
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "主题设置失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}

15 View Complete Implementation : XssMiddleware.java
Copyright MIT License
Author : biezhi
protected void filterParameters(Request request) {
    Map<String, List<String>> parameters = request.parameters();
    Set<Map.Entry<String, List<String>>> entries = parameters.entrySet();
    for (Map.Entry<String, List<String>> entry : entries) {
        List<String> snzValues = entry.getValue().stream().map(this::stripXSS).collect(Collectors.toList());
        parameters.put(entry.getKey(), snzValues);
    }
}

15 View Complete Implementation : HttpRequestTest.java
Copyright Apache License 2.0
Author : lets-blade
@Test
public void testQueryParam() {
    Request mockRequest = mockHttpRequest("GET");
    Map<String, List<String>> parameters = new HashMap<>();
    parameters.put("name", Collections.singletonList("jack"));
    parameters.put("price", Collections.singletonList("22.1"));
    parameters.put("age", Collections.singletonList("25"));
    parameters.put("id", Collections.singletonList("220291"));
    when(mockRequest.parameters()).thenReturn(parameters);
    Request request = new HttpRequest(mockRequest);
    replacedertEquals("jack", request.query("name").get());
    replacedertEquals(Double.valueOf(22.1), request.queryDouble("price").get());
    replacedertEquals(Long.valueOf(220291), request.queryLong("id").get());
    replacedertEquals(Integer.valueOf(25), request.queryInt("age").get());
}

15 View Complete Implementation : BasicAuthMiddlewareTest.java
Copyright Apache License 2.0
Author : lets-blade
@Test
public void testAuthSuccess() throws Exception {
    Request mockRequest = mockHttpRequest("GET");
    WebContext.init(Blade.of(), "/");
    Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", "Basic YWRtaW46MTIzNDU2");
    when(mockRequest.parameters()).thenReturn(new HashMap<>());
    when(mockRequest.headers()).thenReturn(headers);
    Request request = new HttpRequest(mockRequest);
    Response response = mockHttpResponse(200);
    RouteContext context = new RouteContext(request, response);
    context.initRoute(Route.builder().action(AuthHandler.clreplaced.getMethod("handle", RouteContext.clreplaced)).targetType(AuthHandler.clreplaced).target(new AuthHandler()).build());
    WebContext.set(new WebContext(request, response, null));
    AuthOption authOption = AuthOption.builder().build();
    authOption.addUser("admin", "123456");
    BasicAuthMiddleware basicAuthMiddleware = new BasicAuthMiddleware(authOption);
    boolean flag = basicAuthMiddleware.before(context);
    replacedertTrue(flag);
}

15 View Complete Implementation : BasicAuthMiddlewareTest.java
Copyright Apache License 2.0
Author : lets-blade
@Test
public void testAuthFail() throws Exception {
    Request mockRequest = mockHttpRequest("GET");
    WebContext.init(Blade.of(), "/");
    Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", "Basic YmxhZGU6YmxhZGUyMg==");
    when(mockRequest.parameters()).thenReturn(new HashMap<>());
    when(mockRequest.headers()).thenReturn(headers);
    Request request = new HttpRequest(mockRequest);
    Response response = mockHttpResponse(200);
    RouteContext context = new RouteContext(request, response);
    context.initRoute(Route.builder().action(AuthHandler.clreplaced.getMethod("handle", RouteContext.clreplaced)).targetType(AuthHandler.clreplaced).target(new AuthHandler()).build());
    WebContext.set(new WebContext(request, response, null));
    AuthOption authOption = AuthOption.builder().build();
    authOption.addUser("admin", "123456");
    BasicAuthMiddleware basicAuthMiddleware = new BasicAuthMiddleware(authOption);
    boolean flag = basicAuthMiddleware.before(context);
    replacedertFalse(flag);
}

11 View Complete Implementation : IndexController.java
Copyright MIT License
Author : tfssweb
/**
 * 保存系统设置
 */
@Route(value = "setting", method = HttpMethod.POST)
@JSON
public RestResponse saveSetting(@Param String site_theme, Request request) {
    try {
        Map<String, List<String>> querys = request.parameters();
        optionsService.saveOptions(querys);
        Environment config = Environment.of(optionsService.getOptions());
        TaleConst.OPTIONS = config;
        new Logs(LogActions.SYS_SETTING, JsonKit.toString(querys), request.address(), this.getUid()).save();
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "保存设置失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}