org.apache.poi
diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java
index 0d38208bab..1fdf07a05f 100644
--- a/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java
+++ b/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java
@@ -1,6 +1,8 @@
package com.baeldung.pdf;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
@@ -10,14 +12,21 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.fit.pdfdom.PDFDomTree;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.pdf.PdfWriter;
+import com.itextpdf.tool.xml.XMLWorkerHelper;
+
public class PDF2HTMLExample {
- private static final String FILENAME = "src/main/resources/pdf.pdf";
+ private static final String PDF = "src/main/resources/pdf.pdf";
+ private static final String HTML = "src/main/resources/html.html";
public static void main(String[] args) {
try {
- generateHTMLFromPDF(FILENAME);
- } catch (IOException | ParserConfigurationException e) {
+ generateHTMLFromPDF(PDF);
+ generatePDFFromHTML(HTML);
+ } catch (IOException | ParserConfigurationException | DocumentException e) {
e.printStackTrace();
}
}
@@ -32,4 +41,12 @@ public class PDF2HTMLExample {
pdf.close();
}
}
+
+ private static void generatePDFFromHTML(String filename) throws ParserConfigurationException, IOException, DocumentException {
+ Document document = new Document();
+ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("src/output/html.pdf"));
+ document.open();
+ XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(filename));
+ document.close();
+ }
}
diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java
index 00778d16c1..69f5d9731f 100644
--- a/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java
+++ b/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java
@@ -1,24 +1,36 @@
package com.baeldung.pdf;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.tools.imageio.ImageIOUtil;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
+import com.itextpdf.text.BadElementException;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.Image;
+import com.itextpdf.text.pdf.PdfWriter;
public class PDF2ImageExample {
- private static final String FILENAME = "src/main/resources/pdf.pdf";
-
+ private static final String PDF = "src/main/resources/pdf.pdf";
+ private static final String JPG = "http://cdn2.baeldung.netdna-cdn.com/wp-content/uploads/2016/05/baeldung-rest-widget-main-1.2.0";
+ private static final String GIF = "https://media.giphy.com/media/l3V0x6kdXUW9M4ONq/giphy";
+
public static void main(String[] args) {
try {
- generateImageFromPDF(FILENAME, "png");
- generateImageFromPDF(FILENAME, "jpeg");
- generateImageFromPDF(FILENAME, "gif");
- } catch (IOException e) {
+ generateImageFromPDF(PDF, "png");
+ generateImageFromPDF(PDF, "jpeg");
+ generateImageFromPDF(PDF, "gif");
+ generatePDFFromImage(JPG, "jpg");
+ generatePDFFromImage(GIF, "gif");
+ } catch (IOException | DocumentException e) {
e.printStackTrace();
}
}
@@ -32,4 +44,19 @@ public class PDF2ImageExample {
}
document.close();
}
+
+ private static void generatePDFFromImage(String filename, String extension)
+ throws IOException, BadElementException, DocumentException {
+ Document document = new Document();
+ String input = filename + "." + extension;
+ String output = "src/output/" + extension + ".pdf";
+ FileOutputStream fos = new FileOutputStream(output);
+ PdfWriter writer = PdfWriter.getInstance(document, fos);
+ writer.open();
+ document.open();
+ document.add(Image.getInstance((new URL(input))));
+ document.close();
+ writer.close();
+ }
+
}
diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java
index c5880a4e91..7965152234 100644
--- a/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java
+++ b/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java
@@ -1,6 +1,9 @@
package com.baeldung.pdf;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
@@ -10,14 +13,24 @@ import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.Element;
+import com.itextpdf.text.Font;
+import com.itextpdf.text.PageSize;
+import com.itextpdf.text.Paragraph;
+import com.itextpdf.text.pdf.PdfWriter;
+
public class PDF2TextExample {
- private static final String FILENAME = "src/main/resources/pdf.pdf";
+ private static final String PDF = "src/main/resources/pdf.pdf";
+ private static final String TXT = "src/main/resources/txt.txt";
public static void main(String[] args) {
try {
- generateTxtFromPDF(FILENAME);
- } catch (IOException e) {
+ generateTxtFromPDF(PDF);
+ generatePDFFromTxt(TXT);
+ } catch (IOException | DocumentException e) {
e.printStackTrace();
}
}
@@ -45,4 +58,27 @@ public class PDF2TextExample {
pw.close();
}
+ private static void generatePDFFromTxt(String filename) throws IOException, DocumentException {
+ Document pdfDoc = new Document(PageSize.A4);
+ PdfWriter.getInstance(pdfDoc, new FileOutputStream("src/output/txt.pdf"))
+ .setPdfVersion(PdfWriter.PDF_VERSION_1_7);
+ pdfDoc.open();
+
+ Font myfont = new Font();
+ myfont.setStyle(Font.NORMAL);
+ myfont.setSize(11);
+ pdfDoc.add(new Paragraph("\n"));
+
+ BufferedReader br = new BufferedReader(new FileReader(filename));
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ Paragraph para = new Paragraph(strLine + "\n", myfont);
+ para.setAlignment(Element.ALIGN_JUSTIFIED);
+ pdfDoc.add(para);
+ }
+
+ pdfDoc.close();
+ br.close();
+ }
+
}
diff --git a/pdf/src/main/resources/html.html b/pdf/src/main/resources/html.html
new file mode 100644
index 0000000000..d3072c056c
--- /dev/null
+++ b/pdf/src/main/resources/html.html
@@ -0,0 +1,53 @@
+
+
+
+
+A very simple webpage
+
+
+
+A very simple webpage. This is an "h1" level header.
+
+This is a level h2 header.
+
+This is a level h6 header. Pretty small!
+
+This is a standard paragraph.
+
+Now I've aligned it in the center of the screen.
+
+Now aligned to the right
+
+Bold text
+
+Strongly emphasized text Can you tell the difference vs. bold?
+
+Italics
+
+Emphasized text Just like Italics!
+
+How about a nice ordered list!
+
+ - This little piggy went to market
+ - This little piggy went to SB228 class
+ - This little piggy went to an expensive restaurant in Downtown Palo Alto
+ - This little piggy ate too much at Indian Buffet.
+ - This little piggy got lost
+
+
+Unordered list
+
+ - First element
+ - Second element
+ - Third element
+
+
+
+And finally, how about some
Links?
+
+Remember, you can view the HTMl code from this or any other page by using the "View Page Source" command of your browser.
+
+
+
+
+
diff --git a/pdf/src/main/resources/txt.txt b/pdf/src/main/resources/txt.txt
new file mode 100644
index 0000000000..de0c36ae75
--- /dev/null
+++ b/pdf/src/main/resources/txt.txt
@@ -0,0 +1,3 @@
+Test
+Text
+ Test TEST
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9dfb0fdaaf..b8d0303160 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,11 +52,11 @@
jee7
jjwt
jpa-storedprocedure
- jsf
+ jsf
json-path
json
junit5
-
+
log4j
log-mdc
lombok
@@ -72,19 +72,19 @@
querydsl
- redis
+ redis
rest-assured
rest-testing
resteasy
selenium-junit-testng
- spring-akka
+ spring-akka
spring-all
spring-apache-camel
spring-autowire
spring-batch
spring-boot
- spring-cloud-data-flow
+ spring-cloud-data-flow
spring-cloud
spring-core
spring-cucumber
@@ -132,7 +132,7 @@
spring-security-rest-custom
spring-security-rest-digest-auth
spring-security-rest-full
- spring-security-rest
+ spring-security-rest
spring-security-x509
spring-session
spring-spel
diff --git a/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java b/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java
index dd309cec79..b97f66e9dd 100644
--- a/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java
+++ b/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java
@@ -1,14 +1,13 @@
package main.java.com.baeldung.selenium;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.concurrent.TimeUnit;
-
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
public class SeleniumExample {
private WebDriver webDriver;
@@ -38,12 +37,12 @@ public class SeleniumExample {
private void closeOverlay() {
List webElementList = webDriver.findElements(By.tagName("a"));
- try {
- if (webElementList != null && !webElementList.isEmpty()) {
- webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click();
- }
- } catch (NoSuchElementException exception) {
- exception.printStackTrace();
+ if (webElementList != null) {
+ webElementList.stream()
+ .filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
+ .filter(WebElement::isDisplayed)
+ .findAny()
+ .ifPresent(WebElement::click);
}
}
diff --git a/spring-apache-camel/pom.xml b/spring-apache-camel/pom.xml
index fbea9b779d..6cd4f136e0 100644
--- a/spring-apache-camel/pom.xml
+++ b/spring-apache-camel/pom.xml
@@ -11,25 +11,26 @@
2.16.1
4.2.4.RELEASE
+ 2.19.1
1.7
- 4.1
+ 4.12
-
+
junit
junit
${junit.version}
test
-
+
org.apache.camel
camel-core
${env.camel.version}
-
+
org.apache.camel
camel-spring
@@ -49,7 +50,7 @@
-
+
@@ -62,6 +63,22 @@
${java.version}
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+
+
diff --git a/spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorIntegrationTest.java b/spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorIntegrationTest.java
new file mode 100644
index 0000000000..e73ad1e4a4
--- /dev/null
+++ b/spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorIntegrationTest.java
@@ -0,0 +1,68 @@
+package org.apache.camel.file.processor;
+
+import java.io.File;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import com.baeldung.camel.file.FileProcessor;
+
+
+public class FileProcessorIntegrationTest {
+
+ private static final long DURATION_MILIS = 10000;
+ private static final String SOURCE_FOLDER = "src/test/source-folder";
+ private static final String DESTINATION_FOLDER = "src/test/destination-folder";
+
+ @Before
+ public void setUp() throws Exception {
+ File sourceFolder = new File(SOURCE_FOLDER);
+ File destinationFolder = new File(DESTINATION_FOLDER);
+
+ cleanFolder(sourceFolder);
+ cleanFolder(destinationFolder);
+
+ sourceFolder.mkdirs();
+ File file1 = new File(SOURCE_FOLDER + "/File1.txt");
+ File file2 = new File(SOURCE_FOLDER + "/File2.txt");
+ file1.createNewFile();
+ file2.createNewFile();
+ }
+
+ private void cleanFolder(File folder) {
+ File[] files = folder.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isFile()) {
+ file.delete();
+ }
+ }
+ }
+ }
+
+ @Test
+ public void moveFolderContentJavaDSLTest() throws Exception {
+ final CamelContext camelContext = new DefaultCamelContext();
+ camelContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file://" + SOURCE_FOLDER + "?delete=true").process(new FileProcessor()).to("file://" + DESTINATION_FOLDER);
+ }
+ });
+ camelContext.start();
+ Thread.sleep(DURATION_MILIS);
+ camelContext.stop();
+ }
+
+ @Test
+ public void moveFolderContentSpringDSLTest() throws InterruptedException {
+ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml");
+ Thread.sleep(DURATION_MILIS);
+ applicationContext.close();
+
+ }
+}
\ No newline at end of file
diff --git a/spring-apache-camel/src/test/java/org/apache/camel/main/AppTest.java b/spring-apache-camel/src/test/java/org/apache/camel/main/AppIntegrationTest.java
similarity index 95%
rename from spring-apache-camel/src/test/java/org/apache/camel/main/AppTest.java
rename to spring-apache-camel/src/test/java/org/apache/camel/main/AppIntegrationTest.java
index 87b20369f3..fc7fa9653b 100644
--- a/spring-apache-camel/src/test/java/org/apache/camel/main/AppTest.java
+++ b/spring-apache-camel/src/test/java/org/apache/camel/main/AppIntegrationTest.java
@@ -15,7 +15,7 @@ import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Paths;
-public class AppTest extends TestCase {
+public class AppIntegrationTest extends TestCase {
private static final String FILE_NAME = "file.txt";
private static final String SAMPLE_INPUT_DIR = "src/test/data/sampleInputFile/";
diff --git a/spring-cloud/spring-cloud-bootstrap/config/src/main/java/com/baeldung/spring/cloud/bootstrap/config/ConfigApplication.java b/spring-cloud/spring-cloud-bootstrap/config/src/main/java/com/baeldung/spring/cloud/bootstrap/config/ConfigApplication.java
index 847c86f881..c51819dfe5 100644
--- a/spring-cloud/spring-cloud-bootstrap/config/src/main/java/com/baeldung/spring/cloud/bootstrap/config/ConfigApplication.java
+++ b/spring-cloud/spring-cloud-bootstrap/config/src/main/java/com/baeldung/spring/cloud/bootstrap/config/ConfigApplication.java
@@ -9,7 +9,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@EnableConfigServer
@EnableEurekaClient
public class ConfigApplication {
- public static void main(String[] args) {
- SpringApplication.run(ConfigApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(ConfigApplication.class, args);
+ }
}
diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/DiscoveryApplication.java b/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/DiscoveryApplication.java
index 32bcdc90b6..4ac445b083 100644
--- a/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/DiscoveryApplication.java
+++ b/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/DiscoveryApplication.java
@@ -7,7 +7,7 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApplication {
- public static void main(String[] args) {
- SpringApplication.run(DiscoveryApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(DiscoveryApplication.class, args);
+ }
}
diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java
index a3d2df5357..b5ae1e4e7b 100644
--- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java
+++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java
@@ -18,23 +18,23 @@ import java.util.List;
@EnableZuulProxy
@EnableEurekaClient
public class GatewayApplication {
- public static void main(String[] args) {
- SpringApplication.run(GatewayApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(GatewayApplication.class, args);
+ }
- @Autowired(required = false)
- private List configurations = new ArrayList<>();
+ @Autowired(required = false)
+ private List configurations = new ArrayList<>();
- @Bean
- @LoadBalanced RestTemplate restTemplate(){
- return new RestTemplate();
- }
+ @Bean
+ @LoadBalanced
+ RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
-
- @Bean
- public SpringClientFactory springClientFactory() {
- SpringClientFactory factory = new SpringClientFactory();
- factory.setConfigurations(this.configurations);
- return factory;
- }
+ @Bean
+ public SpringClientFactory springClientFactory() {
+ SpringClientFactory factory = new SpringClientFactory();
+ factory.setConfigurations(this.configurations);
+ return factory;
+ }
}
diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/filter/SessionSavingZuulPreFilter.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/filter/SessionSavingZuulPreFilter.java
index 9a2b5bab74..1c90ba2e12 100644
--- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/filter/SessionSavingZuulPreFilter.java
+++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/filter/SessionSavingZuulPreFilter.java
@@ -14,34 +14,34 @@ import javax.servlet.http.HttpSession;
@Component
public class SessionSavingZuulPreFilter extends ZuulFilter {
- private Logger log = LoggerFactory.getLogger(this.getClass());
+ private Logger log = LoggerFactory.getLogger(this.getClass());
- @Autowired
- private SessionRepository repository;
+ @Autowired
+ private SessionRepository repository;
- @Override public boolean shouldFilter() {
- return true;
- }
+ @Override
+ public boolean shouldFilter() {
+ return true;
+ }
- @Override
- public Object run() {
- RequestContext context = RequestContext.getCurrentContext();
+ @Override
+ public Object run() {
+ RequestContext context = RequestContext.getCurrentContext();
+ HttpSession httpSession = context.getRequest().getSession();
+ Session session = repository.getSession(httpSession.getId());
- HttpSession httpSession = context.getRequest().getSession();
- Session session = repository.getSession(httpSession.getId());
+ context.addZuulRequestHeader("Cookie", "SESSION=" + httpSession.getId());
+ log.info("ZuulPreFilter session proxy: {}", session.getId());
+ return null;
+ }
- context.addZuulRequestHeader("Cookie", "SESSION=" + httpSession.getId());
+ @Override
+ public String filterType() {
+ return "pre";
+ }
- log.info("ZuulPreFilter session proxy: {}", session.getId());
-
- return null;
- }
-
- @Override public String filterType() {
- return "pre";
- }
-
- @Override public int filterOrder() {
- return 0;
- }
+ @Override
+ public int filterOrder() {
+ return 0;
+ }
}
diff --git a/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/ResourceApplication.java b/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/ResourceApplication.java
index e12d43f46b..accef18a14 100644
--- a/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/ResourceApplication.java
+++ b/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/ResourceApplication.java
@@ -11,31 +11,31 @@ import org.springframework.web.bind.annotation.RestController;
@EnableEurekaClient
@RestController
public class ResourceApplication {
- public static void main(String[] args) {
- SpringApplication.run(ResourceApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(ResourceApplication.class, args);
+ }
- @Value("${resource.returnString}")
- private String returnString;
+ @Value("${resource.returnString}")
+ private String returnString;
- @Value("${resource.user.returnString}")
- private String userReturnString;
+ @Value("${resource.user.returnString}")
+ private String userReturnString;
- @Value("${resource.admin.returnString}")
- private String adminReturnString;
+ @Value("${resource.admin.returnString}")
+ private String adminReturnString;
- @RequestMapping("/hello/cloud")
- public String getString() {
- return returnString;
- }
+ @RequestMapping("/hello/cloud")
+ public String getString() {
+ return returnString;
+ }
- @RequestMapping("/hello/user")
- public String getUserString() {
- return userReturnString;
- }
+ @RequestMapping("/hello/user")
+ public String getUserString() {
+ return userReturnString;
+ }
- @RequestMapping("/hello/admin")
- public String getAdminString() {
- return adminReturnString;
- }
+ @RequestMapping("/hello/admin")
+ public String getAdminString() {
+ return adminReturnString;
+ }
}
diff --git a/spring-core/.gitignore b/spring-core/.gitignore
index 6531dfc93f..08259abdaf 100644
--- a/spring-core/.gitignore
+++ b/spring-core/.gitignore
@@ -5,8 +5,8 @@ RemoteSystemsTempFiles/
bin/
.metadata/
docs/*.autosave
-docs/*.autosave
.recommenders/
build/
.gradle/
.DS_Store
+.idea/
\ No newline at end of file
diff --git a/spring-core/pom.xml b/spring-core/pom.xml
index 9b94ba7b35..84a492bbe4 100644
--- a/spring-core/pom.xml
+++ b/spring-core/pom.xml
@@ -4,22 +4,13 @@
4.0.0
com.baeldung
- dependency-injection
+ spring-core
0.0.1-SNAPSHOT
war
- dependency-injection
- Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely
- Resource, Inject, and Autowired
-
+ spring-core
-
- junit
- junit
- 4.11
- test
-
org.mockito
mockito-all
@@ -50,6 +41,12 @@
javax.inject
1
+
+ junit
+ junit
+ 4.12
+ test
+
diff --git a/spring-core/src/main/java/com/baeldung/beanfactory/Employee.java b/spring-core/src/main/java/com/baeldung/beanfactory/Employee.java
new file mode 100644
index 0000000000..bd7c7a5dc7
--- /dev/null
+++ b/spring-core/src/main/java/com/baeldung/beanfactory/Employee.java
@@ -0,0 +1,28 @@
+package com.baeldung.beanfactory;
+
+public class Employee {
+
+ private String name;
+ private int age;
+
+ public Employee(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+}
diff --git a/spring-core/src/test/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResourceTest.java b/spring-core/src/test/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResourceTest.java
new file mode 100644
index 0000000000..80123a1bee
--- /dev/null
+++ b/spring-core/src/test/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResourceTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.beanfactory;
+
+import org.junit.Test;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class BeanFactoryWithClassPathResourceTest {
+
+ @Test
+ public void createBeanFactoryAndCheckEmployeeBean() {
+ Resource res = new ClassPathResource("beanfactory-example.xml");
+ BeanFactory factory = new XmlBeanFactory(res);
+ Employee emp = (Employee) factory.getBean("employee");
+
+ assertTrue(factory.isSingleton("employee"));
+ assertTrue(factory.getBean("employee") instanceof Employee);
+ assertTrue(factory.isTypeMatch("employee", Employee.class));
+ assertTrue(factory.getAliases("employee").length > 0);
+ }
+}
diff --git a/spring-core/src/test/resources/beanfactory-example.xml b/spring-core/src/test/resources/beanfactory-example.xml
new file mode 100644
index 0000000000..7b3d4f29ed
--- /dev/null
+++ b/spring-core/src/test/resources/beanfactory-example.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml
index bd48a53d06..ec6eb7bf46 100644
--- a/spring-data-solr/pom.xml
+++ b/spring-data-solr/pom.xml
@@ -1,21 +1,21 @@
-
+
4.0.0
com.baeldung
spring-data-solr
0.0.1-SNAPSHOT
jar
spring-data-solr
-
-
+
+
UTF-8
4.2.5.RELEASE
2.19.1
2.0.4.RELEASE
-
+
org.springframework
@@ -50,20 +50,58 @@
test
-
+
+
+ maven-compiler-plugin
+
org.apache.maven.plugins
maven-surefire-plugin
${maven-surefire-plugin.version}
-
- **/*IntegrationTest.java
-
+
+ **/*IntegrationTest.java
+ **/*LiveTest.java
+
-
-
+
+
+
+ integration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*LiveTest.java
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+ json
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java
index 7cd0890718..5286f53309 100644
--- a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java
+++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java
@@ -6,50 +6,28 @@ import org.springframework.data.solr.core.mapping.SolrDocument;
@SolrDocument(solrCoreName = "product")
public class Product {
-
+
@Id
@Indexed(name = "id", type = "string")
private String id;
-
+
@Indexed(name = "name", type = "string")
private String name;
-
- @Indexed(name = "category", type = "string")
- private String category;
-
- @Indexed(name = "description", type = "string")
- private String description;
-
+
public String getId() {
return id;
}
-
+
public void setId(String id) {
this.id = id;
}
-
+
public String getName() {
return name;
}
-
+
public void setName(String name) {
this.name = name;
}
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
+
}
diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java
index 01ec1fb909..5649cd7888 100644
--- a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java
+++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java
@@ -13,7 +13,7 @@ public interface ProductRepository extends SolrCrudRepository {
public List findByName(String name);
- @Query("name:*?0* OR category:*?0* OR description:*?0*")
+ @Query("id:*?0* OR name:*?0*")
public Page findByCustomQuery(String searchTerm, Pageable pageable);
@Query(name = "Product.findByNamedQuery")
diff --git a/spring-data-solr/src/main/resources/solr-named-queries.properties b/spring-data-solr/src/main/resources/solr-named-queries.properties
index cec59cbebd..c00b5bace9 100644
--- a/spring-data-solr/src/main/resources/solr-named-queries.properties
+++ b/spring-data-solr/src/main/resources/solr-named-queries.properties
@@ -1 +1 @@
-Product.findByNamedQuery=name:*?0* OR category:*?0* OR description:*?0*
\ No newline at end of file
+Product.findByNamedQuery=id:*?0* OR name:*?0*
\ No newline at end of file
diff --git a/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java b/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java
index 74d94ef91c..a3765a74ec 100644
--- a/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java
+++ b/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java
@@ -21,124 +21,105 @@ import com.baeldung.spring.data.solr.repository.ProductRepository;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SolrConfig.class)
public class ProductRepositoryIntegrationTest {
-
+
@Autowired
private ProductRepository productRepository;
-
+
@Before
public void clearSolrData() {
productRepository.deleteAll();
}
-
+
@Test
public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
final Product product = new Product();
product.setId("P000089998");
product.setName("Desk");
- product.setCategory("Furniture");
- product.setDescription("New Desk");
productRepository.save(product);
final Product retrievedProduct = productRepository.findOne(product.getId());
assertEquals(product.getId(), retrievedProduct.getId());
}
-
+
@Test
public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception {
final Product product = new Product();
product.setId("P0001");
product.setName("T-Shirt");
- product.setCategory("Kitchen");
- product.setDescription("New T-Shirt");
+
productRepository.save(product);
-
- product.setCategory("Clothes");
+
+ product.setName("Shirt");
productRepository.save(product);
-
+
final Product retrievedProduct = productRepository.findOne(product.getId());
- assertEquals(product.getCategory(), retrievedProduct.getCategory());
+ assertEquals(product.getName(), retrievedProduct.getName());
}
-
+
@Test
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
final Product product = new Product();
product.setId("P0001");
product.setName("Desk");
- product.setCategory("Furniture");
- product.setDescription("New Desk");
productRepository.save(product);
-
+
productRepository.delete(product);
-
+
Product retrievedProduct = productRepository.findOne(product.getId());
assertNull(retrievedProduct);
-
+
}
-
+
@Test
public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
Product phone = new Product();
phone.setId("P0001");
phone.setName("Phone");
- phone.setCategory("Electronics");
- phone.setDescription("New Phone");
productRepository.save(phone);
-
+
List retrievedProducts = productRepository.findByName("Phone");
assertEquals(phone.getId(), retrievedProducts.get(0).getId());
}
-
+
@Test
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
final Product phone = new Product();
phone.setId("P0001");
phone.setName("Smart Phone");
- phone.setCategory("Electronics");
- phone.setDescription("New Item");
productRepository.save(phone);
-
+
final Product phoneCover = new Product();
phoneCover.setId("P0002");
- phoneCover.setName("Cover");
- phoneCover.setCategory("Phone");
- phoneCover.setDescription("New Product");
+ phoneCover.setName("Phone Cover");
productRepository.save(phoneCover);
-
+
final Product wirelessCharger = new Product();
wirelessCharger.setId("P0003");
- wirelessCharger.setName("Charging Cable");
- wirelessCharger.setCategory("Cable");
- wirelessCharger.setDescription("Wireless Charger for Phone");
+ wirelessCharger.setName("Phone Charging Cable");
productRepository.save(wirelessCharger);
-
+
Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
assertEquals(3, result.getNumberOfElements());
}
-
+
@Test
public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
final Product phone = new Product();
phone.setId("P0001");
phone.setName("Smart Phone");
- phone.setCategory("Electronics");
- phone.setDescription("New Item");
productRepository.save(phone);
-
+
final Product phoneCover = new Product();
phoneCover.setId("P0002");
- phoneCover.setName("Cover");
- phoneCover.setCategory("Phone");
- phoneCover.setDescription("New Product");
+ phoneCover.setName("Phone Cover");
productRepository.save(phoneCover);
-
+
final Product wirelessCharger = new Product();
wirelessCharger.setId("P0003");
- wirelessCharger.setName("Charging Cable");
- wirelessCharger.setCategory("Cable");
- wirelessCharger.setDescription("Wireless Charger for Phone");
+ wirelessCharger.setName("Phone Charging Cable");
productRepository.save(wirelessCharger);
-
+
Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));
assertEquals(3, result.getNumberOfElements());
}
-
+
}
diff --git a/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java b/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java
index e7cf43e902..aec2ae8858 100644
--- a/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java
+++ b/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java
@@ -26,7 +26,7 @@ public class FileCopyConfig {
public final String INPUT_DIR = "source";
public final String OUTPUT_DIR = "target";
- public final String FILE_PATTERN = ".jpg";
+ public final String FILE_PATTERN = "*.jpg";
@Bean
public MessageChannel fileChannel() {
@@ -47,11 +47,12 @@ public class FileCopyConfig {
public MessageHandler fileWritingMessageHandler() {
FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(OUTPUT_DIR));
handler.setFileExistsMode(FileExistsMode.REPLACE);
+ handler.setExpectReply(false);
return handler;
}
public static void main(final String... args) {
- final AbstractApplicationContext context = new AnnotationConfigApplicationContext(FileCopyConfig.class.getCanonicalName());
+ final AbstractApplicationContext context = new AnnotationConfigApplicationContext(FileCopyConfig.class);
context.registerShutdownHook();
final Scanner scanner = new Scanner(System.in);
System.out.print("Please enter a string and press : ");
diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/MailController.java b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/MailController.java
index 768a0f8e7b..ff828ca9ec 100644
--- a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/MailController.java
+++ b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/MailController.java
@@ -20,12 +20,10 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-/**
- * Created by Olga on 7/20/2016.
- */
@Controller
@RequestMapping("/mail")
public class MailController {
+
@Autowired
public EmailServiceImpl emailService;
@@ -33,7 +31,6 @@ public class MailController {
private String attachmentPath;
@Autowired
- @Qualifier("templateSimpleMessage")
public SimpleMailMessage template;
private static final Map> labels;
diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml
index 011de70ad2..8e2db044a6 100644
--- a/spring-mvc-java/pom.xml
+++ b/spring-mvc-java/pom.xml
@@ -248,8 +248,8 @@
- 4.2.5.RELEASE
- 4.0.4.RELEASE
+ 4.3.4.RELEASE
+ 4.2.0.RELEASE
2.1.4.RELEASE
2.7.8
diff --git a/spring-mvc-xml/pom.xml b/spring-mvc-xml/pom.xml
index 849699cfae..ca51a56633 100644
--- a/spring-mvc-xml/pom.xml
+++ b/spring-mvc-xml/pom.xml
@@ -112,6 +112,11 @@
commons-io
2.2
+