Merge remote-tracking branch 'eugenp/master'
This commit is contained in:
commit
83d45139d9
25
apache-tika/pom.xml
Normal file
25
apache-tika/pom.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<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>apache-tika</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<tika.version>1.17</tika.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-parsers</artifactId>
|
||||
<version>${tika.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,67 @@
|
||||
package com.baeldung.tika;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.tika.Tika;
|
||||
import org.apache.tika.detect.DefaultDetector;
|
||||
import org.apache.tika.detect.Detector;
|
||||
import org.apache.tika.exception.TikaException;
|
||||
import org.apache.tika.metadata.Metadata;
|
||||
import org.apache.tika.mime.MediaType;
|
||||
import org.apache.tika.parser.AutoDetectParser;
|
||||
import org.apache.tika.parser.ParseContext;
|
||||
import org.apache.tika.parser.Parser;
|
||||
import org.apache.tika.sax.BodyContentHandler;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class TikaAnalysis {
|
||||
public static String detectDocTypeUsingDetector(InputStream stream) throws IOException {
|
||||
Detector detector = new DefaultDetector();
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
MediaType mediaType = detector.detect(stream, metadata);
|
||||
return mediaType.toString();
|
||||
}
|
||||
|
||||
public static String detectDocTypeUsingFacade(InputStream stream) throws IOException {
|
||||
Tika tika = new Tika();
|
||||
String mediaType = tika.detect(stream);
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
public static String extractContentUsingParser(InputStream stream) throws IOException, TikaException, SAXException {
|
||||
Parser parser = new AutoDetectParser();
|
||||
ContentHandler handler = new BodyContentHandler();
|
||||
Metadata metadata = new Metadata();
|
||||
ParseContext context = new ParseContext();
|
||||
|
||||
parser.parse(stream, handler, metadata, context);
|
||||
return handler.toString();
|
||||
}
|
||||
|
||||
public static String extractContentUsingFacade(InputStream stream) throws IOException, TikaException {
|
||||
Tika tika = new Tika();
|
||||
String content = tika.parseToString(stream);
|
||||
return content;
|
||||
}
|
||||
|
||||
public static Metadata extractMetadatatUsingParser(InputStream stream) throws IOException, SAXException, TikaException {
|
||||
Parser parser = new AutoDetectParser();
|
||||
ContentHandler handler = new BodyContentHandler();
|
||||
Metadata metadata = new Metadata();
|
||||
ParseContext context = new ParseContext();
|
||||
|
||||
parser.parse(stream, handler, metadata, context);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public static Metadata extractMetadatatUsingFacade(InputStream stream) throws IOException, TikaException {
|
||||
Tika tika = new Tika();
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
tika.parse(stream, metadata);
|
||||
return metadata;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.baeldung.tika;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.tika.exception.TikaException;
|
||||
import org.apache.tika.metadata.Metadata;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class TikaUnitTest {
|
||||
@Test
|
||||
public void whenUsingDetector_thenDocumentTypeIsReturned() throws IOException {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.txt");
|
||||
String mediaType = TikaAnalysis.detectDocTypeUsingDetector(stream);
|
||||
|
||||
assertEquals("application/pdf", mediaType);
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingFacade_thenDocumentTypeIsReturned() throws IOException {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.txt");
|
||||
String mediaType = TikaAnalysis.detectDocTypeUsingFacade(stream);
|
||||
|
||||
assertEquals("application/pdf", mediaType);
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingParser_thenContentIsReturned() throws IOException, TikaException, SAXException {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.docx");
|
||||
String content = TikaAnalysis.extractContentUsingParser(stream);
|
||||
|
||||
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
|
||||
assertThat(content, containsString("detects and extracts metadata and text"));
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingFacade_thenContentIsReturned() throws IOException, TikaException {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.docx");
|
||||
String content = TikaAnalysis.extractContentUsingFacade(stream);
|
||||
|
||||
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
|
||||
assertThat(content, containsString("detects and extracts metadata and text"));
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingParser_thenMetadataIsReturned() throws IOException, TikaException, SAXException {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.xlsx");
|
||||
Metadata metadata = TikaAnalysis.extractMetadatatUsingParser(stream);
|
||||
|
||||
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
|
||||
assertEquals("Microsoft Office User", metadata.get("Author"));
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingFacade_thenMetadataIsReturned() throws IOException, TikaException {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.xlsx");
|
||||
Metadata metadata = TikaAnalysis.extractMetadatatUsingFacade(stream);
|
||||
|
||||
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
|
||||
assertEquals("Microsoft Office User", metadata.get("Author"));
|
||||
|
||||
stream.close();
|
||||
}
|
||||
}
|
BIN
apache-tika/src/test/resources/tika.docx
Normal file
BIN
apache-tika/src/test/resources/tika.docx
Normal file
Binary file not shown.
BIN
apache-tika/src/test/resources/tika.txt
Normal file
BIN
apache-tika/src/test/resources/tika.txt
Normal file
Binary file not shown.
BIN
apache-tika/src/test/resources/tika.xlsx
Normal file
BIN
apache-tika/src/test/resources/tika.xlsx
Normal file
Binary file not shown.
@ -23,9 +23,15 @@ public class SuperHero extends Person {
|
||||
* @return the amount of health hero has after attack
|
||||
* @see <a href="http://www.link_to_jira/HERO-402">HERO-402</a>
|
||||
* @since 1.0
|
||||
* @deprecated As of version 1.1, use . . . instead
|
||||
* @version 1.2
|
||||
* @throws IllegalArgumentException if incomingDamage is negative
|
||||
*/
|
||||
public int successfullyAttacked(int incomingDamage, String damageType) {
|
||||
public int successfullyAttacked(int incomingDamage, String damageType) throws Exception {
|
||||
// do things
|
||||
if (incomingDamage < 0) {
|
||||
throw new IllegalArgumentException ("Cannot cause negative damage");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
4
pom.xml
4
pom.xml
@ -38,6 +38,7 @@
|
||||
<module>apache-cxf</module>
|
||||
<module>apache-fop</module>
|
||||
<module>apache-poi</module>
|
||||
<module>apache-tika</module>
|
||||
<module>apache-thrift</module>
|
||||
<module>apache-curator</module>
|
||||
<module>apache-zookeeper</module>
|
||||
@ -199,7 +200,8 @@
|
||||
<module>spring-ldap</module>
|
||||
<module>spring-mockito</module>
|
||||
<module>spring-mvc-email</module>
|
||||
<module>spring-mvc-forms</module>
|
||||
<module>spring-mvc-forms-jsp</module>
|
||||
<module>spring-mvc-forms-thymeleaf</module>
|
||||
<module>spring-mvc-java</module>
|
||||
<module>spring-mvc-tiles</module>
|
||||
<module>spring-mvc-velocity</module>
|
||||
|
@ -43,10 +43,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-hateoas</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectreactor</groupId>
|
||||
<artifactId>reactor-spring</artifactId>
|
||||
@ -56,6 +52,18 @@
|
||||
<groupId>javax.json.bind</groupId>
|
||||
<artifactId>javax.json.bind-api</artifactId>
|
||||
</dependency>
|
||||
<!-- Dependencies for Yasson -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.eclipse</groupId> -->
|
||||
<!-- <artifactId>yasson</artifactId> -->
|
||||
<!-- <version>1.0</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.glassfish</groupId> -->
|
||||
<!-- <artifactId>javax.json</artifactId> -->
|
||||
<!-- <version>1.1.2</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- Dependencies for Johnzon -->
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-json_1.1_spec</artifactId>
|
||||
@ -64,7 +72,6 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.johnzon</groupId>
|
||||
<artifactId>johnzon-jsonb</artifactId>
|
||||
<version>${johnzon.version}</version>
|
||||
</dependency>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
@ -205,8 +212,8 @@
|
||||
<java.version>1.8</java.version>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
|
||||
<spring.version>5.0.2.RELEASE</spring.version>
|
||||
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
|
||||
<johnzon.version>1.1.3</johnzon.version>
|
||||
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
|
||||
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version>
|
||||
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
|
||||
|
@ -6,9 +6,9 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<artifactId>spring-mvc-forms</artifactId>
|
||||
<artifactId>spring-mvc-forms-jsp</artifactId>
|
||||
|
||||
<name>spring-mvc-forms</name>
|
||||
<name>spring-mvc-forms-jsp</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
73
spring-mvc-forms-thymeleaf/pom.xml
Normal file
73
spring-mvc-forms-thymeleaf/pom.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?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.baeldung</groupId>
|
||||
<artifactId>spring-mvc-forms-thymeleaf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-mvc-forms-thymeleaf</name>
|
||||
<description>spring forms examples using thymeleaf</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.0.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- runtime and test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<parallel>methods</parallel>
|
||||
<useUnlimitedThreads>true</useUnlimitedThreads>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,3 @@
|
||||
server.port=8081
|
||||
|
||||
logging.level.root=INFO
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" lang="en">
|
||||
<head>
|
||||
<title>Session Scope in Spring MVC</title>
|
||||
<title>Session Attributes in Spring MVC</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" lang="en">
|
||||
<head>
|
||||
<title>Session Scope in Spring MVC</title>
|
||||
<title>Session Attributes in Spring MVC</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" lang="en">
|
||||
<head>
|
||||
<title>Session Scope in Spring MVC</title>
|
||||
<title>Session Attributes in Spring MVC</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" lang="en">
|
||||
<head>
|
||||
<title>Session Scope in Spring MVC</title>
|
||||
<title>Session Attributes in Spring MVC</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" lang="en">
|
||||
<head>
|
||||
<title>Session Scope in Spring MVC</title>
|
||||
<title>Session Attributes in Spring MVC</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SessionAttrsApplicationIntegrationTest {
|
||||
public class SessionAttrsApplicationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
@ -25,7 +25,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@Import(TestConfig.class)
|
||||
public class TodoControllerWithScopedProxyIntegrationTest {
|
||||
public class TodoControllerWithScopedProxyTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@ -40,7 +40,7 @@ public class TodoControllerWithScopedProxyIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFirstRequest_thenContainsAllCategoriesAndUnintializedTodo() throws Exception {
|
||||
public void whenFirstRequest_thenContainsUnintializedTodo() throws Exception {
|
||||
MvcResult result = mockMvc.perform(get("/scopedproxy/form"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("todo"))
|
@ -24,7 +24,7 @@ import org.springframework.web.servlet.FlashMap;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class TodoControllerWithSessionAttributesIntegrationTest {
|
||||
public class TodoControllerWithSessionAttributesTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
Loading…
x
Reference in New Issue
Block a user