2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
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.
31 * You may obtain a copy of the License at:
33 * http://www.apache.org/licenses/
35 * A copy is also included in the downloadable source code package
36 * containing Woodstox, in file "ASL2.0", under the same directory
39 package org.onap.aai.sparky;
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;
54 @SpringBootApplication
55 public class Application /*extends SpringBootServletInitializer */ {
57 private @Autowired AutowireCapableBeanFactory beanFactory;
59 public static void main(String[] args) {
61 ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
63 /*for (String name : applicationContext.getBeanDefinitionNames()) {
64 System.out.println(name);
70 class RestApi extends RouteBuilder {
73 public void configure() {
75 //restConfiguration().component("restlet").contextPath("/rs").bindingMode(RestBindingMode.json);
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")
83 .get("order/{id}").description("Details of an order by id")
84 .route().routeId("order-api")
85 .bean(Database.class, "findOrder(${header.id})");*/
91 * TODO: we need to figure out the initialization required for our restlets
95 public ServletRegistrationBean restletBootstrapInitialization() {
97 SpringServerServlet serverServlet = new SpringServerServlet();
98 ServletRegistrationBean regBean = new ServletRegistrationBean( serverServlet, "/rest/*");
101 Map<String,String> params = new HashMap<String,String>();
103 params.put("org.restlet.component", "restletComponent");
105 regBean.setInitParameters(params);
113 * This initialization code enabled access to aai-ui-proxy-processor
117 ServletRegistrationBean servletRegistrationBean() {
118 final ServletRegistrationBean servlet =
119 new ServletRegistrationBean(new CamelHttpTransportServlet(), "/rest/*");
120 servlet.setName("CamelServlet");
125 public EmbeddedServletContainerFactory servletContainerFactory() {
126 return new TomcatEmbeddedServletContainerFactory() {
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
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();
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");
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);
148 return super.getTomcatEmbeddedServletContainer(tomcat);
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("/*");