Search in sources :

Example 1 with RequestMapper

use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.RequestMapper in project FAAAST-Service by FraunhoferIOSB.

the class RequestMappingManager method init.

private void init() {
    try (ScanResult scanResult = new ClassGraph().enableAllInfo().acceptPackages(getClass().getPackageName()).scan()) {
        mappers = scanResult.getSubclasses(RequestMapper.class.getName()).filter(x -> !x.isAbstract() && !x.isInterface()).loadClasses(RequestMapper.class).stream().map(x -> {
            try {
                Constructor<RequestMapper> constructor = x.getConstructor(ServiceContext.class);
                return constructor.newInstance(serviceContext);
            } catch (NoSuchMethodException | SecurityException e) {
                LOGGER.warn("request mapper implementation could not be loaded, " + "reason: missing constructor (implementation class: {}, required constructor signature: {})", x.getName(), ServiceContext.class.getName(), e);
            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                LOGGER.warn("request mapper implementation could not be loaded, " + "reason: calling constructor failed (implementation class: {}, constructor arguments: {})", x.getName(), ServiceContext.class.getName(), e);
            }
            LOGGER.debug("unable to instantiate class {}", x.getName());
            return null;
        }).filter(x -> x != null).collect(Collectors.toList());
        mappers.stream().filter(x -> x == null).collect(Collectors.toList());
    }
}
Also used : ClassGraph(io.github.classgraph.ClassGraph) Logger(org.slf4j.Logger) HttpRequest(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest) LoggerFactory(org.slf4j.LoggerFactory) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) Constructor(java.lang.reflect.Constructor) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) InvalidRequestException(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.exception.InvalidRequestException) RequestMapper(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.RequestMapper) Request(de.fraunhofer.iosb.ilt.faaast.service.model.api.Request) Optional(java.util.Optional) ScanResult(io.github.classgraph.ScanResult) ScanResult(io.github.classgraph.ScanResult) Constructor(java.lang.reflect.Constructor) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) ClassGraph(io.github.classgraph.ClassGraph) RequestMapper(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.RequestMapper)

Aggregations

ServiceContext (de.fraunhofer.iosb.ilt.faaast.service.ServiceContext)1 InvalidRequestException (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.exception.InvalidRequestException)1 HttpRequest (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest)1 RequestMapper (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.RequestMapper)1 Request (de.fraunhofer.iosb.ilt.faaast.service.model.api.Request)1 ClassGraph (io.github.classgraph.ClassGraph)1 ScanResult (io.github.classgraph.ScanResult)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1