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