Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2688cb9c10
|
@ -123,6 +123,12 @@
|
|||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package org.baeldung.java.md5;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.Hashing;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class JavaMD5Test {
|
||||
|
||||
|
||||
String filename = "src/test/resources/test_md5.txt";
|
||||
String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
|
||||
|
||||
String hash = "35454B055CC325EA1AF2126E27707052";
|
||||
String password = "ILoveJava";
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void givenPassword_whenHashing_thenVerifying() throws NoSuchAlgorithmException {
|
||||
String hash = "35454B055CC325EA1AF2126E27707052";
|
||||
String password = "ILoveJava";
|
||||
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(password.getBytes());
|
||||
byte[] digest = md.digest();
|
||||
String myHash = DatatypeConverter.printHexBinary(digest).toUpperCase();
|
||||
|
||||
assertThat(myHash.equals(hash)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFile_generatingChecksum_thenVerifying() throws NoSuchAlgorithmException, IOException {
|
||||
String filename = "src/test/resources/test_md5.txt";
|
||||
String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
|
||||
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(Files.readAllBytes(Paths.get(filename)));
|
||||
byte[] digest = md.digest();
|
||||
String myChecksum = DatatypeConverter
|
||||
.printHexBinary(digest).toUpperCase();
|
||||
|
||||
assertThat(myChecksum.equals(checksum)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPassword_whenHashingUsingCommons_thenVerifying() {
|
||||
String hash = "35454B055CC325EA1AF2126E27707052";
|
||||
String password = "ILoveJava";
|
||||
|
||||
String md5Hex = DigestUtils
|
||||
.md5Hex(password).toUpperCase();
|
||||
|
||||
assertThat(md5Hex.equals(hash)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenFile_whenChecksumUsingGuava_thenVerifying() throws IOException {
|
||||
String filename = "src/test/resources/test_md5.txt";
|
||||
String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
|
||||
|
||||
HashCode hash = com.google.common.io.Files
|
||||
.hash(new File(filename), Hashing.md5());
|
||||
String myChecksum = hash.toString()
|
||||
.toUpperCase();
|
||||
|
||||
assertThat(myChecksum.equals(checksum)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
}
|
1
pom.xml
1
pom.xml
|
@ -96,6 +96,7 @@
|
|||
<module>spring-mvc-java</module>
|
||||
<module>spring-mvc-no-xml</module>
|
||||
<module>spring-mvc-xml</module>
|
||||
<module>spring-mvc-tiles</module>
|
||||
<module>spring-openid</module>
|
||||
<module>spring-protobuf</module>
|
||||
<module>spring-quartz</module>
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
<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</groupId>
|
||||
<artifactId>spring-mvc-tiles</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>spring-mvc-tiles</name>
|
||||
<description>Integrating Spring MVC with Apache Tiles</description>
|
||||
|
||||
<properties>
|
||||
<springframework.version>4.3.2.RELEASE</springframework.version>
|
||||
<apachetiles.version>3.0.5</apachetiles.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${springframework.version}</version>
|
||||
</dependency>
|
||||
<!-- Apache Tiles -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
<version>${apachetiles.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Servlet+JSP+JSTL -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</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>spring-mvc-tiles</warName>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<finalName>spring-mvc-tiles</finalName>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,47 @@
|
|||
package com.baeldung.tiles.springmvc;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
|
||||
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@ComponentScan(basePackages = "com.baeldung.tiles.springmvc")
|
||||
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
/**
|
||||
* Configure TilesConfigurer.
|
||||
*/
|
||||
@Bean
|
||||
public TilesConfigurer tilesConfigurer() {
|
||||
TilesConfigurer tilesConfigurer = new TilesConfigurer();
|
||||
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" });
|
||||
tilesConfigurer.setCheckRefresh(true);
|
||||
return tilesConfigurer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure ViewResolvers to deliver views.
|
||||
*/
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
TilesViewResolver viewResolver = new TilesViewResolver();
|
||||
registry.viewResolver(viewResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure ResourceHandlers to serve static resources
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.baeldung.tiles.springmvc;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class ApplicationController {
|
||||
|
||||
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
|
||||
public String homePage(ModelMap model) {
|
||||
return "home";
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/apachetiles" }, method = RequestMethod.GET)
|
||||
public String productsPage(ModelMap model) {
|
||||
return "apachetiles";
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/springmvc" }, method = RequestMethod.GET)
|
||||
public String contactUsPage(ModelMap model) {
|
||||
return "springmvc";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.tiles.springmvc;
|
||||
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return new Class[] { ApplicationConfiguration.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
|
||||
}
|
|
@ -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>Apache Tiles</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Tiles with Spring MVC Demo</h2>
|
||||
</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>Home</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Welcome to Apache Tiles integration with Spring MVC</h2>
|
||||
</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>Spring MVC</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Spring MVC configured to work with Apache Tiles</h2>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<%@ page isELIgnored="false"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title><tiles:getAsString name="title" /></title>
|
||||
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="flex-container">
|
||||
<tiles:insertAttribute name="header" />
|
||||
<tiles:insertAttribute name="menu" />
|
||||
<article class="article">
|
||||
<tiles:insertAttribute name="body" />
|
||||
</article>
|
||||
<tiles:insertAttribute name="footer" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
<footer>copyright © Baeldung</footer>
|
|
@ -0,0 +1,3 @@
|
|||
<header>
|
||||
<h1>Welcome to Spring MVC integration with Apache Tiles</h1>
|
||||
</header>
|
|
@ -0,0 +1,8 @@
|
|||
<nav class="nav">
|
||||
<a href="${pageContext.request.contextPath}/"></a>
|
||||
<ul id="menu">
|
||||
<li><a href="${pageContext.request.contextPath}/">Home</a></li>
|
||||
<li><a href="${pageContext.request.contextPath}/springmvc">SpringMVC</a></li>
|
||||
<li><a href="${pageContext.request.contextPath}/apachetiles">ApacheTiles</a></li>
|
||||
</ul>
|
||||
</nav>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
|
||||
|
||||
<tiles-definitions>
|
||||
|
||||
<!-- Template Definition -->
|
||||
<definition name="template-def"
|
||||
template="/WEB-INF/views/tiles/layouts/defaultLayout.jsp">
|
||||
<put-attribute name="title" value="" />
|
||||
<put-attribute name="header" value="/WEB-INF/views/tiles/templates/defaultHeader.jsp" />
|
||||
<put-attribute name="menu" value="/WEB-INF/views/tiles/templates/defaultMenu.jsp" />
|
||||
<put-attribute name="body" value="" />
|
||||
<put-attribute name="footer" value="/WEB-INF/views/tiles/templates/defaultFooter.jsp" />
|
||||
</definition>
|
||||
|
||||
<!-- Main Page -->
|
||||
<definition name="home" extends="template-def">
|
||||
<put-attribute name="title" value="Welcome" />
|
||||
<put-attribute name="body" value="/WEB-INF/views/pages/home.jsp" />
|
||||
</definition>
|
||||
|
||||
<!-- Apache Tiles Page -->
|
||||
<definition name="apachetiles" extends="template-def">
|
||||
<put-attribute name="title" value="ApacheTiles" />
|
||||
<put-attribute name="body" value="/WEB-INF/views/pages/apachetiles.jsp" />
|
||||
</definition>
|
||||
|
||||
<!-- Spring MVC Page -->
|
||||
<definition name="springmvc" extends="template-def">
|
||||
<put-attribute name="title" value="SpringMVC" />
|
||||
<put-attribute name="body" value="/WEB-INF/views/pages/springmvc.jsp" />
|
||||
</definition>
|
||||
|
||||
</tiles-definitions>
|
|
@ -0,0 +1,36 @@
|
|||
.flex-container {
|
||||
display: -webkit-flex;
|
||||
display: flex;
|
||||
-webkit-flex-flow: row wrap;
|
||||
flex-flow: row wrap;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.flex-container > * {
|
||||
padding: 15px;
|
||||
-webkit-flex: 1 100%;
|
||||
flex: 1 100%;
|
||||
}
|
||||
|
||||
.article {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
header {background: black;color:white;}
|
||||
footer {background: #aaa;color:white;}
|
||||
.nav {background:#eee;}
|
||||
|
||||
.nav ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.nav ul a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media all and (min-width: 768px) {
|
||||
.nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;}
|
||||
.article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;}
|
||||
footer {-webkit-order:3;order:3;}
|
||||
}
|
Loading…
Reference in New Issue