Now, this method is private and the modification is simple.
The impact is big. You can control how an application instance is created (by default an application instance is created using applicationClassName init parameter supplied in web.xml).
For example, this modification allows me to use a PippoApplication defined as Spring bean in Spring configuration.
The steps are:
- create a custom filter that knows how to retrieves the Pippo application bean from Spring
public class SpringPippoFilter extends PippoFilter {
@Override
protected void createApplication(FilterConfig filterConfig) {
ServletContext servletContext = filterConfig.getServletContext();
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
Application application = (Application) applicationContext.getBean("pippoApplication");
setApplication(application);
}
}
- define Pippo application as bean in Spring configuration
@Configuration
public SpringConfig {
@Bean
public FrontendApplication pippoApplication() {
return new FrontendApplication();
}
@Bean
public ProductService productService() {
return new DefaultProductService();
}
// other beans injected via @Autowire in pippoApplication
}
- inject in your Pippo application other components managed by Spring (for example
ProductService in my case)
@Component
public class FrontendApplication extends Application {
@Autowired
private ProductService productService;
@Override
protected void onInit() {
getRouter().ignorePaths("/admin"); // Wicket application
// send 'Hello World' as response
GET("/", routeContext -> routeContext.send("Hello World"));
GET("/products", routeContext -> routeContext.text().send(productService.count()));
}
}
- specify where Spring keeps configuration (
SpringConfig in our case) and specify that I want to use my custom filter SpringPippoFilter instead of default PippoFilter (that comes with pippo-core)
[web.xml]
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>SpringConfig</param-value>
</context-param>
<filter>
<filter-name>pippo.filter</filter-name>
<filter-class>SpringPippoFilter</filter-class>
</filter>
Sure this modification is not valuable is you don't use the web.xml standard descriptor file to specify your Pippo application.
Now, this method is
private and the modification is simple.The impact is big. You can control how an application instance is created (by default an application instance is created using
applicationClassNameinit parameter supplied inweb.xml).For example, this modification allows me to use a
PippoApplicationdefined as Spring bean in Spring configuration.The steps are:
ProductServicein my case)SpringConfigin our case) and specify that I want to use my custom filterSpringPippoFilterinstead of defaultPippoFilter(that comes withpippo-core)[web.xml]
Sure this modification is not valuable is you don't use the
web.xmlstandard descriptor file to specify your Pippo application.