private FullHttpResponse handleJsonServiceMappings( FullHttpRequest request, JsonServiceMapping jsonServiceMapping, Matcher matcher) throws Exception { if (!httpSessionManager.hasReadAccess(request)) { return handleNotAuthenticated(request); } boolean isGetRequest = request.method().name().equals(HttpMethod.GET.name()); if (!isGetRequest && !httpSessionManager.hasAdminAccess(request)) { return handleNotAuthorized(); } String requestText = getRequestText(request); String[] args = new String[matcher.groupCount()]; for (int i = 0; i < args.length; i++) { String group = matcher.group(i + 1); checkNotNull(group); args[i] = group; } logger.debug( "handleJsonRequest(): serviceMethodName={}, args={}, requestText={}", jsonServiceMapping.methodName(), args, requestText); Object responseObject; try { responseObject = callMethod( jsonServiceMapping.service(), jsonServiceMapping.methodName(), args, requestText); } catch (Exception e) { return newHttpResponseFromException(e); } return buildJsonResponse(responseObject); }
private @Nullable JsonServiceMatcher getJsonServiceMatcher(FullHttpRequest request, String path) { for (JsonServiceMapping jsonServiceMapping : jsonServiceMappings) { if (!jsonServiceMapping.httpMethod().name().equals(request.method().name())) { continue; } Matcher matcher = jsonServiceMapping.pattern().matcher(path); if (matcher.matches()) { return ImmutableJsonServiceMatcher.of(jsonServiceMapping, matcher); } } return null; }