Tuesday, November 24, 2020

How to create and consume a SOAP based web service in JAVA

  • To create a SOAP webservice, you need to add the JAX-WS dependency to your project
                <dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>${jaxws-rt.version}</version>
</dependency>
  • Create an interface to expose the web methods e.g.

package com.arsoft.projects.artutorial.learning.soap.server;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface HelloWorldService {
@WebMethod
public String sayHello(String name);
}

  • Annotate the interface with @WebService and @SOAPBinding and the exposed method with @WebMethod
  • Create the implementation class e.g.

package com.arsoft.projects.artutorial.learning.soap.server;
import javax.jws.WebService;
@WebService(endpointInterface = "com.arsoft.projects.artutorial.learning.soap.server.HelloWorldService")
public class HelloWorldServiceImpl implements HelloWorldService {
public String sayHello(String name) {
return "Hello " + name + "!!";
}

  • Annotate the class with @WebService providing the fully qualified name of the interface as endpointInterface 
  • Publish the webservice as below

package com.arsoft.projects.artutorial.learning.soap.server;
import javax.xml.ws.Endpoint;
import com.arsoft.projects.artutorial.learning.soap.Constant;
public class SoapServer {
public static void main(String[] args) {
Endpoint.publish(Constant.helloWorldSoapServiceUrl, new HelloWorldServiceImpl());
}
}
                  •  To consume the above webservice, create the stubs from the wsdl by adding below plugin to the pom.xml file of the client application
                                       <plugin>
                  <groupId>com.sun.xml.ws</groupId>
                  <artifactId>jaxws-maven-plugin</artifactId>
                  <version>2.3.2</version>
                  <executions>
                  <execution>
                  <id>generate-java-sources</id>
                  <phase>process-sources</phase>
                  <goals>
                  <goal>wsimport</goal>
                  </goals>
                  <configuration>
                  <extension>true</extension>
                  <wsdlUrls>
                  <wsdlUrl>http://localhost:8888/ws/hello?wsdl</wsdlUrl>
                  </wsdlUrls>
                  </configuration>
                  </execution>
                  </executions>
                  </plugin>
                  • Add the JAX-WS dependency to the client project
                  •                 <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-rt</artifactId>
                    <version>${jaxws-rt.version}</version>
                    </dependency>

                  • Generate the stub classes by running maven goal 'mvn process-sources. The stub classes will be generated inside folder target/generated-sources. Copy the file to src directory
                  • Create the consumer class as below
                  package com.odigo.bre.reporting;
                  import java.net.MalformedURLException;
                  import java.net.URL;
                  import javax.xml.namespace.QName;
                  import javax.xml.ws.Service;
                  import com.arsoft.projects.artutorial.learning.soap.server.HelloWorldService;
                  public class SoapClient {
                      public static void main(String[] args) throws MalformedURLException {
                          URL webserviceURL = new URL("http://localhost:8888/ws/hello?wsdl");
                          QName qname = new QName("http://server.soap.learning.artutorial.projects.arsoft.com/",
                                  "HelloWorldServiceImplService");
                          Service service = Service.create(webserviceURL, qname);
                          HelloWorldService helloWorldService = service.getPort(HelloWorldService.class);
                          String message = helloWorldService.sayHello("Anshul Sood");
                          System.out.println(message);
                      }
                  }

                   where QName takes targetNamespace and name from wsdl as its arguments. 

                                      Thursday, May 4, 2017

                                      Git

                                      Set up the initial global configuration
                                      git config --global user.name "Anshul Sood"
                                      git config --global user.email "anshulsood2006@gmail.com

                                      Get all the configurations
                                      git config --list

                                      Get all the global configurations
                                      git config --global --list

                                      To get the help related to any/all commands
                                      git help config
                                      git help --all

                                      To ignore a file in the git operations add them in .gitignore file e.g.
                                      # ignore all bin directories matches "bin" in any subfolder
                                      bin/
                                      # ignore all target directories
                                      target/
                                      # ignore all files ending with ~
                                      *~

                                      To create a global gitignore to exclude bin folder
                                      cd ~/
                                      touch .gitignore
                                      echo "bin" >> .gitignore
                                      git config --global core.excludesfile ~/.gitignore

                                      Create a git repository
                                      Go to the folder
                                      git init


                                      Get the current status of git repository
                                      git status

                                      Add the file to staging area
                                      git add file1 file2 file3
                                      git all .

                                      Commit files to local repository
                                      git commit -m "Commit Message"

                                      To get history
                                      git log

                                      To show the changes
                                      git show

                                      To revert the changes to a file
                                      git checkout file1

                                      To add to the remote repository
                                      Create a repository on github and copy the URL
                                      git remote add origin "https://github.com/anshulsood2006/Documentation.git"
                                      git push origin {branchName}

                                      If getting error
                                      remote origin already exists
                                      git remote rm origin
                                      Updates were rejected because the tip of your current branch is behind
                                         git pull https://github.com/anshulsood2006/Documentation.git {branchName}
                                      refusing to merge unrelated histories
                                         git merge origin/{branchName} --allow-unrelated-histories

                                      To create a branch
                                      git branch {branchName}

                                      To go to the branch
                                      git checkout {branchName}

                                      To add brancb to remote
                                      git push origin testing

                                      To delete a branch
                                      git branch -D {branchName}

                                      To get the difference from the commit
                                      git diff {fileName}

                                      Sunday, November 13, 2016

                                      ClassLoader

                                      ClassLoader:
                                      Java class loader is a class which used to load classes at runtime. ClassLoader in Java works on three principle:
                                      • 1.       Delegation principle: Responsibility of loading class is of parent classloader. A classloader will load class only if parent is not able to find or load class.
                                      • 2.       Visibility principle: Child class loader can see all the classes loaded by parent ClassLoader, but parent class loader can not see classes loaded by child.
                                      • 3.       Uniqueness principle: A class should be loaded exactly once. This is basically achieved by delegation and ensures that child ClassLoader doesn't reload the class already loaded by parent.


                                      Types of Classloader:
                                      There are three default class loader used in Java:
                                      • 1.       Bootstrap ClassLoader/Primordial ClassLoader is responsible for loading standard JDK class files from rt.jar and it is parent of all class loaders in Java. Bootstrap class loader don't have any parents, if you call String.class.getClassLoader() it will return null and any code based on that may throw NullPointerException in Java.
                                      • 2.       Extension ClassLoader delegates class loading request to its parent, Bootstrap and if unsuccessful, loads class form jre/lib/ext directory or any other directory pointed by java.ext.dirs system property. Extension ClassLoader in JVM is implemented by sun.misc.Launcher$ExtClassLoader.
                                      • 3.       Application class loader is responsible for loading application specific classes from CLASSPATH environment variable, -classpath or -cp command line option, Class-Path attribute of Manifest file inside JAR. Application class loader is a child of Extension ClassLoader and its implemented by sun.misc.Launcher$AppClassLoader class.


                                      Except Bootstrap class loader, which is implemented in native language mostly in C, all Java class loaders are implemented using java.lang.ClassLoader.

                                      Explicitly load a class:
                                      Java provides API to explicitly load a class by
                                      • 1.       Class.forName(classname)
                                      • 2.       Class.forName(classname, initialized, classloader)


                                      Uses:
                                      • 1.       J2EE uses multiple class loaders to load class from different location e.g. classes from WAR file will be loaded by Web-app ClassLoader while classes bundled in EJB-JAR is loaded by another class loader.
                                      • 2.       Some web server also supports hot deploy functionality which is implemented using ClassLoader.
                                      • 3.       You can also use ClassLoader to load classes from database or any other persistent store.


                                      String.class.getClassLoader() returns null because this class is loaded by bootstrap classLoader which is not implemented in java , it's either implemented in c or c++ so there is no reference for it that's why it returns null.
                                      Why write a Custom ClassLoader in Java
                                      If you are expecting a class at the runtime or from FTP server or via third party web service at the time of loading the class then you have to extend the existing class loader.

                                      How does Java ClassLoader Work
                                      • 1.       When JVM requests for a class, it invokes loadClass function of the ClassLoader by passing the fully classified name of the Class.
                                      • 2.       loadClass function calls for findLoadedClass() method to check that the class has been already loaded or not. It’s required to avoid loading the class multiple times.
                                      • 3.       If the Class is not already loaded then it will delegate the request to parent ClassLoader to load the class.
                                      • 4.       If the parent ClassLoader is not finding the Class then it will invoke findClass() method to look for the classes in the file system.


                                      Custom ClassLoader in Java

                                      By extending ClassLoader class and overriding loadClass(String name) 

                                      Saturday, August 27, 2016

                                      Hibernate

                                      Hibernate is a high-performance Object/Relational persistence and query service which is licensed under the open source GNU Lesser General Public License (LGPL) and is free to download. Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities.

                                      It involves two files :-
                                      1. Hibernate configuration file (.cfg.xml)
                                      2. Hibernate mapping file (.hbm.xml) 
                                      Both these files are places in src folder. The configuration file is the main and the mapping file is declared inside it inside <mapping> tag with attribute resource.


                                      Hibernate configuration file :-




                                      <hibernate-configuration>  
                                      <session-factory>  
                                      <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property>  
                                      <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> 
                                       <!-- Assume test is the database name -->  
                                      <property name="hibernate.connection.url"> jdbc:mysql://localhost/test </property>  
                                      <property name="hibernate.connection.username"> root </property>  
                                      <property name="hibernate.connection.password"> root123  </property>  
                                      <!-- List of XML mapping files -->  
                                      <mapping resource="Employee.hbm.xml"/> 
                                       </session-factory>  
                                      </hibernate-configuration>

                                      Properties :- 
                                      hibernate.dialect  :-

                                      Hibernate Mapping File :-

                                      Monday, June 6, 2016

                                      Eclipse Issues

                                      Issue: 
                                      "Java compiler level does not match the version of the installed Java project facet."

                                      Resolution:
                                      Go to project >> Properties >> Project Facets and change the facets to required java version

                                      Issue:
                                      Unbound classpath container: 'JRE System Library' in project 'XYZ'

                                      Resolution:
                                      Go to Project >> build path >> Configure Buildpath >> Libraries >> Add Library >> JRE System Library >> Select an existing library

                                      Issue:
                                      "Cannot change version of project facet Dynamic Web Module to 3.0"

                                      Resolution:
                                      Change the attributes of web-app tag in web.xml file of the project to point to module 3.0


                                      Issue:
                                      The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

                                      Resolution:
                                      Add the dependency for java servlet api to the classpath

                                      Issue:
                                      How to enable to write mult-line string in eclipse

                                      Resolution:
                                      Go to Windows >> Preferences >> Java >> Editors >> Tying and Make sure that check box "Escape text when pasting into a string literal" is checked

                                      Issue:
                                      Warning message in an XML file "No grammar constraints (DTD or XML Schema) referenced in the document."

                                      Resolution:
                                      Just add <!DOCTYPE xml> below the tags <?xml version="1.0" encoding="UTF-8"?>

                                      Issue:
                                      While compiling maven project getting exception "Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project {project name}: Compilation failure: Compilation failure"

                                      Resolution:
                                      Go to pom.xml and remove <scope>test</scope> all the dependencies.

                                      Issue:

                                      Resolution:



                                      Thursday, June 2, 2016

                                      MAVEN

                                      MAVEN is an innovative software project management tool that provides new concept of a project object model (POM) file to manage project’s build, dependency and documentation. The most powerful feature is able to download the project dependency libraries automatically.

                                      Steps to install MAVEN:-
                                      • Download the  binary file form apache's site
                                      • Unzip the zip file and add to the environment variable.
                                      • To confirm installation use mvn -version on command prompt.
                                      A simple maven project consists of following folder structure
                                      •  project
                                        • src
                                          • main
                                            • java (the source code)
                                            • resources
                                          • test
                                            • java (the unit test code )
                                            • resources ()
                                        • pom.xml (the configuration file containing the information to build the project)
                                      POM.xml stands for Project Object Model and it has the below structure

                                      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                                      <modelVersion>4.0.0</modelVersion>
                                      <groupId>PROJECT_NAME_IN_PACKAGE_NAME_STYLE</groupId>
                                      <artifactId>NAME_OF_JAR</artifactId>
                                      <version>VERSION_OF_JAR</version>
                                      </project>

                                      MVN Install:-
                                      • It is used to install the package to local repository so that it can be referenced by several projects
                                      MVN package:-
                                      •  It is used to build the project
                                      mvn archetype:generate:-

                                      To create a java project in java 
                                      mvn archetype:generate
                                      -DgroupId=com.anshul.ws
                                      -DartifactId=MyWebService
                                      -DarchetypeArtifactId=maven-archetype-quickstart
                                      -DinteractiveMode=false

                                      To support eclipse

                                      mvn eclipse:eclipse -Dwtpversion=2.0
                                      Life cycle of Maven:-
                                      Like we have targets in case of Ant , we have phases in maven

                                      Features of MAVEN:-
                                      • Build process becomes very easy
                                      To create a web-app using maven
                                      1. Using command prompt go to the directory where project needs to be created
                                      2. Type below
                                        mvn archetype:generate -DgroupId=org.arsoft.projects.sood -DartifactId=arsood -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
                                      3. To be able to access the project on eclipse go to the directory and run command
                                        mvn eclipse:eclipse -Dwtpversion=2.0
                                      To create a Java project:

                                      mvn archetype:generate -DgroupId=org.arsoft.projects.sood -DartifactId=arsood -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

                                      To create an EJB project:

                                      mvn archetype:generate -DgroupId=com.arsoft.projects -DartifactId=Common -DarchetypeArtifactId=ejb-javaee6 -DinteractiveMode=false

                                      Understanding POM
                                      1. It stands for Project Object Model and is the fundamental unit of work in maven.

                                      Saturday, January 4, 2014

                                      WeCare

                                      1. All the tables would be under a database named WECARE.
                                      2. To register a hospital to WeCare, the hospital is provided some credentials by WeCare and these will be called WeCareRegisterationCredentials.
                                        1. These will be stored in table called LICENSE.
                                        2. This table will not be accessible to the hospitals
                                        3.  The credentials will be able to register as many hospitals as purchased by the user in license agreement. The maximum number can be controlled by an external property
                                      3. Many members would be able to be registered under the hospital. The main types of the members would be
                                        1. Doctors
                                        2. Clinical Staff (Nurses,Pharmacists)
                                        3. Non Clinical Staff (Clerk, Drivers)\
                                      4.  
                                         

                                      Wednesday, December 25, 2013

                                      Struts

                                      1. Struts2 is configured in web.xml file using filter and filter-mapping tags as below
                                          <filter>
                                              <filter-name>struts2</filter-name>
                                              <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
                                              <init-param>
                                               <param-name>config</param-name>
                                               <param-value>struts-default.xml,struts-plugin.xml,/resources/struts.xml</param-value>
                                              </init-param>
                                          </filter>
                                          <filter-mapping>
                                              <filter-name>struts2</filter-name>
                                              <url-pattern>/*</url-pattern>
                                          </filter-mapping>
                                       2. The default location of struts.xml can be changed by giving the desired location in init-param of filter tag as given above.
                                      3. Properties file can be accessed in struts2 using  a  constant in struts.xml as below:-
                                      <constant name="struts.custom.i18n.resources" value="resources/ApplicationResources" />
                                      4. Struts tags can be used in jsp files using taglib directives as below:-
                                      <%@ taglib uri="/struts-tags" prefix="s" %>
                                       

                                      Monday, December 16, 2013

                                      Collections Framework

                                      This framework has following features
                                      1. The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hashtables) are highly efficient.
                                      2. The framework had allows different types of collections to work in a similar manner and with a high degree of interoperability.
                                      3. Extending and/or adapting a collection is very easy.
                                      Collections frameworks contain the following:
                                      1. Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy. These are the basic interfaces in this framework
                                        1. Collection Interface
                                          1. It is at the top of hierarchy.
                                        2. List Interface:-
                                          1.  It extends collection interface
                                          2. Elements can be inserted or accessed by their position in the list, using a zero-based index.
                                          3. A list may contain duplicate elements.
                                          4. Implementations are ArrayList and LinkedList
                                        3. Set:-
                                          1. A Set is a Collection that cannot contain duplicate elements.
                                          2. Null can not be used. 
                                          3. Implementations are HashSet
                                        4. SortedSet
                                          1. The SortedSet interface extends Set and declares the behavior of a set sorted in ascending order
                                          2. Null can not be used. \
                                          3. Implementations are TreeSet
                                        5. Map
                                          1.  Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key
                                          2. Null can not be used.   
                                          3. Implementations are HashMap
                                        6. MapEntry
                                          1. It enables you to work with a map entry that is the set of map keys
                                        7.  SortedMap
                                          1. The SortedMap interface extends Map. It ensures that the entries are maintained in ascending key order
                                          2. Implementations are TreeMap.
                                        8. Enumeration
                                          1. It helps to deal with one element at a time for any collection
                                          2. It is almost obsolete and is replaced by iterator interface.

                                      2. Implementations, i.e., Classes: These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.The main implementation classes of each of the collection interfaces are  given above already in the interface definitions
                                      3. Algorithms: These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.
                                      ArrayList and Vector:-
                                      1. Synchronization - ArrayList is not thread-safe whereas Vector is thread-safe. In Vector class each method like add(), get(int i) is surrounded with a synchronized block and thus making Vector class thread-safe.
                                      2. Data growth -Internally, both the ArrayList and Vector hold onto their contents using an Array. When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
                                      Synchronizing a non-synchronized Collection
                                      1. Collection.synchronizedList(List list)
                                      2. Collection.synchronizedCollection(Collection collection)
                                      3. Collection.synchronizedMap(Map map)
                                      HashMap and HashTable:-
                                      1. HashMap is not synchronized whereas HashTable is.
                                      2. HaspMap permits null values in both key and value
                                      3. HaspMap is 
                                      List:- Classes are ArrayList, LinkedList, Vector
                                      1. ArrayList :- resizable array and is indexed, non sysnchronized. It grows 50% of its size when more elements are added
                                      2. LinkedList :- double linked list and is indexed, get and set decreases performance while add and remove are fast and is non sysnchronized
                                      3. Vector : - It is synchronized and doubles its size when more elements are added. It also implements Queque interface so more methods like offer, peak, poll etc are available.
                                      Set :- Classes are HashSet, LinkedHashSet and TreeSet
                                      1. HashSet: -Allows one null, order is not maintained.
                                      2. LinkedHashSet :- Order is maintained, one null allowed
                                      3. TreeSet :- Order is maintained, null is not allowed
                                      Map :- Classes are HashMap, HashTable and TreeMap
                                      1. HashMap : It allows ONLY one null key and multiple null values. Ordered on the basis of keys. It is not synschronized
                                      2. TreeMap :- Null keys are not allowed at all but null values are.
                                      3. HashTable :- It is synchronized but unordered and null keys and null values are not allowed at all 

                                      Resource: http://www.docjar.com/html/api/java/util/

                                      Collection Interface:

                                      List Interface


                                         

                                      Thursday, November 21, 2013

                                      Web Services in JAVA

                                      REST :- Stands for Representation State Transfer and is an architectural style of client-server application centered around the transfer of representations of resources through requests and responses.

                                      The Web is comprised of resources. A resource is any item of interest. For example, the Boeing Aircraft Corp may define a 747 resource. Clients may access that resource with this URL:
                                      http://www.boeing.com/aircraft/747
                                      
                                      A representation of the resource is returned (e.g., Boeing747.html). The representation places the client application in a state. The result of the client traversing a hyperlink in Boeing747.html is another resource is accessed. The new representation places the client application into yet another state. Thus, the client application changes (transfers) state with each resource representation --> Representational State Transfer! Here is Roy Fielding's explanation of the meaning of Representational State Transfer: "Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use."
                                      In the REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs)

                                      Note: URI (Uniform Resource Identifier) consists of either URL (Uniform Resource Locator )or URN(Uniform Resource Name) or both

                                      REST is an Architectural Style, not a Standard
                                      While REST is not a standard, it does use standards:
                                      • HTTP
                                      • URL
                                      • XML/HTML/GIF/JPEG/etc (Resource Representations)
                                      • text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)
                                      The web service makes available a URL to a list of  resource. For example, a client would use this URL to get the parts list:
                                      http://www.parts-depot.com/parts
                                      
                                      Note that "how" the web service generates the list is completely transparent to the client. All the client knows is that if he/she submits the above URL then a document containing the list of resources is returned. Since the implementation is transparent to clients, Parts Depot is free to modify the underlying implementation of this resource without impacting clients. This is loose coupling.

                                      Principles of REST Web Service Design
                                      1. The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services. Above we saw some examples of resources: parts list, detailed part data, purchase order. 2. Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:
                                      http://www.parts-depot.com/parts/getPart?id=00345
                                      
                                      Note the verb, getPart. Instead, use a noun:
                                      http://www.parts-depot.com/parts/00345
                                      
                                      3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.  
                                      4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.  
                                      5. No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information.  
                                      6. Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details.
                                      7. Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron). For those services that require a POST or PUT to it, also provide a schema to specify the format of the response.
                                      8. Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.
                                      Reference:-
                                      http://www.xfront.com/REST-Web-Services.html
                                      http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/

                                       







                                      Web.xml

                                      References:-
                                      http://download.oracle.com/docs/cd/E13222_01/wls/docs81/webapp/web_xml.html
                                      This file is used to define each servlet and JSP page inside a web-application.
                                      It is found in WEB-INF directory under the document root of the web application.
                                      It is also called Deployment Descriptor

                                      Context parameters are accessible to any servlet or JSP in the web-app and can be accessed through ServletContext object.
                                      String value = getServletContext().getInitParameter("name_of_context_initialization_parameter");

                                      For springs Context param name for
                                          application context is  "contextConfigLocation" with value "*.xml"
                                          log4j is "log4jConfigLocation" with value "*.properties"
                                          applicationContext.xml is an XML file having the context parameters

                                      Init parameters are specific to a particular servlet and and can be accessed through ServletConfig object.
                                      String value = getServletConfig().getInitParameter("name_of_context_initialization_parameter");

                                      load-on-startup gives the order in which the servlet will initialize

                                      <?xml version="1.0" encoding="ISO-8859-1"?>
                                      <!DOCTYPE web-app
                                          PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                                          "http://java.sun.com/dtd/web-app_2_3.dtd">
                                      <web-app>
                                          <display-name>The name of the application </display-name>
                                          <description>Description of Application</description>
                                          <welcome-file-list>
                                                 <welcome-file>index.jsp</welcome-file>
                                          </welcome-file-list>
                                          <context-param>
                                           <description>Description of parameter</description>
                                           <param-name>name_of_context_initialization_parameter</param-name>
                                           <param-value>value_of_context_initializtion_parameter</param-value>
                                          </context-param>

                                       //In case of Servlets , we define our own Servlet classes and corresponding mappings are given  in web.xml

                                          <servlet>
                                           <servlet-name>guess_what_name_of_servlet</servlet-name>
                                           <description>Again, some description</description>
                                           <servlet-class>com.foo-bar.somepackage.TheServlet</servlet-class>
                                           <init-param>
                                             <param-name>foo</param-name>
                                             <param-value>bar</param-value>
                                           </init-param>
                                           <load-on-startup>1</load-on-startup>
                                          </servlet>
                                          <servlet-mapping>
                                           <servlet-name>name_of_a_servlet</servlet-name>
                                           <url-pattern>*.some_pattern</url-pattern>
                                          </servlet-mapping>


                                       //In case of struts 2 , we define the filters and corresponding mapping of FilterDispatcher in web.xml
                                         <filter>
                                            <filter-name>struts2</filter-name>
                                            <filter-class>
                                               org.apache.struts2.dispatcher.FilterDispatcher
                                            </filter-class>
                                         </filter>
                                         <filter-mapping>
                                            <filter-name>struts2</filter-name>
                                            <url-pattern>/*</url-pattern>
                                         </filter-mapping>

                                      //In case of springs, we define the servlet and  corresponding mapping of Dispatcher Serv
                                          <servlet>
                                              <servlet-name>employee</servlet-name>
                                              <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
                                              <load-on-startup>1</load-on-startup>
                                          </servlet>
                                          <servlet-mapping>
                                              <servlet-name>employee</servlet-name>
                                              <url-pattern>/</url-pattern>
                                          </servlet-mapping>
                                          <context-param>
                                              <param-name>contextConfigLocation</param-name>
                                              <param-value>/WEB-INF/employee-servlet.xml</param-value>
                                          </context-param>
                                          <session-config>
                                           <session-timeout>30</session-timeout>
                                          </session-config>
                                      </web-app>

                                      SpringBoot Application Event Listeners

                                      When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...