Search in sources :

Example 1 with WebServiceInterfaceValidator

use of core.framework.impl.web.service.WebServiceInterfaceValidator in project core-ng-project by neowu.

the class APIConfig method client.

public <T> APIClientConfig client(Class<T> serviceInterface, String serviceURL) {
    logger.info("create api service client, interface={}, serviceURL={}", serviceInterface.getCanonicalName(), serviceURL);
    RequestBeanMapper requestBeanMapper = context.httpServer.handler.requestBeanMapper;
    new WebServiceInterfaceValidator(serviceInterface, requestBeanMapper, context.httpServer.handler.responseBeanTypeValidator).validate();
    HTTPClient httpClient = httpClient();
    WebServiceClient webServiceClient = new WebServiceClient(serviceURL, httpClient, requestBeanMapper, context.logManager);
    T client = createWebServiceClient(serviceInterface, webServiceClient);
    context.beanFactory.bind(serviceInterface, null, client);
    return new APIClientConfig(webServiceClient);
}
Also used : HTTPClient(core.framework.http.HTTPClient) RequestBeanMapper(core.framework.impl.web.bean.RequestBeanMapper) WebServiceInterfaceValidator(core.framework.impl.web.service.WebServiceInterfaceValidator) WebServiceClient(core.framework.impl.web.service.WebServiceClient)

Example 2 with WebServiceInterfaceValidator

use of core.framework.impl.web.service.WebServiceInterfaceValidator 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);
}
Also used : Path(core.framework.api.web.service.Path) HTTPMethod(core.framework.http.HTTPMethod) Method(java.lang.reflect.Method) Controller(core.framework.web.Controller) APIController(core.framework.impl.web.management.APIController) ControllerHolder(core.framework.impl.web.ControllerHolder) HTTPMethod(core.framework.http.HTTPMethod) WebServiceInterfaceValidator(core.framework.impl.web.service.WebServiceInterfaceValidator)

Aggregations

WebServiceInterfaceValidator (core.framework.impl.web.service.WebServiceInterfaceValidator)2 Path (core.framework.api.web.service.Path)1 HTTPClient (core.framework.http.HTTPClient)1 HTTPMethod (core.framework.http.HTTPMethod)1 ControllerHolder (core.framework.impl.web.ControllerHolder)1 RequestBeanMapper (core.framework.impl.web.bean.RequestBeanMapper)1 APIController (core.framework.impl.web.management.APIController)1 WebServiceClient (core.framework.impl.web.service.WebServiceClient)1 Controller (core.framework.web.Controller)1 Method (java.lang.reflect.Method)1