2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.service;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Optional;
33 import java.util.function.Function;
34 import java.util.stream.Collectors;
36 import javax.ws.rs.ApplicationPath;
37 import javax.ws.rs.core.Application;
39 import org.springframework.beans.factory.config.BeanDefinition;
40 import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
41 import org.springframework.core.type.filter.AnnotationTypeFilter;
42 import org.springframework.stereotype.Component;
45 @ApplicationPath("/restservices/clds/v1")
46 public class JaxrsApplication extends Application {
48 private static final EELFLogger logger = EELFManager.getInstance().getLogger(JaxrsApplication.class);
49 private Function<BeanDefinition, Optional<Class<?>>> beanDefinitionToClass = b -> {
51 return Optional.of(Class.forName(b.getBeanClassName()));
52 } catch (ClassNotFoundException e) {
53 logger.error("Could not get class annotated with @Path for swagger documentation generation", e);
54 return Optional.empty();
59 public Set<Class<?>> getClasses() {
60 Set<Class<?>> resources = new HashSet<>();
61 resources.add(JacksonObjectMapperProvider.class);
62 resources.add(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource.class);
63 resources.addAll(scan());
67 private List<Class<?>> scan() {
68 ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
69 scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));
70 return scanner.findCandidateComponents("org.onap.clamp.clds").stream().map(beanDefinitionToClass)
71 .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());