2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Respect Knolx session timings, you
are requested not to join sessions
after a 5 minutes threshold post
the session start time.
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Silent Mode
Keep your screen on mute, in case
you have question ask and mute
again.
Avoid Disturbance
Avoid unwanted chit chat during
the session.
4. What is Servlet?
Servlets are the Java programs that runs on the Java-enabled web server or application server.
Servlet is an interface, They are used to handle the request obtained from the web server,
process the request, produce the response, then send response back to the web server.
init() service() destroy()
public abstract class GenericServlet extends Object implements Servlet, ServletConfig,Serializable
abstract void service(ServletRequest req, ServletResponse res)
public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
doGet(HttpServletRequest req, HttpServletResponse resp)
doPost(HttpServletRequest req, HttpServletResponse resp)
doPut(HttpServletRequest req, HttpServletResponse resp)
doDelete(HttpServletRequest req, HttpServletResponse resp)
Lifecycle of a Servlet:
5. What is Filter?
A Filter is an object that is invoked at the preprocessing and postprocessing of a request.
It is mainly used to perform filtering tasks such as conversion, logging, compression,
encryption and decryption, input validation etc.
init() doFilter() destroy()
Lifecycle of a Filter:
Filter 1 Filter 2 Servlet
Request
Response
Request and Response Flow:
7. Spring Framework
The Spring Framework is an application framework and inversion of control container for the Java
platform.
The framework's core features can be used by any Java application, but there are extensions for
building web applications on top of the Java EE (Enterprise Edition) platform.
Inversion of Control is a programming pattern to achieve loose coupling where the independent
objects don't responsible for their dependencies. The Spring Inversion of Control container is the heart
of the Spring Framework. The IoC container receives metadata from either an XML file, Java
annotations, or Java code.
8. Spring Base Servlets
HttpServletBean
FrameworkServlet
DispatcherServlet
HttpServlet
● This servlet leaves request handling to subclasses, inheriting the default
behavior of HttpServlet (doGet, doPost, etc).
● Provides servlets that integrate with the application context infrastructure
● Mapping an HTTP request to a certain processing method.
● parsing of HTTP request data and headers into data transfer objects
● model-view-controller interaction.
● Generation of responses from DTOs
● Manages a WebApplicationContext instance per servlet.
● Publishes events on request processing, whether or not a request is successfully
handled
9. Spring Base Filters
DelegatingFilterProxy
FilterChainProxy
UsernamePasswordAuthenticationFilter
SecurityContextHolderAwareRequestFilter
ExceptionTranslationFilter
FilterSecurityInterceptor
Delegate the Filter's methods through to a bean which is obtained from the Spring application
context. This enables the bean to benefit from the Spring web application context lifecycle
support and configuration flexibility
FilterChainProxy guarantees to only initialize and destroy each Filter bean once, no matter
how many times it is declared in the filter chain(s).
Authentication processing mechanisms
Allows the user to determine if they are authenticated and if not send the user to the login page
To catch any Spring Security exceptions so that either an HTTP error response can be
returned or an appropriate AuthenticationEntryPoint can be launched
To protect web URIs and raise exceptions when access is denied
10. Aware Interfaces
Sometimes we might require access to framework objects, such as ApplicationContext,
BeanFactory, and ResourceLoader . To gain access, a bean can implement one of the many Aware
interfaces of the Spring Framework.
When a bean implements an Aware interface, the Spring Framework injects a particular framework
object to the bean through a callback-style method
For example, if the bean implements the ApplicationContextAware interface, Spring will inject an
ApplicationContext object in to the bean
In the bean lifecycle, the Spring Framework calls the aware interface methods after populating bean
properties and just before pre initialization
12. Bean Lifecycle : Extended
Instantiate
Call the setBeanFactory of
BeanFactoryAware
Next Aware Interface……..
Populate Properties
Call the setApplicationContext of
ApplicationContextAware
Pre-initialization by postProcessor()
of bean
Call setBeanName of
BeanNameAware
Next Aware Interface
afterPropertiesSet() of bean
Custom Init Method Post Initialization
BeanPostProcessors
Bean Ready To Use
13. Demo
In Demo I have created an application which we will run in debug mode and will see all the above
classes in debug stack.
Demo application is a Spring Boot application with Spring Security.