use of core.framework.impl.web.management.APIController in project core-ng-project by neowu.
the class APIConfig method apiController.
private APIController apiController() {
if (state.apiController == null) {
state.apiController = new APIController();
context.route(HTTPMethod.GET, "/_sys/api", state.apiController, true);
}
return state.apiController;
}
use of core.framework.impl.web.management.APIController in project core-ng-project by neowu.
the class APIConfig method service.
public <T> void service(Class<T> serviceInterface, T service) {
logger.info("create api service, interface={}", serviceInterface.getCanonicalName());
new WebServiceInterfaceValidator(serviceInterface, context.httpServer.handler.requestBeanMapper, context.httpServer.handler.responseBeanTypeValidator).validate();
new WebServiceImplValidator<>(serviceInterface, service).validate();
for (Method method : serviceInterface.getMethods()) {
HTTPMethod httpMethod = HTTPMethods.httpMethod(method);
String path = method.getDeclaredAnnotation(Path.class).value();
Controller controller = new WebServiceControllerBuilder<>(serviceInterface, service, method).build();
try {
Class<?>[] parameterTypes = method.getParameterTypes();
Class<?> serviceClass = service.getClass();
Method targetMethod = serviceClass.getMethod(method.getName(), parameterTypes);
String controllerInfo = serviceClass.getCanonicalName() + "." + targetMethod.getName();
String action = "api:" + ASCII.toLowerCase(httpMethod.name()) + ":" + path;
context.httpServer.handler.route.add(httpMethod, path, new ControllerHolder(controller, targetMethod, controllerInfo, action, false));
} catch (NoSuchMethodException e) {
throw new Error("failed to find impl method", e);
}
}
apiController().serviceInterfaces.add(serviceInterface);
}
Aggregations