Spring Dependencies for Maven

<?xml version="1.0" encoding="UTF-8"?><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>com.practice.spring</groupId>
    <artifactId>SpringPractice</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
    </dependencies>

</project>

You might also like:









Servlet Filter

- Filter help to block a malicious request if they are not allowed to access a backend resource.
- Filter also help to manipulate the responses that will be sent back to the client.

Different types of filters:
  1. Authentication-Blocking: Block or allow any requests based on user identity.
  2. Logging and auditing: Helps in user tracking.
  3. Image conversion: Helps with scaling maps
  4. Data compression: Reduces download size
  5. Localization: Helps support the code in various countries based on different languages and formatting. 
  6. Encryption filters
  7. Tokenizing filters
  8. Mime-type chaining filters
  9. Caching filters
  10. XSL/T Filters: Helps transforming XML requests.

- Filters are specified in web.xml and are executed in the order specified in the file.
- Filter java class implements javax.servlet.Filter and implements these 3 methods: init(), doFilter(), destroy()

import javax.servlet.*;
import java.util.logging.Filter;

public class TestFilter implements Filter {
    public void  init(FilterConfig config) throws ServletException {
        //Get and print init param                
        String testParam = config.getInitParameter("param1");
        System.out.println("Test Param: " + testParam);
    }

    public void  doFilter(ServletRequest request,
                          ServletResponse response,
                          FilterChain chain)
            throws java.io.IOException, ServletException {

        // Get the method of the request
        String method = request.getMethod();
        logger.info("Request Method is: ", method);

        // Pass request back down the filter chain
        chain.doFilter(request,response);
    }
    public void destroy( ){
        //close any resources here        }
}

Compile TestFilter.java in usual way and put your class file in <Tomcat-installation-directory>/webapps/ROOT/WEB-INF/classes

Make following config change in the web.xml
<filter>
    <filter-name>TestFilter</filter-name>
    <filter-class>TestFilter</filter-class>
    <init-param>
        <param-name>param1</param-name>
        <param-value>Test</param-value>
    </init-param>
</filter>
<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

The TestFilter will apply to all the servlets since we specified url-pattern as /*. For example if we want to apply TestFilter to only a class called as TestFile then the config will look like
<filter>
    <filter-name>TestFilter</filter-name>
    <filter-class>TestFilter</filter-class>
    <init-param>
        <param-name>param1</param-name>
        <param-value>Test</param-value>
    </init-param>
</filter>
<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern>TestFile</url-pattern>
</filter-mapping>

Multiple filters
<filter>
    <filter-name>TestFilter</filter-name>
    <filter-class>TestFilter</filter-class>
    <init-param>
        <param-name>param1</param-name>
        <param-value>Value1</param-value>
    </init-param>
</filter>

<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>TestFilter2</filter-name>
<filter-class>TestFilter2</filter-class>
<init-param>
    <param-name>param</param-name>
    <param-value>Value</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>TestFilter2</filter-name>
<url-pattern>TestFile</url-pattern>
</filter-mapping>
In this example, TestFilter will be applied followed by TestFilter2.

You might also like:
Java Concepts
Java String concepts
Immutable classes in Java
Remove duplicates from the array
Telephonic phone technical interview questions
Telephonic phone technical interview questions - Part 2
Serialization & Deserialization
Jersey Package Dependencies
Observable and Observer Interface
Servlet Client Request
Spring dependencies for Maven
Java String Operations

Java Servlet Client Request

Client request from java servlet can contain a lot of data and most of the data can be retrieved using different methods. Here are those methods. Most methods are self explanatory so their explanation is not provided.


  1. getLocale: Returns the preferred locale that the client will accept the locale in.
  2. getAttribute(String name): Returns the value of the attribute.
  3. getInputStream(): Returns body of the request in binary data.
  4. getAuthType: Returns BASIC, SSL or NULL
  5. getCharacterEncoding: Returns encoding type like ASCII, 8-bit, UTF-8, UTF-16
  6. getContentType: Returns MIME type(Type of data like application/json/xml, etc). Specifying it will help the application to decode it.
  7. getContextPath: Returns URI's portion that returns context of the request.
  8. getHeader(String name): Returns values of the specified header.
  9. getMethod: Returns Get, post, put, delete
  10. getRequestURI()
  11. getRequestedSessionId()
  12. getServletPath()
  13. getParameterValues(String name)
  14. isSecure()
  15. getContentLength(): Returns the length of the request body or -1 if the length is not know.
  16. getIntHeader(String name): Returns value of the header as an int.
  17. getServerPort(): Returns the port number on which this request was received.
  18. getParameter(String name): Returns the parameter value or null if the param doesn't exist.
  19. getPathInfo(): Returns any extra path info associated with the URL.
  20. getProtocol(): Returns protocol like HTTP, HTTPS, etc
  21. getQueryString():
  22. getCookies(): Returns all the cookies from the client's request as an array.
  23. getAttributeNames(): Returns an enum of all the attributes from the request.
  24. getHeaderNames: Returns an enum of all the headers from the request.
  25. getParameterNames: Returns an enum of all the parameters from the request.
  26. getSession: Returns the current session or creates a new one.
  27. getSession(boolean create): Returns the current session if one exists and will create a new one only if(boolean = true).
  28. getRemoteAddr()
  29. getRemoteHost()
  30. getRemoteUser()


Example
This is how any method is needed to be applied to the request to retrieve a specific value.
request.getHeaderNames();

You might also like:
Java Concepts
Java String concepts
Immutable classes in Java
Remove duplicates from the array
Telephonic phone technical interview questions
Telephonic phone technical interview questions - Part 2
Serialization & Deserialization
Jersey Package Dependencies
Observable and Observer Interface
Servlet Filter
Spring dependencies for Maven
Java String Operations

Mercurial Commands CheatSheet

Mercurial Commands:
  1. Merging
    1. hg update default
    2. hg pull
    3. hg update
    4. hg merge branch_name
    5. hg commit 
    6. hg push
  2. Creating a new branch
    1. hg branch branch_name
    2. hg commit -m “Creating a new branch” 
    3. hg push - - new-branch
  3. Post a review on one of the published reviews
    1. hg postreview -i {repositoryId} -e {CodeReviewId}
  4. To rollback a merge:
    1. hg update -C . 
  5. Clone a repository:
    1. hg clone ssh://merc//home/hg/RepoName
  6. Undo a merge:
    1. hg update -C -r .

Jersey Package dependencies

Dependencies:
Package: Server side support for Grizzly Containers
<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-grizzly2-http</artifactId>
   <version>2.22.2</version>
</dependency>

Package: Server side support for JDK Containers
<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-jdk-http</artifactId>
   <version>2.22.2</version>
</dependency>


Package: Server side support for Simple Containers
<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-simple-http</artifactId>
   <version>2.22.2</version>
</dependency>

Package: Server side support for Jetty Containers
<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-jetty-http</artifactId>
   <version>2.22.2</version>
</dependency>
<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-jetty-servlet</artifactId>
   <version>2.22.2</version>
</dependency>

Package: Grizzly connector for Jersey Client
<dependency>
   <groupId>org.glassfish.jersey.connectors</groupId>
   <artifactId>jersey-grizzly-connector</artifactId>
   <version>2.22.2</version>
</dependency>
 

Package: Apache connector for Jersey Client
<dependency>
   <groupId>org.glassfish.jersey.connectors</groupId>
   <artifactId>jersey-apache-connector</artifactId>
   <version>2.22.2</version>
</dependency>

Package: Jetty connector for Jersey Client
<dependency>
   <groupId>org.glassfish.jersey.connectors</groupId>
   <artifactId>jersey-jetty-connector</artifactId>
   <version>2.22.2</version>
</dependency>


Package: Jersey
<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-servlet</artifactId>
   <version>2.22.2</version>
   <scope>provided</scope>
</dependency>
<!-- if you are using Jersey client specific features without the server side -->
<dependency>
   <groupId>org.glassfish.jersey.core</groupId>
   <artifactId>jersey-client</artifactId>
   <version>2.22.2</version>
   <scope>provided</scope>
</dependency>

Package: JAX-RS API
<dependency>
   <groupId>javax.ws.rs</groupId>
   <artifactId>javax.ws.rs-api</artifactId>
   <version>2.0.1</version>
   <scope>provided</scope>
</dependency>

Apache Commons dependency
<!-- http://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>


You might also like:
Java Concepts
Java String concepts
Immutable classes in Java
Remove duplicates from the array
Telephonic phone technical interview questions
Telephonic phone technical interview questions - Part 2
Serialization & Deserialization
Observable and Observer Interface
Servlet Filter
Servlet Client Request
Spring dependencies for Maven
Java String Operations

NoSQL

This one is reviewed but I need to delete its copy from hubpages or somewhere NoSQL Data models: key-value  Aggregate model.  key or i...