group and cleanup (#3027)

* move security content from spring-security-rest-full

* swagger update

* move query language to new module

* rename spring-security-rest-full to spring-rest-full

* group persistence modules

* group testing modules

* try fix conflict

* cleanup

* group and cleanup
This commit is contained in:
Doha2012
2017-11-13 17:45:26 +02:00
committed by Grzegorz Piwowarek
parent 2a85b9c96e
commit 2e5531edd0
198 changed files with 20 additions and 15 deletions
@@ -0,0 +1,76 @@
About the application
---------------------
This application demonstrates the usage of JavaEE Web Annotations.
Contents of the application
---------------------------
1. AccountServlet.java - Demonstrates the @WebServlet and @ServletSecurity annotation.
NOTES: @WebServlet annotation designates the AccountServlet class as a Servlet component.
The usage of its parameters 'urlPatterns' & 'initParams' can be observed.
An initialization parameter 'type' is being set to denote the type of the bank account.
@ServletSecurity annotation imposes security constraints on the AccountServlet based on
the tomcat-users.xml.
 
This code assumes that your tomcat-users.xml looks as follows:
<role rolename="Admin"/>
<role rolename="Member"/>
<role rolename="Guest"/>
<user username="Annie" password="admin" roles="Admin, Member, Guest" />
<user username="Diane" password="coder" roles="Member, Guest" />
<user username="Ted" password="newbie" roles="Guest" />
 
N.B : To see @ServletSecurity annotation in action, please uncomment the annotation code
for @ServletSecurity.
2. BankAppServletContextListener.java - Demonstrates the @WebListener annotation for denoting a class as a ServletContextListener.
NOTES: Sets a Servlet context attribute ATTR_DEFAULT_LANGUAGE to 'english' on web application start up,
which can then be used throughout the application.
3. LogInFilter.java - Demonstrates the @WebFilter annotation.
NOTES: @WebFilter annotation designates the LogInFilter class as a Filter component.
It filters all requests to the bank account servlet and redirects them to
the login page.
N.B : To see @WebFilter annotation in action, please uncomment the annotation code for @WebFilter.
4. UploadCustomerDocumentsServlet.java - Demonstrates the @MultipartConfig annotation.
NOTES: @MultipartConfig anotation designates the UploadCustomerDocumentsServlet Servlet component,
to handle multipart/form-data requests.
To see it in action, deploy the web application an access the url: http://<your host>:<your port>/JavaEEAnnotationsSample/upload.jsp
Once you upload a file from here, it will get uploaded to D:/custDocs (assuming such a folder exists).
5. index.jsp - This is the welcome page.
NOTES: You can enter a deposit amount here and click on the 'Deposit' button to see the AccountServlet in action.
6. login.jsp - All requests to the AccountServlet are redirected to this page, if the LogInFilter is imposed.
7. upload.jsp - Demonstrates the usage of handling multipart/form-data requests by the UploadCustomerDocumentsServlet.
Building and Running the application
------------------------------------
To build the application:
1. Open the project in eclipse
2. Right click on it in eclispe and choose Run As > Maven build
3. Give 'clean install' under Goals
4. This should build the WAR file of the application
To run the application:
1. Right click on the project
2. Run as > Run on Server
3. This will start you Tomcat server and deploy the application (Provided that you have configured Tomcat in your eclipse)
4. You should now be able to access the url : http://<your host>:<your port>/JavaEEAnnotationsSample
@@ -0,0 +1,57 @@
<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.baeldung.javaeeannotations</groupId>
<artifactId>JavaEEAnnotationsSample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>JavaEEAnnotationsSample</name>
<description>JavaEEAnnotationsSample</description>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>SpringFieldConstructorInjection</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>JavaEEAnnotationsSample</finalName>
</build>
</project>
@@ -0,0 +1,50 @@
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(
name = "BankAccountServlet",
description = "Represents a Bank Account and it's transactions",
urlPatterns = {"/account", "/bankAccount" },
initParams = { @WebInitParam(name = "type", value = "savings") }
)
/*@ServletSecurity(
value = @HttpConstraint(rolesAllowed = {"Member"}),
httpMethodConstraints = {@HttpMethodConstraint(value = "POST", rolesAllowed = {"Admin"})}
)*/
public class AccountServlet extends javax.servlet.http.HttpServlet {
String accountType = null;
public void init(ServletConfig config) throws ServletException {
accountType = config.getInitParameter("type");
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter writer = response.getWriter();
writer.println("<html>Hello, I am an AccountServlet!</html>");
writer.flush();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
double accountBalance = 1000d;
String paramDepositAmt = request.getParameter("dep");
double depositAmt = Double.parseDouble(paramDepositAmt);
accountBalance = accountBalance + depositAmt;
PrintWriter writer = response.getWriter();
writer.println("<html> Balance of " + accountType + " account is: " + accountBalance + "</html>");
writer.flush();
}
}
@@ -0,0 +1,17 @@
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class BankAppServletContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
sce.getServletContext().setAttribute("ATTR_DEFAULT_LANGUAGE", "english");
}
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("CONTEXT DESTROYED");
}
}
@@ -0,0 +1,36 @@
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*@WebFilter(
urlPatterns = "/bankAccount/*",
filterName = "LogInFilter",
description = "Filter all account transaction URLs"
)*/
public class LogInFilter implements javax.servlet.Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect(req.getContextPath() + "/login.jsp");
chain.doFilter(request, response);
}
public void destroy() {
}
}
@@ -0,0 +1,34 @@
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
@WebServlet(urlPatterns = { "/uploadCustDocs" })
@MultipartConfig(
fileSizeThreshold = 1024 * 1024 * 20,
maxFileSize = 1024 * 1024 * 20,
maxRequestSize = 1024 * 1024 * 25,
location = "D:/custDocs"
)
public class UploadCustomerDocumentsServlet extends HttpServlet {
protected void doPost(
HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
for (Part part : request.getParts()) {
part.write("myFile");
}
PrintWriter writer = response.getWriter();
writer.println("<html>File uploaded successfully!</html>");
writer.flush();
}
}
@@ -0,0 +1,10 @@
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>default</realm-name>
</login-config>
</web-app>
@@ -0,0 +1,16 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Account</title>
</head>
<body>
<form action="bankAccount" method="post">
Amount: <input type="text" size="5" name="dep"/>
&nbsp;&nbsp;
<input type="submit" value="Deposit" />
</form>
</body>
</html>
@@ -0,0 +1,12 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
Login Here...
</body>
</html>
@@ -0,0 +1,16 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="uploadCustDocs" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>