2 * ============LICENSE_START=======================================================
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
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=========================================================
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.
27 * You may obtain a copy of the License at:
29 * http://www.apache.org/licenses/
31 * A copy is also included in the downloadable source code package
32 * containing Woodstox, in file "ASL2.0", under the same directory
35 package org.onap.aai.sparky;
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;
50 @SpringBootApplication
51 public class Application /*extends SpringBootServletInitializer */ {
53 private @Autowired AutowireCapableBeanFactory beanFactory;
55 public static void main(String[] args) {
57 ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
59 /*for (String name : applicationContext.getBeanDefinitionNames()) {
60 System.out.println(name);
66 class RestApi extends RouteBuilder {
69 public void configure() {
71 //restConfiguration().component("restlet").contextPath("/rs").bindingMode(RestBindingMode.json);
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")
79 .get("order/{id}").description("Details of an order by id")
80 .route().routeId("order-api")
81 .bean(Database.class, "findOrder(${header.id})");*/
87 * TODO: we need to figure out the initialization required for our restlets
91 public ServletRegistrationBean restletBootstrapInitialization() {
93 SpringServerServlet serverServlet = new SpringServerServlet();
94 ServletRegistrationBean regBean = new ServletRegistrationBean( serverServlet, "/rest/*");
97 Map<String,String> params = new HashMap<String,String>();
99 params.put("org.restlet.component", "restletComponent");
101 regBean.setInitParameters(params);
109 * This initialization code enabled access to aai-ui-proxy-processor
113 ServletRegistrationBean servletRegistrationBean() {
114 final ServletRegistrationBean servlet =
115 new ServletRegistrationBean(new CamelHttpTransportServlet(), "/rest/*");
116 servlet.setName("CamelServlet");
121 public EmbeddedServletContainerFactory servletContainerFactory() {
122 return new TomcatEmbeddedServletContainerFactory() {
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
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();
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");
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);
144 return super.getTomcatEmbeddedServletContainer(tomcat);
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("/*");