d6721b21d0107eabcbdb10f2ebd958ec5e3ccbc6
[aai/sparky-be.git] / sparkybe-onap-application / src / main / java / org / onap / aai / sparky / Application.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 /**
26  * This copy of Woodstox XML processor is licensed under the
27  * Apache (Software) License, version 2.0 ("the License").
28  * See the License for details about distribution rights, and the
29  * specific rights regarding derivate works.
30  *
31  * You may obtain a copy of the License at:
32  *
33  * http://www.apache.org/licenses/
34  *
35  * A copy is also included in the downloadable source code package
36  * containing Woodstox, in file "ASL2.0", under the same directory
37  * as this file.
38  */
39 package org.onap.aai.sparky;
40
41 import org.apache.camel.builder.RouteBuilder;
42 import org.apache.camel.component.servlet.CamelHttpTransportServlet;
43 import org.apache.camel.model.rest.RestBindingMode;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
46 import org.springframework.boot.SpringApplication;
47 import org.springframework.boot.autoconfigure.SpringBootApplication;
48 import org.springframework.boot.web.servlet.ServletRegistrationBean;
49 import org.springframework.boot.web.support.SpringBootServletInitializer;
50 import org.springframework.context.ApplicationContext;
51 import org.springframework.context.annotation.Bean;
52 import org.springframework.stereotype.Component;
53
54 @SpringBootApplication
55 public class Application  /*extends SpringBootServletInitializer */ {
56   
57   private @Autowired AutowireCapableBeanFactory beanFactory;
58
59   public static void main(String[] args) {
60
61     ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
62
63     /*for (String name : applicationContext.getBeanDefinitionNames()) {
64       System.out.println(name);
65     }*/
66
67   }
68   
69  /* @Component
70   class RestApi extends RouteBuilder {
71
72       @Override
73       public void configure() {
74         
75       //restConfiguration().component("restlet").contextPath("/rs").bindingMode(RestBindingMode.json);
76         
77
78           /*rest("/books").description("Books REST service")
79               .get("/").description("The list of all the books")
80                   .route().routeId("books-api")
81                   .bean(Database.class, "findBooks")
82                   .endRest()
83               .get("order/{id}").description("Details of an order by id")
84                   .route().routeId("order-api")
85                   .bean(Database.class, "findOrder(${header.id})");*/
86    /*   }
87   }*/
88   
89
90   /*
91    * TODO:  we need to figure out the initialization required for our restlets
92    */
93       
94       /*@Bean
95       public ServletRegistrationBean restletBootstrapInitialization() {
96           
97           SpringServerServlet serverServlet = new SpringServerServlet();
98           ServletRegistrationBean regBean = new ServletRegistrationBean( serverServlet, "/rest/*");
99           
100           
101           Map<String,String> params = new HashMap<String,String>();
102           
103           params.put("org.restlet.component", "restletComponent");
104           
105           regBean.setInitParameters(params);
106           
107           return regBean;
108       }*/
109       
110       
111      
112   /*
113    * This initialization code enabled access to aai-ui-proxy-processor
114    */
115   
116   @Bean
117   ServletRegistrationBean servletRegistrationBean() {
118     final ServletRegistrationBean servlet =
119         new ServletRegistrationBean(new CamelHttpTransportServlet(), "/rest/*");
120     servlet.setName("CamelServlet");
121     return servlet;
122   }
123
124  /* @Bean
125   public EmbeddedServletContainerFactory servletContainerFactory() {
126     return new TomcatEmbeddedServletContainerFactory() {
127       
128       /*
129        * Stackoverflow solution for adding a WAR into our embedded tomcat runtime
130        * https://stackoverflow.com/questions/31374726/spring-boot-how-to-add-another-war-files-to-the-embedded-tomcat
131        */
132       
133
134   /*    @Override
135       protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
136         // Ensure that the webapps directory exists
137         System.out.println("catalina base = " + tomcat.getServer().getCatalinaBase());
138         new File(tomcat.getServer().getCatalinaBase(), "webapps").mkdirs();
139
140         try {
141           Context context = tomcat.addWebapp("/services/aai/webapp", "X:\\2018_dev\\OSEAAI\\NUC-7257-spring-boot-conversion\\onap_sparky-be\\src\\main\\resources\\extApps\\aai.war");
142
143           // Allow the webapp to load classes from your fat jar
144           context.setParentClassLoader(getClass().getClassLoader());
145         } catch (ServletException ex) {
146           throw new IllegalStateException("Failed to add webapp", ex);
147         }
148         return super.getTomcatEmbeddedServletContainer(tomcat);
149       }
150
151     };
152   }*/
153
154   /**
155    * bind LoginFilter 
156    */
157   
158   /*@Bean
159   public FilterRegistrationBean myFilter() {
160       FilterRegistrationBean registration = new FilterRegistrationBean();
161       Filter myFilter = new LoginFilter();
162       beanFactory.autowireBean(myFilter);
163       registration.setFilter(myFilter);
164       registration.addUrlPatterns("/*");
165       return registration;
166   }*/
167   
168       
169   
170   
171 }