use of core.framework.impl.web.route.PathPatternValidator in project core-ng-project by neowu.
the class ModuleContext method route.
public void route(HTTPMethod method, String path, Controller controller, boolean skipInterceptor) {
new PathPatternValidator(path).validate();
ControllerInspector inspector = new ControllerInspector(controller);
new ControllerClassValidator(inspector.targetClass, inspector.targetMethod).validate();
String action = "http:" + ASCII.toLowerCase(method.name()) + ":" + path;
httpServer.handler.route.add(method, path, new ControllerHolder(controller, inspector.targetMethod, inspector.controllerInfo, action, skipInterceptor));
}
use of core.framework.impl.web.route.PathPatternValidator in project core-ng-project by neowu.
the class WebServiceInterfaceValidator method validate.
private void validate(Method method) {
validateHTTPMethod(method);
HTTPMethod httpMethod = HTTPMethods.httpMethod(method);
Path path = method.getDeclaredAnnotation(Path.class);
if (path == null)
throw Exceptions.error("method must have @Path, method={}", method);
new PathPatternValidator(path.value()).validate();
validateResponseBeanType(method.getGenericReturnType());
Set<String> pathVariables = pathVariables(path.value());
Type requestBeanType = null;
Annotation[][] annotations = method.getParameterAnnotations();
Type[] paramTypes = method.getGenericParameterTypes();
Set<String> pathParams = Sets.newHashSet();
for (int i = 0; i < paramTypes.length; i++) {
Type paramType = paramTypes[i];
PathParam pathParam = Params.annotation(annotations[i], PathParam.class);
if (pathParam != null) {
validatePathParamType(paramType);
pathParams.add(pathParam.value());
} else {
if (requestBeanType != null)
throw Exceptions.error("service method must not have more than one bean param, previous={}, current={}", requestBeanType.getTypeName(), paramType.getTypeName());
requestBeanType = paramType;
if (httpMethod == HTTPMethod.GET || httpMethod == HTTPMethod.DELETE) {
requestBeanMapper.registerQueryParamBean(requestBeanType);
} else {
requestBeanMapper.registerRequestBean(requestBeanType);
}
}
}
if (pathVariables.size() != pathParams.size() || !pathVariables.containsAll(pathParams))
throw Exceptions.error("service method @PathParam params must match variable in path pattern, path={}, method={}", path.value(), method);
}
Aggregations