001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.microservice.springboot.template;
014
015import org.apache.juneau.rest.springboot.*;
016import org.apache.juneau.rest.springboot.annotation.*;
017import org.springframework.boot.autoconfigure.SpringBootApplication;
018import org.springframework.boot.builder.*;
019import org.springframework.boot.web.servlet.FilterRegistrationBean;
020import org.springframework.context.annotation.*;
021import org.springframework.stereotype.Controller;
022import org.springframework.web.filter.HiddenHttpMethodFilter;
023
024/**
025 * Entry point for Examples REST application when deployed as a Spring Boot application.
026 */
027@SpringBootApplication
028@Controller
029public class App {
030
031   /**
032    * Entry point method.
033    *
034    * @param args Command-line arguments
035    */
036   public static void main(String[] args) {
037      new SpringApplicationBuilder(App.class)
038         .initializers(new JuneauRestInitializer(App.class))
039         .run(args);
040   }
041
042   /**
043    * @return Our root resource.
044    */
045   @Bean @JuneauRestRoot
046   public RootResources getRootResources() {
047      return new RootResources();
048   }
049
050
051   /**
052    * If you want to parse URL-encoded form posts directly into beans, this call will disable the HiddenHttpMethodFilter
053    * which triggers form posts to be consumed.
054    *
055    * @param filter The filter to alter.
056    * @return The registration bean.
057    */
058   @Bean
059   public FilterRegistrationBean<HiddenHttpMethodFilter> registration(HiddenHttpMethodFilter filter) {
060       FilterRegistrationBean<HiddenHttpMethodFilter> registration = new FilterRegistrationBean<>(filter);
061       registration.setEnabled(false);
062       return registration;
063   }
064}