From 24c25206a4d8b748e727f0cc9db5d64d456017e8 Mon Sep 17 00:00:00 2001 From: oreva Date: Thu, 28 Jul 2016 18:41:17 +0300 Subject: [PATCH 01/86] Spring MVC Email application added. --- spring-mvc-email/pom.xml | 142 ++++++++++++++++++ .../com/baeldung/spring/config/AppConfig.java | 100 ++++++++++++ .../spring/controllers/HomeController.java | 19 +++ .../spring/controllers/MailController.java | 44 ++++++ .../com/baeldung/spring/mail/Application.java | 20 +++ .../com/baeldung/spring/mail/MailService.java | 73 +++++++++ .../baeldung/spring/web/dto/MailObject.java | 50 ++++++ .../main/resources/META-INF/application.xml | 19 +++ .../src/main/webapp/WEB-INF/views/home.jsp | 25 +++ .../main/webapp/WEB-INF/views/mail/send.jsp | 60 ++++++++ .../src/main/webapp/WEB-INF/web.xml | 28 ++++ 11 files changed, 580 insertions(+) create mode 100644 spring-mvc-email/pom.xml create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/controllers/MailController.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java create mode 100644 spring-mvc-email/src/main/resources/META-INF/application.xml create mode 100644 spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp create mode 100644 spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp create mode 100644 spring-mvc-email/src/main/webapp/WEB-INF/web.xml diff --git a/spring-mvc-email/pom.xml b/spring-mvc-email/pom.xml new file mode 100644 index 0000000000..0ac84f5cc9 --- /dev/null +++ b/spring-mvc-email/pom.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + + org.baeldung.spring + SpringMVCEmail + war + 1.0 + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + javax.servlet + jstl + 1.2 + + + + + org.springframework + spring-context + 4.2.5.RELEASE + + + + org.springframework + spring-core + 4.2.5.RELEASE + + + + org.springframework + spring-web + 4.2.5.RELEASE + + + + org.springframework + spring-webmvc + 4.2.5.RELEASE + + + + + javax.validation + validation-api + 1.1.0.Final + + + + + org.hibernate + hibernate-validator + 5.0.1.Final + + + + + org.springframework.data + spring-data-jpa + 1.10.1.RELEASE + + + + + org.springframework.security + spring-security-web + 4.0.4.RELEASE + + + org.springframework.security + spring-security-config + 4.0.4.RELEASE + + + + + com.sun.mail + javax.mail + 1.5.5 + + + + + org.springframework.integration + spring-integration-mail + 4.3.0.RELEASE + + + + + SpringMVCEmail + + + + + org.apache.tomcat.maven + tomcat6-maven-plugin + 2.2 + + http://localhost:8080/manager/text + TomcatServer + /SpringMVCEmail + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + src/main/webapp/WEB-INF/web.xml + + + src/main/resources/META-INF + + + + + + + \ No newline at end of file diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java new file mode 100644 index 0000000000..2a7caadf23 --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java @@ -0,0 +1,100 @@ +package com.baeldung.spring.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSenderImpl; +import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; +import org.springframework.web.servlet.view.UrlBasedViewResolver; + +import java.util.Properties; + +/** + * Created with IntelliJ IDEA. + * User: Olga + */ +@Configuration +@ComponentScan("com.baeldung.spring") +@EnableWebMvc //tha same as +public class AppConfig extends WebMvcConfigurerAdapter { + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + + @Bean + public UrlBasedViewResolver urlBasedViewResolver() { + UrlBasedViewResolver resolver = new UrlBasedViewResolver(); + resolver.setOrder(0); + resolver.setPrefix("/WEB-INF/views/"); + resolver.setSuffix(".jsp"); + resolver.setCache(false); + resolver.setViewClass(JstlView.class); + return resolver; + } + + @Bean + public InternalResourceViewResolver internalResourceViewResolver() { + InternalResourceViewResolver resolver = new InternalResourceViewResolver(); + resolver.setOrder(1); + resolver.setPrefix("/WEB-INF/views/"); + resolver.setSuffix(".jsp"); + resolver.setViewClass(JstlView.class); + return resolver; + } + + /* Gmail */ + @Bean + public JavaMailSenderImpl mailSender() { + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); + mailSender.setHost("smtp.gmail.com"); + mailSender.setPort(587); + mailSender.setUsername("reva.olga"); + mailSender.setPassword("zakpnejnnoqkehgs"); + mailSender.setJavaMailProperties(javaMailProperties()); + return mailSender; + } + + private Properties javaMailProperties() { + Properties props = new Properties(); + props.setProperty("mail.smtp.auth", "true"); + props.setProperty("mail.smtp.starttls.enable", "true"); + return props; + } + + @Bean + public SimpleMailMessage templateMessage() { + SimpleMailMessage message = new SimpleMailMessage(); + message.setText("This is automatically generated email,\n" + + "Original mail text is included : %s\n" + + "\n" + + "Sincerely yours,\n" + + "Yourcompany."); + return message; + } + + /*Amazon SES + @Bean + public JavaMailSenderImpl mailSender() { + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); + mailSender.setHost("email-smtp.us-west-2.amazonaws.com"); + mailSender.setUsername("username"); + mailSender.setPassword("password"); + mailSender.setJavaMailProperties(javaMailProperties()); + return mailSender; + } + + private Properties javaMailProperties() { + Properties props = new Properties(); + props.setProperty("mail.transport.protocol", "smtps"); + props.setProperty("mail.smtp.port", "25"); + + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.starttls.enable", "true"); + props.put("mail.smtp.starttls.required", "true"); + return props; + }*/ +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java new file mode 100644 index 0000000000..656e237a9e --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java @@ -0,0 +1,19 @@ +package com.baeldung.spring.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * Created with IntelliJ IDEA. + * User: Olga + */ +@Controller +@RequestMapping({"/","/home"}) +public class HomeController { + + @RequestMapping(method = RequestMethod.GET) + public String showHomePage() { + return "home"; + } +} 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 new file mode 100644 index 0000000000..5de722f444 --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/MailController.java @@ -0,0 +1,44 @@ +package com.baeldung.spring.controllers; + +import com.baeldung.spring.mail.MailService; +import com.baeldung.spring.web.dto.MailObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.validation.Valid; + +/** + * Created by Olga on 7/20/2016. + */ +@Controller +@RequestMapping("/mail") +public class MailController { + @Autowired + public MailService mailService; + + @RequestMapping(value = "/send", method = RequestMethod.GET) + public String createMail(Model model) { + model.addAttribute("mailObject", new MailObject()); + return "mail/send"; + } + + @RequestMapping(value = "/send", method = RequestMethod.POST) + public String createMail(Model model, + @ModelAttribute("mailObject") @Valid MailObject mailObject, + Errors errors) { + if(errors.hasErrors()) { + return "mail/send"; + } + + SimpleMailMessage mailMessage = mailService.createSimpleMailMessage(mailObject); + mailService.sendMail(mailMessage); + + return "redirect:/home"; + } +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java new file mode 100644 index 0000000000..68f89f778d --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.mail; + +import org.springframework.mail.SimpleMailMessage; + +/** + * Created by Olga on 7/15/2016. + */ +public class Application { + + public static void main(String ...args) { + MailService mailService = new MailService(); + + SimpleMailMessage message = new SimpleMailMessage(); + message.setFrom("from@test.com"); + message.setTo("to@test.com"); + message.setSubject("Test Message"); + + mailService.sendMail(message); + } +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java new file mode 100644 index 0000000000..4deab12e0a --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java @@ -0,0 +1,73 @@ +package com.baeldung.spring.mail; + +import com.baeldung.spring.web.dto.MailObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.FileSystemResource; +import org.springframework.mail.MailException; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Service; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.File; + +/** + * Created by Olga on 7/15/2016. + */ +@Service +public class MailService { + @Autowired + public JavaMailSender mailSender; + + public void sendMail(MimeMessage message) { + try { + mailSender.send(message); + } catch (MailException exception) { + exception.printStackTrace(); + } + } + + public MimeMessage createMessageWithAttachment(MailObject mailObject) { + MimeMessage message = mailSender.createMimeMessage(); + try { + // pass 'true' to the constructor to create a multipart message + MimeMessageHelper helper = new MimeMessageHelper(message, true); + + helper.setFrom(mailObject.getFrom()); + helper.setTo(mailObject.getTo()); + helper.setSubject(mailObject.getSubject()); + helper.setText(mailObject.getText()); + + // attach a sample image attachment + FileSystemResource file = new FileSystemResource(new File("c:/attachment.jpg")); + helper.addAttachment("Attachment.jpg", file); + } catch (MessagingException e) { + e.printStackTrace(); + } + return message; + } + + public void sendMail(SimpleMailMessage message) { + try { + mailSender.send(message); + } catch (MailException exception) { + exception.printStackTrace(); + } + } + + @Autowired + public SimpleMailMessage template; + + public SimpleMailMessage createSimpleMailMessage(MailObject mailObject) { + SimpleMailMessage mailMessage = new SimpleMailMessage(template); + + mailMessage.setFrom(mailObject.getFrom()); + mailMessage.setTo(mailObject.getTo()); + mailMessage.setSubject(mailObject.getSubject()); + mailMessage.setText(String.format(template.getText(), mailObject.getText())); + + return mailMessage; + } +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java b/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java new file mode 100644 index 0000000000..70975be84c --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java @@ -0,0 +1,50 @@ +package com.baeldung.spring.web.dto; + +import org.hibernate.validator.constraints.Email; + +import javax.validation.constraints.NotNull; + +/** + * Created by Olga on 7/20/2016. + */ +public class MailObject { + @Email + private String from; + @NotNull + @Email + private String to; + private String subject; + private String text; + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} diff --git a/spring-mvc-email/src/main/resources/META-INF/application.xml b/spring-mvc-email/src/main/resources/META-INF/application.xml new file mode 100644 index 0000000000..f2d901b497 --- /dev/null +++ b/spring-mvc-email/src/main/resources/META-INF/application.xml @@ -0,0 +1,19 @@ + + + + + + SpringMVCEmail.war + SpringMVCEmail + + + + + web.war + SpringMVCEmail + + + \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp b/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp new file mode 100644 index 0000000000..74165f2626 --- /dev/null +++ b/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp @@ -0,0 +1,25 @@ +<%-- + Created by IntelliJ IDEA. + User: Olga + Date: 1/19/16 + Time: 3:53 PM + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + Home Page + + +
+
+

Send Email

+
+ +
+
+
+ + \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp new file mode 100644 index 0000000000..9e9cbc1ff7 --- /dev/null +++ b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp @@ -0,0 +1,60 @@ +<%-- + Created by IntelliJ IDEA. + User: Olga + Date: 7/20/2016 + Time: 1:47 PM + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + Send Email + + +
+

Create Email

+ +
+ + + + + + + + + + + + + + + + + + + + +
+ Enter email address
+ +
+ Enter your email address
+ +
+ Enter the subject
+ +
+ Enter message text
+ +
+ Send +
+
+
+
+ + diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..5fe46d45d6 --- /dev/null +++ b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,28 @@ + + + + + simpleweb + org.springframework.web.servlet.DispatcherServlet + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + com.baeldung.spring.config.AppConfig + + 1 + + + + simpleweb + / + + From 2bef18b3db5c1362f5ac7f9a3574762cba9c13ca Mon Sep 17 00:00:00 2001 From: oreva Date: Thu, 28 Jul 2016 21:56:36 +0300 Subject: [PATCH 02/86] Validation for empty "to" and "from" fields added. --- .../main/java/com/baeldung/spring/web/dto/MailObject.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java b/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java index 70975be84c..3369ccd9f6 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java @@ -3,15 +3,19 @@ package com.baeldung.spring.web.dto; import org.hibernate.validator.constraints.Email; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; /** * Created by Olga on 7/20/2016. */ public class MailObject { @Email - private String from; @NotNull + @Size(min = 1, message = "Please, specify your email address") + private String from; @Email + @NotNull + @Size(min = 1, message = "Please, set an email address to send the message to it") private String to; private String subject; private String text; From 8c21d6a3b090cc9c89ee034e8b1fccb22bd742d0 Mon Sep 17 00:00:00 2001 From: oreva Date: Thu, 28 Jul 2016 21:57:56 +0300 Subject: [PATCH 03/86] My personal username and pwd removed, test strings added instead. --- .../src/main/java/com/baeldung/spring/config/AppConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java index 2a7caadf23..4c5286490b 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java @@ -52,8 +52,8 @@ public class AppConfig extends WebMvcConfigurerAdapter { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost("smtp.gmail.com"); mailSender.setPort(587); - mailSender.setUsername("reva.olga"); - mailSender.setPassword("zakpnejnnoqkehgs"); + mailSender.setUsername("username"); + mailSender.setPassword("password"); mailSender.setJavaMailProperties(javaMailProperties()); return mailSender; } From 468ccfc2168c004c9e9a5458ea353df7b487ab00 Mon Sep 17 00:00:00 2001 From: oreva Date: Thu, 18 Aug 2016 22:33:41 +0300 Subject: [PATCH 04/86] Spring-boot-starter-mail added. Don't work (JavaMailSender is not created automatically). --- spring-mvc-email/pom.xml | 160 +++++++----------- spring-mvc-email/pom_old.xml | 142 ++++++++++++++++ .../java/com/baeldung/spring/Application.java | 35 ++++ .../spring/{ => app}/config/AppConfig.java | 17 +- .../baeldung/spring/application.properties | 4 + .../spring/controllers/HomeController.java | 8 +- .../spring/controllers/MailController.java | 16 +- .../com/baeldung/spring/mail/Application.java | 20 --- ...MailService.java => EmailServiceImpl.java} | 26 +-- .../main/resources/META-INF/application.xml | 2 +- .../main/webapp/WEB-INF/simpleweb-servlet.xml | 23 +++ .../src/main/webapp/WEB-INF/web.xml | 19 ++- 12 files changed, 307 insertions(+), 165 deletions(-) create mode 100644 spring-mvc-email/pom_old.xml create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/Application.java rename spring-mvc-email/src/main/java/com/baeldung/spring/{ => app}/config/AppConfig.java (89%) create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/application.properties delete mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java rename spring-mvc-email/src/main/java/com/baeldung/spring/mail/{MailService.java => EmailServiceImpl.java} (81%) create mode 100644 spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml diff --git a/spring-mvc-email/pom.xml b/spring-mvc-email/pom.xml index 0ac84f5cc9..6b2ef0bf9b 100644 --- a/spring-mvc-email/pom.xml +++ b/spring-mvc-email/pom.xml @@ -1,142 +1,96 @@ - 4.0.0 org.baeldung.spring SpringMVCEmail + 1.0-SNAPSHOT war - 1.0 + + + org.springframework.boot + spring-boot-starter-parent + 1.4.0.RELEASE + + - - javax.servlet - javax.servlet-api - 3.0.1 + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-mail + 1.4.0.RELEASE + + + org.springframework.boot + spring-boot-starter-tomcat provided - - - javax.servlet - jstl - 1.2 + + com.jayway.jsonpath + json-path + test + --> + + + - - javax.validation - validation-api - 1.1.0.Final - - - - - org.hibernate - hibernate-validator - 5.0.1.Final - - - - - org.springframework.data - spring-data-jpa - 1.10.1.RELEASE - - - - - org.springframework.security - spring-security-web - 4.0.4.RELEASE - - - org.springframework.security - spring-security-config - 4.0.4.RELEASE - - - - - com.sun.mail - javax.mail - 1.5.5 - - - - - org.springframework.integration - spring-integration-mail - 4.3.0.RELEASE - + 4.3.2.RELEASE + --> + + 1.8 + + + - SpringMVCEmail - - - org.apache.tomcat.maven - tomcat6-maven-plugin - 2.2 - - http://localhost:8080/manager/text - TomcatServer - /SpringMVCEmail - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - - org.apache.maven.plugins - maven-war-plugin - 2.4 - - src/main/webapp/WEB-INF/web.xml - - - src/main/resources/META-INF - - - + org.springframework.boot + spring-boot-maven-plugin - \ No newline at end of file + + + + spring-releases + https://repo.spring.io/libs-release + + + + + spring-releases + https://repo.spring.io/libs-release + + + diff --git a/spring-mvc-email/pom_old.xml b/spring-mvc-email/pom_old.xml new file mode 100644 index 0000000000..0ac84f5cc9 --- /dev/null +++ b/spring-mvc-email/pom_old.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + + org.baeldung.spring + SpringMVCEmail + war + 1.0 + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + javax.servlet + jstl + 1.2 + + + + + org.springframework + spring-context + 4.2.5.RELEASE + + + + org.springframework + spring-core + 4.2.5.RELEASE + + + + org.springframework + spring-web + 4.2.5.RELEASE + + + + org.springframework + spring-webmvc + 4.2.5.RELEASE + + + + + javax.validation + validation-api + 1.1.0.Final + + + + + org.hibernate + hibernate-validator + 5.0.1.Final + + + + + org.springframework.data + spring-data-jpa + 1.10.1.RELEASE + + + + + org.springframework.security + spring-security-web + 4.0.4.RELEASE + + + org.springframework.security + spring-security-config + 4.0.4.RELEASE + + + + + com.sun.mail + javax.mail + 1.5.5 + + + + + org.springframework.integration + spring-integration-mail + 4.3.0.RELEASE + + + + + SpringMVCEmail + + + + + org.apache.tomcat.maven + tomcat6-maven-plugin + 2.2 + + http://localhost:8080/manager/text + TomcatServer + /SpringMVCEmail + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + src/main/webapp/WEB-INF/web.xml + + + src/main/resources/META-INF + + + + + + + \ No newline at end of file diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java new file mode 100644 index 0000000000..0ab568e111 --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java @@ -0,0 +1,35 @@ +package com.baeldung.spring; + +import com.baeldung.spring.mail.EmailServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.mail.SimpleMailMessage; + +import javax.annotation.PostConstruct; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + + } + + @Autowired + public EmailServiceImpl emailService; + + @PostConstruct + public void postConstruct() { + sendSimpleEmail(); + } + + private void sendSimpleEmail() { + + SimpleMailMessage message = new SimpleMailMessage(); + message.setFrom("from@test.com"); + message.setTo("to@test.com"); + message.setSubject("Test Message"); + + emailService.sendMail(message); + } +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java similarity index 89% rename from spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java rename to spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java index 4c5286490b..4dcf9c1b7d 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/config/AppConfig.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java @@ -1,24 +1,19 @@ -package com.baeldung.spring.config; +package com.baeldung.spring.app.config; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.web.servlet.config.annotation.*; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.UrlBasedViewResolver; -import java.util.Properties; - /** * Created with IntelliJ IDEA. * User: Olga */ -@Configuration -@ComponentScan("com.baeldung.spring") -@EnableWebMvc //tha same as +//@Configuration +//@ComponentScan("com.baeldung.spring") +//@EnableWebMvc //tha same as public class AppConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { @@ -47,7 +42,7 @@ public class AppConfig extends WebMvcConfigurerAdapter { } /* Gmail */ - @Bean + /*@Bean public JavaMailSenderImpl mailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost("smtp.gmail.com"); @@ -63,7 +58,7 @@ public class AppConfig extends WebMvcConfigurerAdapter { props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtp.starttls.enable", "true"); return props; - } + }*/ @Bean public SimpleMailMessage templateMessage() { diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/application.properties b/spring-mvc-email/src/main/java/com/baeldung/spring/application.properties new file mode 100644 index 0000000000..573f901152 --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/application.properties @@ -0,0 +1,4 @@ +spring.mail.host=smtp.gmail.com +spring.mail.port=25 +spring.mail.username=test +spring.mail.password=test \ No newline at end of file diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java index 656e237a9e..234593f02e 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java @@ -3,17 +3,19 @@ package com.baeldung.spring.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; /** * Created with IntelliJ IDEA. * User: Olga */ -@Controller +@RestController @RequestMapping({"/","/home"}) public class HomeController { @RequestMapping(method = RequestMethod.GET) - public String showHomePage() { - return "home"; + public ModelAndView showHomePage() { + return new ModelAndView("home"); } } 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 5de722f444..90f628f586 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 @@ -1,17 +1,7 @@ package com.baeldung.spring.controllers; -import com.baeldung.spring.mail.MailService; -import com.baeldung.spring.web.dto.MailObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mail.SimpleMailMessage; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import javax.validation.Valid; /** * Created by Olga on 7/20/2016. @@ -19,8 +9,8 @@ import javax.validation.Valid; @Controller @RequestMapping("/mail") public class MailController { - @Autowired - public MailService mailService; + /*@Autowired + public EMailService mailService; @RequestMapping(value = "/send", method = RequestMethod.GET) public String createMail(Model model) { @@ -40,5 +30,5 @@ public class MailController { mailService.sendMail(mailMessage); return "redirect:/home"; - } + }*/ } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java deleted file mode 100644 index 68f89f778d..0000000000 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Application.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.spring.mail; - -import org.springframework.mail.SimpleMailMessage; - -/** - * Created by Olga on 7/15/2016. - */ -public class Application { - - public static void main(String ...args) { - MailService mailService = new MailService(); - - SimpleMailMessage message = new SimpleMailMessage(); - message.setFrom("from@test.com"); - message.setTo("to@test.com"); - message.setSubject("Test Message"); - - mailService.sendMail(message); - } -} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java similarity index 81% rename from spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java rename to spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java index 4deab12e0a..bba646afcc 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/MailService.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java @@ -2,11 +2,13 @@ package com.baeldung.spring.mail; import com.baeldung.spring.web.dto.MailObject; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.core.io.FileSystemResource; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import javax.mail.MessagingException; @@ -16,21 +18,23 @@ import java.io.File; /** * Created by Olga on 7/15/2016. */ -@Service -public class MailService { - @Autowired - public JavaMailSender mailSender; +@Component +@ConditionalOnClass(JavaMailSender.class) +public class EmailServiceImpl { - public void sendMail(MimeMessage message) { + @Autowired + public JavaMailSender emailSender; + + /*public void sendMail(MimeMessage message) { try { - mailSender.send(message); + emailSender.send(message); } catch (MailException exception) { exception.printStackTrace(); } } public MimeMessage createMessageWithAttachment(MailObject mailObject) { - MimeMessage message = mailSender.createMimeMessage(); + MimeMessage message = emailSender.createMimeMessage(); try { // pass 'true' to the constructor to create a multipart message MimeMessageHelper helper = new MimeMessageHelper(message, true); @@ -47,17 +51,17 @@ public class MailService { e.printStackTrace(); } return message; - } + }*/ public void sendMail(SimpleMailMessage message) { try { - mailSender.send(message); + emailSender.send(message); } catch (MailException exception) { exception.printStackTrace(); } } - @Autowired + /*@Autowired public SimpleMailMessage template; public SimpleMailMessage createSimpleMailMessage(MailObject mailObject) { @@ -69,5 +73,5 @@ public class MailService { mailMessage.setText(String.format(template.getText(), mailObject.getText())); return mailMessage; - } + }*/ } diff --git a/spring-mvc-email/src/main/resources/META-INF/application.xml b/spring-mvc-email/src/main/resources/META-INF/application.xml index f2d901b497..759a312bd4 100644 --- a/spring-mvc-email/src/main/resources/META-INF/application.xml +++ b/spring-mvc-email/src/main/resources/META-INF/application.xml @@ -13,7 +13,7 @@ web.war - SpringMVCEmail + SpringMVCEmailWeb \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml b/spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml new file mode 100644 index 0000000000..5a3bb2377a --- /dev/null +++ b/spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml index 5fe46d45d6..b979e00276 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml +++ b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml @@ -8,7 +8,7 @@ simpleweb org.springframework.web.servlet.DispatcherServlet - + 1 @@ -25,4 +25,17 @@ simpleweb / + + + + org.springframework.web.context.ContextLoaderListener + + + + + contextConfigLocation + + /WEB-INF/simpleweb-servlet.xml + + From faf368d10c4ac7d086eb7f2b9d1a02226fa7ea5d Mon Sep 17 00:00:00 2001 From: oreva Date: Mon, 22 Aug 2016 23:58:18 +0300 Subject: [PATCH 05/86] Spring-boot-starter-mail provided succsessfully. --- spring-mvc-email/pom.xml | 59 +++---------------- .../java/com/baeldung/spring/Application.java | 25 ++++---- .../baeldung/spring/app/config/AppConfig.java | 29 ++++----- .../baeldung/spring/application.properties | 4 -- .../spring/controllers/HomeController.java | 6 +- .../spring/controllers/MailController.java | 23 +++++--- .../baeldung/spring/mail/EmailService.java | 20 +++++++ .../spring/mail/EmailServiceImpl.java | 57 ++++++++++++++---- .../java/com/baeldung/spring/mail/Order.java | 43 ++++++++++++++ .../baeldung/spring/mail/OrderManager.java | 29 +++++++++ .../src/main/resources/application.properties | 20 +++++++ .../src/main/webapp/WEB-INF/web.xml | 8 +-- 12 files changed, 216 insertions(+), 107 deletions(-) delete mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/application.properties create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailService.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java create mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java create mode 100644 spring-mvc-email/src/main/resources/application.properties diff --git a/spring-mvc-email/pom.xml b/spring-mvc-email/pom.xml index 6b2ef0bf9b..0d3acec1fe 100644 --- a/spring-mvc-email/pom.xml +++ b/spring-mvc-email/pom.xml @@ -5,7 +5,7 @@ org.baeldung.spring SpringMVCEmail - 1.0-SNAPSHOT + 1.0 war @@ -20,51 +20,23 @@ org.springframework.boot spring-boot-starter-web + org.springframework.boot spring-boot-starter-mail 1.4.0.RELEASE + - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - - @@ -80,17 +52,4 @@ - - - - spring-releases - https://repo.spring.io/libs-release - - - - - spring-releases - https://repo.spring.io/libs-release - - diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java index 0ab568e111..769658fdde 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java @@ -1,9 +1,14 @@ package com.baeldung.spring; +import com.baeldung.spring.mail.EmailService; import com.baeldung.spring.mail.EmailServiceImpl; +import com.baeldung.spring.mail.Order; +import com.baeldung.spring.mail.OrderManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ImportResource; import org.springframework.mail.SimpleMailMessage; import javax.annotation.PostConstruct; @@ -12,24 +17,18 @@ import javax.annotation.PostConstruct; public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); - } @Autowired - public EmailServiceImpl emailService; + public EmailService emailService; + + @Autowired + public OrderManager orderManager; @PostConstruct public void postConstruct() { - sendSimpleEmail(); - } - - private void sendSimpleEmail() { - - SimpleMailMessage message = new SimpleMailMessage(); - message.setFrom("from@test.com"); - message.setTo("to@test.com"); - message.setSubject("Test Message"); - - emailService.sendMail(message); + //emailService.sendSimpleMessage("to@gmail.com", "Test Subject", "Test Message"); + Order order = new Order("reva.olga@gmail.com", "First Name", "Last Name"); + orderManager.placeOrder(order); } } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java index 4dcf9c1b7d..0c1662a36c 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java @@ -1,6 +1,8 @@ package com.baeldung.spring.app.config; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; import org.springframework.mail.SimpleMailMessage; import org.springframework.web.servlet.config.annotation.*; import org.springframework.web.servlet.view.InternalResourceViewResolver; @@ -11,9 +13,9 @@ import org.springframework.web.servlet.view.UrlBasedViewResolver; * Created with IntelliJ IDEA. * User: Olga */ -//@Configuration -//@ComponentScan("com.baeldung.spring") -//@EnableWebMvc //tha same as +@Configuration +@ComponentScan("com.baeldung.spring") +@EnableWebMvc //tha same as public class AppConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { @@ -41,6 +43,16 @@ public class AppConfig extends WebMvcConfigurerAdapter { return resolver; } + @Bean + public SimpleMailMessage templateMessage() { + SimpleMailMessage message = new SimpleMailMessage(); + message.setText("Dear %s %s, \nthank you for placing order.\n" + + "\n" + + "Sincerely yours,\n" + + "Yourcompany."); + return message; + } + /* Gmail */ /*@Bean public JavaMailSenderImpl mailSender() { @@ -60,17 +72,6 @@ public class AppConfig extends WebMvcConfigurerAdapter { return props; }*/ - @Bean - public SimpleMailMessage templateMessage() { - SimpleMailMessage message = new SimpleMailMessage(); - message.setText("This is automatically generated email,\n" + - "Original mail text is included : %s\n" + - "\n" + - "Sincerely yours,\n" + - "Yourcompany."); - return message; - } - /*Amazon SES @Bean public JavaMailSenderImpl mailSender() { diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/application.properties b/spring-mvc-email/src/main/java/com/baeldung/spring/application.properties deleted file mode 100644 index 573f901152..0000000000 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.mail.host=smtp.gmail.com -spring.mail.port=25 -spring.mail.username=test -spring.mail.password=test \ No newline at end of file diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java index 234593f02e..50643684d1 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java @@ -10,12 +10,12 @@ import org.springframework.web.servlet.ModelAndView; * Created with IntelliJ IDEA. * User: Olga */ -@RestController +@Controller @RequestMapping({"/","/home"}) public class HomeController { @RequestMapping(method = RequestMethod.GET) - public ModelAndView showHomePage() { - return new ModelAndView("home"); + public String showHomePage() { + return "home"; } } 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 90f628f586..79152797ff 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 @@ -1,7 +1,17 @@ package com.baeldung.spring.controllers; +import com.baeldung.spring.mail.EmailServiceImpl; +import com.baeldung.spring.web.dto.MailObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mail.SimpleMailMessage; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.validation.Valid; /** * Created by Olga on 7/20/2016. @@ -9,8 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/mail") public class MailController { - /*@Autowired - public EMailService mailService; + @Autowired + public EmailServiceImpl emailService; @RequestMapping(value = "/send", method = RequestMethod.GET) public String createMail(Model model) { @@ -22,13 +32,8 @@ public class MailController { public String createMail(Model model, @ModelAttribute("mailObject") @Valid MailObject mailObject, Errors errors) { - if(errors.hasErrors()) { - return "mail/send"; - } - - SimpleMailMessage mailMessage = mailService.createSimpleMailMessage(mailObject); - mailService.sendMail(mailMessage); + emailService.sendSimpleMessage("to@gmail.com", "Test Subject", "Test Message"); return "redirect:/home"; - }*/ + } } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailService.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailService.java new file mode 100644 index 0000000000..43d7378227 --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailService.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.mail; + +import org.springframework.mail.SimpleMailMessage; + +/** + * Created by Olga on 8/22/2016. + */ +public interface EmailService { + void sendSimpleMessage(String to, + String subject, + String text); + void sendSimpleMessageUsingTemplate(String to, + String subject, + SimpleMailMessage template, + String ...templateArgs); + void sendMessageWithAttachment(String to, + String subject, + String text, + String pathToAttachment); +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java index bba646afcc..a6bcb00943 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java @@ -19,12 +19,57 @@ import java.io.File; * Created by Olga on 7/15/2016. */ @Component -@ConditionalOnClass(JavaMailSender.class) -public class EmailServiceImpl { +public class EmailServiceImpl implements EmailService { @Autowired public JavaMailSender emailSender; + public void sendSimpleMessage(String to, String subject, String text) { + try { + SimpleMailMessage message = new SimpleMailMessage(); + + message.setTo(to); + message.setSubject(subject); + message.setText(text); + + emailSender.send(message); + } catch (MailException exception) { + exception.printStackTrace(); + } + } + + @Override + public void sendSimpleMessageUsingTemplate(String to, + String subject, + SimpleMailMessage template, + String ...templateArgs) { + String text = String.format(template.getText(), templateArgs); + sendSimpleMessage(to, subject, text); + } + + @Override + public void sendMessageWithAttachment(String to, + String subject, + String text, + String pathToAttachment) { + try { + MimeMessage message = emailSender.createMimeMessage(); + // pass 'true' to the constructor to create a multipart message + MimeMessageHelper helper = new MimeMessageHelper(message, true); + + helper.setTo(to); + helper.setSubject(subject); + helper.setText(text); + + FileSystemResource file = new FileSystemResource(new File(pathToAttachment)); + helper.addAttachment("Invoice", file); + + emailSender.send(message); + } catch (MessagingException e) { + e.printStackTrace(); + } + } + /*public void sendMail(MimeMessage message) { try { emailSender.send(message); @@ -53,14 +98,6 @@ public class EmailServiceImpl { return message; }*/ - public void sendMail(SimpleMailMessage message) { - try { - emailSender.send(message); - } catch (MailException exception) { - exception.printStackTrace(); - } - } - /*@Autowired public SimpleMailMessage template; diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java new file mode 100644 index 0000000000..cd1448b84b --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java @@ -0,0 +1,43 @@ +package com.baeldung.spring.mail; + +/** + * Created by Olga on 8/22/2016. + */ +public class Order { + + public Order(String customerEmail, + String customerFirstName, + String customerLastName) { + this.customerEmail = customerEmail; + this.customerFirstName = customerFirstName; + this.customerLastName = customerLastName; + } + + private String customerEmail; + private String customerFirstName; + private String customerLastName; + + public String getCustomerEmail() { + return customerEmail; + } + + public void setCustomerEmail(String customerEmail) { + this.customerEmail = customerEmail; + } + + public String getCustomerFirstName() { + return customerFirstName; + } + + public void setCustomerFirstName(String customerFirstName) { + this.customerFirstName = customerFirstName; + } + + public String getCustomerLastName() { + return customerLastName; + } + + public void setCustomerLastName(String customerLastName) { + this.customerLastName = customerLastName; + } +} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java new file mode 100644 index 0000000000..23f6184c8a --- /dev/null +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java @@ -0,0 +1,29 @@ +package com.baeldung.spring.mail; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.stereotype.Component; + +/** + * Created by Olga on 8/22/2016. + */ +@Component +public class OrderManager { + @Autowired + public EmailService emailService; + + @Value("${attachment.invoice}") + private String invoiceAttachmentPath; + + @Autowired + public SimpleMailMessage template; + + public void placeOrder(Order order) { + emailService.sendSimpleMessageUsingTemplate(order.getCustomerEmail(), + "Order Confirmation", + template, + order.getCustomerFirstName(), + order.getCustomerLastName()); + } +} diff --git a/spring-mvc-email/src/main/resources/application.properties b/spring-mvc-email/src/main/resources/application.properties new file mode 100644 index 0000000000..07ded8f46b --- /dev/null +++ b/spring-mvc-email/src/main/resources/application.properties @@ -0,0 +1,20 @@ +# Gmail SMTP +spring.mail.host=smtp.gmail.com +spring.mail.port=587 +spring.mail.username=reva.olga@gmail.com +spring.mail.password=yubtqniqehrimqyf +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true + +# Amazon SES SMTP +#spring.mail.host=email-smtp.us-west-2.amazonaws.com +#spring.mail.username=username +#spring.mail.password=password +#spring.mail.properties.mail.transport.protocol=smtp +#spring.mail.properties.mail.smtp.port=25 +#spring.mail.properties.mail.smtp.auth=true +#spring.mail.properties.mail.smtp.starttls.enable=true +#spring.mail.properties.mail.smtp.starttls.required=true + +# path to attachment file +attachment.invoice=c:/invoice.jpg \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml index b979e00276..cbc1bee20a 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml +++ b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml @@ -8,7 +8,7 @@ simpleweb org.springframework.web.servlet.DispatcherServlet - + 1 @@ -26,7 +26,7 @@ / - + From 31bac637ac766856ca22b09ea21c9c6cdb9a638c Mon Sep 17 00:00:00 2001 From: oreva Date: Tue, 23 Aug 2016 00:04:26 +0300 Subject: [PATCH 06/86] Changed application.properties on defaults for username and pwd. --- spring-mvc-email/src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-mvc-email/src/main/resources/application.properties b/spring-mvc-email/src/main/resources/application.properties index 07ded8f46b..61a42050e5 100644 --- a/spring-mvc-email/src/main/resources/application.properties +++ b/spring-mvc-email/src/main/resources/application.properties @@ -1,8 +1,8 @@ # Gmail SMTP spring.mail.host=smtp.gmail.com spring.mail.port=587 -spring.mail.username=reva.olga@gmail.com -spring.mail.password=yubtqniqehrimqyf +spring.mail.username=username +spring.mail.password=password spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true @@ -17,4 +17,4 @@ spring.mail.properties.mail.smtp.starttls.enable=true #spring.mail.properties.mail.smtp.starttls.required=true # path to attachment file -attachment.invoice=c:/invoice.jpg \ No newline at end of file +attachment.invoice=path_to_file \ No newline at end of file From 6a599b94068a8dfb33bb8afca2367f9f3a09ce67 Mon Sep 17 00:00:00 2001 From: oreva Date: Mon, 29 Aug 2016 11:49:29 +0300 Subject: [PATCH 07/86] pom_old.xml deleted. --- spring-mvc-email/pom_old.xml | 142 ----------------------------------- 1 file changed, 142 deletions(-) delete mode 100644 spring-mvc-email/pom_old.xml diff --git a/spring-mvc-email/pom_old.xml b/spring-mvc-email/pom_old.xml deleted file mode 100644 index 0ac84f5cc9..0000000000 --- a/spring-mvc-email/pom_old.xml +++ /dev/null @@ -1,142 +0,0 @@ - - - 4.0.0 - - org.baeldung.spring - SpringMVCEmail - war - 1.0 - - - - - javax.servlet - javax.servlet-api - 3.0.1 - provided - - - - javax.servlet - jstl - 1.2 - - - - - org.springframework - spring-context - 4.2.5.RELEASE - - - - org.springframework - spring-core - 4.2.5.RELEASE - - - - org.springframework - spring-web - 4.2.5.RELEASE - - - - org.springframework - spring-webmvc - 4.2.5.RELEASE - - - - - javax.validation - validation-api - 1.1.0.Final - - - - - org.hibernate - hibernate-validator - 5.0.1.Final - - - - - org.springframework.data - spring-data-jpa - 1.10.1.RELEASE - - - - - org.springframework.security - spring-security-web - 4.0.4.RELEASE - - - org.springframework.security - spring-security-config - 4.0.4.RELEASE - - - - - com.sun.mail - javax.mail - 1.5.5 - - - - - org.springframework.integration - spring-integration-mail - 4.3.0.RELEASE - - - - - SpringMVCEmail - - - - - org.apache.tomcat.maven - tomcat6-maven-plugin - 2.2 - - http://localhost:8080/manager/text - TomcatServer - /SpringMVCEmail - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - - org.apache.maven.plugins - maven-war-plugin - 2.4 - - src/main/webapp/WEB-INF/web.xml - - - src/main/resources/META-INF - - - - - - - \ No newline at end of file From 095fe5625a1a50a534f31f094cfbdbd2b133d0a1 Mon Sep 17 00:00:00 2001 From: oreva Date: Tue, 13 Sep 2016 09:35:23 +0300 Subject: [PATCH 08/86] Implemented changes according to the latest comments in my pull request. Now we can send email from the web. Access: http://localhost:8080 --- spring-mvc-email/readme.txt | 6 +++ .../java/com/baeldung/spring/Application.java | 3 +- .../baeldung/spring/app/config/AppConfig.java | 44 ++--------------- .../spring/controllers/MailController.java | 47 ++++++++++++++++++- .../spring/mail/EmailServiceImpl.java | 42 ----------------- .../baeldung/spring/mail/OrderManager.java | 4 +- .../baeldung/spring/web/dto/MailObject.java | 12 ----- .../src/main/resources/application.properties | 3 +- .../main/webapp/WEB-INF/simpleweb-servlet.xml | 23 --------- .../main/webapp/WEB-INF/views/mail/send.jsp | 12 ++--- .../src/main/webapp/WEB-INF/web.xml | 12 ----- 11 files changed, 67 insertions(+), 141 deletions(-) create mode 100644 spring-mvc-email/readme.txt delete mode 100644 spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml diff --git a/spring-mvc-email/readme.txt b/spring-mvc-email/readme.txt new file mode 100644 index 0000000000..24ff5438d7 --- /dev/null +++ b/spring-mvc-email/readme.txt @@ -0,0 +1,6 @@ +You can send test email in several ways: +First of all, you should set application.properties properly. +1. Just build the project and the test email for order confirmation will be sent on Spring Boot Start. +2. You can use the web form and test all the cases of sending email in your browser. +Just start the application then type http://localhost:8080 and follow the web flow. +You can send simple email, email with template, email with attachment from the web. \ No newline at end of file diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java index 769658fdde..7d92c2964a 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java @@ -27,8 +27,7 @@ public class Application { @PostConstruct public void postConstruct() { - //emailService.sendSimpleMessage("to@gmail.com", "Test Subject", "Test Message"); - Order order = new Order("reva.olga@gmail.com", "First Name", "Last Name"); + Order order = new Order("user_email_address", "First Name", "Last Name"); orderManager.placeOrder(order); } } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java index 0c1662a36c..4fb684c2b6 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java @@ -44,7 +44,7 @@ public class AppConfig extends WebMvcConfigurerAdapter { } @Bean - public SimpleMailMessage templateMessage() { + public SimpleMailMessage templateOrderMessage() { SimpleMailMessage message = new SimpleMailMessage(); message.setText("Dear %s %s, \nthank you for placing order.\n" + "\n" + @@ -53,44 +53,10 @@ public class AppConfig extends WebMvcConfigurerAdapter { return message; } - /* Gmail */ - /*@Bean - public JavaMailSenderImpl mailSender() { - JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); - mailSender.setHost("smtp.gmail.com"); - mailSender.setPort(587); - mailSender.setUsername("username"); - mailSender.setPassword("password"); - mailSender.setJavaMailProperties(javaMailProperties()); - return mailSender; - } - - private Properties javaMailProperties() { - Properties props = new Properties(); - props.setProperty("mail.smtp.auth", "true"); - props.setProperty("mail.smtp.starttls.enable", "true"); - return props; - }*/ - - /*Amazon SES @Bean - public JavaMailSenderImpl mailSender() { - JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); - mailSender.setHost("email-smtp.us-west-2.amazonaws.com"); - mailSender.setUsername("username"); - mailSender.setPassword("password"); - mailSender.setJavaMailProperties(javaMailProperties()); - return mailSender; + public SimpleMailMessage templateSimpleMessage() { + SimpleMailMessage message = new SimpleMailMessage(); + message.setText("This is the test email template for your email:\n%s\n"); + return message; } - - private Properties javaMailProperties() { - Properties props = new Properties(); - props.setProperty("mail.transport.protocol", "smtps"); - props.setProperty("mail.smtp.port", "25"); - - props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.starttls.enable", "true"); - props.put("mail.smtp.starttls.required", "true"); - return props; - }*/ } 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 79152797ff..832a60ba5d 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 @@ -3,6 +3,8 @@ package com.baeldung.spring.controllers; import com.baeldung.spring.mail.EmailServiceImpl; import com.baeldung.spring.web.dto.MailObject; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -22,6 +24,13 @@ public class MailController { @Autowired public EmailServiceImpl emailService; + @Value("${attachment.invoice}") + private String attachmentPath; + + @Autowired + @Qualifier("templateSimpleMessage") + public SimpleMailMessage template; + @RequestMapping(value = "/send", method = RequestMethod.GET) public String createMail(Model model) { model.addAttribute("mailObject", new MailObject()); @@ -32,7 +41,43 @@ public class MailController { public String createMail(Model model, @ModelAttribute("mailObject") @Valid MailObject mailObject, Errors errors) { - emailService.sendSimpleMessage("to@gmail.com", "Test Subject", "Test Message"); + if (errors.hasErrors()) { + return "mail/send"; + } + emailService.sendSimpleMessage(mailObject.getTo(), + mailObject.getSubject(), mailObject.getText()); + + return "redirect:/home"; + } + + @RequestMapping(value = "/sendTemplate", method = RequestMethod.POST) + public String createMailWithTemplate(Model model, + @ModelAttribute("mailObject") @Valid MailObject mailObject, + Errors errors) { + if (errors.hasErrors()) { + return "mail/send"; + } + emailService.sendSimpleMessageUsingTemplate(mailObject.getTo(), + mailObject.getSubject(), + template, + mailObject.getText()); + + return "redirect:/home"; + } + + @RequestMapping(value = "/sendAttachment", method = RequestMethod.POST) + public String createMailWithAttachment(Model model, + @ModelAttribute("mailObject") @Valid MailObject mailObject, + Errors errors) { + if (errors.hasErrors()) { + return "mail/send"; + } + emailService.sendMessageWithAttachment( + mailObject.getTo(), + mailObject.getSubject(), + mailObject.getText(), + attachmentPath + ); return "redirect:/home"; } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java index a6bcb00943..8ecde598f9 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java @@ -69,46 +69,4 @@ public class EmailServiceImpl implements EmailService { e.printStackTrace(); } } - - /*public void sendMail(MimeMessage message) { - try { - emailSender.send(message); - } catch (MailException exception) { - exception.printStackTrace(); - } - } - - public MimeMessage createMessageWithAttachment(MailObject mailObject) { - MimeMessage message = emailSender.createMimeMessage(); - try { - // pass 'true' to the constructor to create a multipart message - MimeMessageHelper helper = new MimeMessageHelper(message, true); - - helper.setFrom(mailObject.getFrom()); - helper.setTo(mailObject.getTo()); - helper.setSubject(mailObject.getSubject()); - helper.setText(mailObject.getText()); - - // attach a sample image attachment - FileSystemResource file = new FileSystemResource(new File("c:/attachment.jpg")); - helper.addAttachment("Attachment.jpg", file); - } catch (MessagingException e) { - e.printStackTrace(); - } - return message; - }*/ - - /*@Autowired - public SimpleMailMessage template; - - public SimpleMailMessage createSimpleMailMessage(MailObject mailObject) { - SimpleMailMessage mailMessage = new SimpleMailMessage(template); - - mailMessage.setFrom(mailObject.getFrom()); - mailMessage.setTo(mailObject.getTo()); - mailMessage.setSubject(mailObject.getSubject()); - mailMessage.setText(String.format(template.getText(), mailObject.getText())); - - return mailMessage; - }*/ } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java index 23f6184c8a..5dfe25f20f 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java @@ -1,6 +1,7 @@ package com.baeldung.spring.mail; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; import org.springframework.stereotype.Component; @@ -16,7 +17,8 @@ public class OrderManager { @Value("${attachment.invoice}") private String invoiceAttachmentPath; - @Autowired + @Autowired() + @Qualifier("templateOrderMessage") public SimpleMailMessage template; public void placeOrder(Order order) { diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java b/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java index 3369ccd9f6..9623ff5d78 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/web/dto/MailObject.java @@ -9,10 +9,6 @@ import javax.validation.constraints.Size; * Created by Olga on 7/20/2016. */ public class MailObject { - @Email - @NotNull - @Size(min = 1, message = "Please, specify your email address") - private String from; @Email @NotNull @Size(min = 1, message = "Please, set an email address to send the message to it") @@ -20,14 +16,6 @@ public class MailObject { private String subject; private String text; - public String getFrom() { - return from; - } - - public void setFrom(String from) { - this.from = from; - } - public String getTo() { return to; } diff --git a/spring-mvc-email/src/main/resources/application.properties b/spring-mvc-email/src/main/resources/application.properties index 61a42050e5..ba0608c3af 100644 --- a/spring-mvc-email/src/main/resources/application.properties +++ b/spring-mvc-email/src/main/resources/application.properties @@ -17,4 +17,5 @@ spring.mail.properties.mail.smtp.starttls.enable=true #spring.mail.properties.mail.smtp.starttls.required=true # path to attachment file -attachment.invoice=path_to_file \ No newline at end of file +attachment.invoice=path_to_file +#attachment.invoice=c:/invoice.jpg \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml b/spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml deleted file mode 100644 index 5a3bb2377a..0000000000 --- a/spring-mvc-email/src/main/webapp/WEB-INF/simpleweb-servlet.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp index 9e9cbc1ff7..1307fc2baf 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp +++ b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp @@ -24,13 +24,6 @@ - - - - Enter your email address
- - - @@ -48,8 +41,11 @@ + - Send + + + diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml index cbc1bee20a..4cd41216d9 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/web.xml +++ b/spring-mvc-email/src/main/webapp/WEB-INF/web.xml @@ -26,16 +26,4 @@ / - From 6e97acc1ca9b0209a97dec455b1a890802910f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Sat, 17 Sep 2016 01:29:51 +0200 Subject: [PATCH 09/86] BAEL-41: Added including tests: - console appender using default layout - console appender using colorized pattern layout - async file appender using JSON layout --- logging/log4j2/pom.xml | 58 +++++++++++++++++++ .../AsyncFileAppenderUsingJsonLayoutTest.java | 45 ++++++++++++++ ...ConsoleAppenderUsingDefaultLayoutTest.java | 18 ++++++ ...enderUsingPatternLayoutWithColorsTest.java | 27 +++++++++ ...sync-file-appender_json-layout_colored.xml | 16 +++++ ...log4j2-console-appender_pattern-layout.xml | 11 ++++ ...onsole-appender_pattern-layout_colored.xml | 4 ++ logging/log4j2/src/test/resources/log4j2.xml | 13 +++++ logging/pom.xml | 40 +++++++++++++ 9 files changed, 232 insertions(+) create mode 100644 logging/log4j2/pom.xml create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java create mode 100644 logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout_colored.xml create mode 100644 logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml create mode 100644 logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml create mode 100644 logging/log4j2/src/test/resources/log4j2.xml create mode 100644 logging/pom.xml diff --git a/logging/log4j2/pom.xml b/logging/log4j2/pom.xml new file mode 100644 index 0000000000..537427e232 --- /dev/null +++ b/logging/log4j2/pom.xml @@ -0,0 +1,58 @@ + + + + logging + com.baeldung.logging + 1.0.0-SNAPSHOT + + 4.0.0 + + log4j2 + + + + + org.apache.logging.log4j + log4j-api + 2.6.2 + + + org.apache.logging.log4j + log4j-core + 2.6.2 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.8.2 + + + + + org.apache.logging.log4j + log4j-core + 2.6.2 + test-jar + test + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java new file mode 100644 index 0000000000..c9ce0c2828 --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java @@ -0,0 +1,45 @@ +package com.baeldung.logging.log4j2.tests; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertTrue; + +@RunWith(JUnit4.class) +public class AsyncFileAppenderUsingJsonLayoutTest { + + @Rule + public LoggerContextRule contextRule = new LoggerContextRule("log4j2-async-file-appender_json-layout_colored.xml"); + + @Test + public void givenLoggerWithAsyncConfig_shouldLogToJsonFile() throws Exception { + Logger logger = contextRule.getLogger(getClass().getSimpleName()); + final int count = 88; + for (int i = 0; i < count; i++) { + logger.info("This is async JSON message #{} at INFO level.", count); + } + ObjectMapper objectMapper = new ObjectMapper(); + List logEvents = Files.readAllLines(Paths.get("target/logfile.json")).stream() + .map(s -> { + try { + return objectMapper.readValue(s.getBytes(), LogEvent.class); + } catch (IOException e) { + throw new RuntimeException("Failed to import LogEvent!", e); + } + }) + .collect(Collectors.toList()); + assertTrue(logEvents.size() <= count); + } +} diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java new file mode 100644 index 0000000000..9d8b2ae81b --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java @@ -0,0 +1,18 @@ +package com.baeldung.logging.log4j2.tests; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ConsoleAppenderUsingDefaultLayoutTest { + + @Test + public void givenLoggerWithDefaultConfig_shouldLogToConsole() throws Exception { + Logger logger = LogManager.getLogger(ConsoleAppenderUsingDefaultLayoutTest.class); + Exception e = new RuntimeException("This is only a test!"); + logger.error("This is a simple message at ERROR level. This is the minimum visible level.", e); + } +} diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java new file mode 100644 index 0000000000..c8d017122e --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java @@ -0,0 +1,27 @@ +package com.baeldung.logging.log4j2.tests; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ConsoleAppenderUsingPatternLayoutWithColorsTest { + + @Rule + public LoggerContextRule contextRule = new LoggerContextRule("log4j2-console-appender_pattern-layout.xml"); + + @Test + public void givenLoggerWithConsoleConfig_shouldLogToConsoleInColors() throws Exception { + Logger logger = contextRule.getLogger(getClass().getSimpleName()); + logger.trace("This is a colored message at TRACE level. This is the minimum visible level."); + logger.debug("This is a colored message at DEBUG level."); + logger.info("This is a colored message at INFO level."); + logger.warn("This is a colored message at WARN level."); + Exception e = new RuntimeException("This is only a test!"); + logger.error("This is a colored message at ERROR level.", e); + logger.fatal("This is a colored message at FATAL level."); + } +} diff --git a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout_colored.xml b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout_colored.xml new file mode 100644 index 0000000000..74767cfb0d --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout_colored.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml new file mode 100644 index 0000000000..2c6f6a1ed0 --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml b/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml new file mode 100644 index 0000000000..02f75be4de --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml @@ -0,0 +1,4 @@ + + + + diff --git a/logging/log4j2/src/test/resources/log4j2.xml b/logging/log4j2/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..3f214e230a --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/logging/pom.xml b/logging/pom.xml new file mode 100644 index 0000000000..535c9e1c54 --- /dev/null +++ b/logging/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + com.baeldung.logging + logging + 1.0.0-SNAPSHOT + + log4j2 + + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + UTF-8 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + + From b86dd316bb7cc920c96909e939152daeb3bf266f Mon Sep 17 00:00:00 2001 From: oreva Date: Sun, 18 Sep 2016 20:47:55 +0300 Subject: [PATCH 10/86] README.md file added. --- spring-mvc-email/README.md | 13 +++++++++++++ spring-mvc-email/readme.txt | 6 ------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 spring-mvc-email/README.md delete mode 100644 spring-mvc-email/readme.txt diff --git a/spring-mvc-email/README.md b/spring-mvc-email/README.md new file mode 100644 index 0000000000..0de6532393 --- /dev/null +++ b/spring-mvc-email/README.md @@ -0,0 +1,13 @@ +## Spring MVC Email + +Example Spring MVC project to send email from web form. + +### Installing and Running + +Just run the Spring Boot application. +Type http://localhost:8080 in your browser to open the application. + + +### Sending test emails + +Follow UI links to send simple email, email using template or email with attachment. \ No newline at end of file diff --git a/spring-mvc-email/readme.txt b/spring-mvc-email/readme.txt deleted file mode 100644 index 24ff5438d7..0000000000 --- a/spring-mvc-email/readme.txt +++ /dev/null @@ -1,6 +0,0 @@ -You can send test email in several ways: -First of all, you should set application.properties properly. -1. Just build the project and the test email for order confirmation will be sent on Spring Boot Start. -2. You can use the web form and test all the cases of sending email in your browser. -Just start the application then type http://localhost:8080 and follow the web flow. -You can send simple email, email with template, email with attachment from the web. \ No newline at end of file From 2f4ac59c54966294d01756446cff09e6170a03b0 Mon Sep 17 00:00:00 2001 From: oreva Date: Sun, 18 Sep 2016 20:53:09 +0300 Subject: [PATCH 11/86] Unused imports removed; Application filed cleaned up from the logic of sending email on startup. --- .../java/com/baeldung/spring/Application.java | 21 ------------------- .../baeldung/spring/app/config/AppConfig.java | 4 +++- .../spring/controllers/HomeController.java | 2 -- .../spring/mail/EmailServiceImpl.java | 3 --- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java index 7d92c2964a..f146ee1d04 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/Application.java @@ -1,33 +1,12 @@ package com.baeldung.spring; -import com.baeldung.spring.mail.EmailService; -import com.baeldung.spring.mail.EmailServiceImpl; -import com.baeldung.spring.mail.Order; -import com.baeldung.spring.mail.OrderManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.support.SpringBootServletInitializer; -import org.springframework.context.annotation.ImportResource; -import org.springframework.mail.SimpleMailMessage; -import javax.annotation.PostConstruct; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } - - @Autowired - public EmailService emailService; - - @Autowired - public OrderManager orderManager; - - @PostConstruct - public void postConstruct() { - Order order = new Order("user_email_address", "First Name", "Last Name"); - orderManager.placeOrder(order); - } } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java index 4fb684c2b6..9f8339c2fe 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java @@ -4,7 +4,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.mail.SimpleMailMessage; -import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.UrlBasedViewResolver; diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java index 50643684d1..656e237a9e 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/controllers/HomeController.java @@ -3,8 +3,6 @@ package com.baeldung.spring.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.ModelAndView; /** * Created with IntelliJ IDEA. diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java index 8ecde598f9..dab5400d25 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java @@ -1,15 +1,12 @@ package com.baeldung.spring.mail; -import com.baeldung.spring.web.dto.MailObject; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.core.io.FileSystemResource; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; From b5c4200ca1ba71b7e43da98ec7f2ef2cf7513678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Sun, 25 Sep 2016 08:24:29 +0200 Subject: [PATCH 12/86] BAEL-41: Added failover appender. --- .../FailoverSyslogConsoleAppenderTest.java | 28 +++++++++++++++++++ ...syslog-console-appender_pattern-layout.xml | 20 +++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java create mode 100644 logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java new file mode 100644 index 0000000000..72d32d76fb --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java @@ -0,0 +1,28 @@ +package com.baeldung.logging.log4j2.tests; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class FailoverSyslogConsoleAppenderTest { + + @Rule + public LoggerContextRule contextRule = + new LoggerContextRule("log4j2-failover-syslog-console-appender_pattern-layout.xml"); + + @Test + public void givenLoggerWithFailoverConfig_shouldLog() throws Exception { + Logger logger = contextRule.getLogger(getClass().getSimpleName()); + logger.trace("This is a syslog message at TRACE level."); + logger.debug("This is a syslog message at DEBUG level."); + logger.info("This is a syslog message at INFO level. This is the minimum visible level."); + logger.warn("This is a syslog message at WARN level."); + Exception e = new RuntimeException("This is only a test!"); + logger.error("This is a syslog message at ERROR level.", e); + logger.fatal("This is a syslog message at FATAL level."); + } +} diff --git a/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml b/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml new file mode 100644 index 0000000000..efb4516489 --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + From a929225e1345ba4563240b4efb90cb934510d35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Sun, 2 Oct 2016 20:50:41 +0200 Subject: [PATCH 13/86] BAEL-41: Added including tests: - rolling file appender using XML layout - async file appender using JSON layout --- logging/log4j2/pom.xml | 7 ++++ .../AsyncFileAppenderUsingJsonLayoutTest.java | 20 ++--------- ...RollingFileAppenderUsingXMLLayoutTest.java | 34 +++++++++++++++++++ ...og4j2-async-file-appender_json-layout.xml} | 0 ...og4j2-rolling-file-appender_xml-layout.xml | 17 ++++++++++ 5 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java rename logging/log4j2/src/test/resources/{log4j2-async-file-appender_json-layout_colored.xml => log4j2-async-file-appender_json-layout.xml} (100%) create mode 100644 logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml diff --git a/logging/log4j2/pom.xml b/logging/log4j2/pom.xml index 537427e232..01cdfc5872 100644 --- a/logging/log4j2/pom.xml +++ b/logging/log4j2/pom.xml @@ -31,6 +31,13 @@ 2.8.2 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.8.2 + + org.apache.logging.log4j diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java index c9ce0c2828..1006b38b14 100644 --- a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java @@ -1,19 +1,14 @@ package com.baeldung.logging.log4j2.tests; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.junit.LoggerContextRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.List; -import java.util.stream.Collectors; import static org.junit.Assert.assertTrue; @@ -21,7 +16,7 @@ import static org.junit.Assert.assertTrue; public class AsyncFileAppenderUsingJsonLayoutTest { @Rule - public LoggerContextRule contextRule = new LoggerContextRule("log4j2-async-file-appender_json-layout_colored.xml"); + public LoggerContextRule contextRule = new LoggerContextRule("log4j2-async-file-appender_json-layout.xml"); @Test public void givenLoggerWithAsyncConfig_shouldLogToJsonFile() throws Exception { @@ -30,16 +25,7 @@ public class AsyncFileAppenderUsingJsonLayoutTest { for (int i = 0; i < count; i++) { logger.info("This is async JSON message #{} at INFO level.", count); } - ObjectMapper objectMapper = new ObjectMapper(); - List logEvents = Files.readAllLines(Paths.get("target/logfile.json")).stream() - .map(s -> { - try { - return objectMapper.readValue(s.getBytes(), LogEvent.class); - } catch (IOException e) { - throw new RuntimeException("Failed to import LogEvent!", e); - } - }) - .collect(Collectors.toList()); - assertTrue(logEvents.size() <= count); + long logEventsCount = Files.lines(Paths.get("target/logfile.json")).count(); + assertTrue(logEventsCount == count); } } diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java new file mode 100644 index 0000000000..f455003b08 --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java @@ -0,0 +1,34 @@ +package com.baeldung.logging.log4j2.tests; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertTrue; + +@RunWith(JUnit4.class) +public class RollingFileAppenderUsingXMLLayoutTest { + + @Rule + public LoggerContextRule contextRule = new LoggerContextRule("log4j2-rolling-file-appender_xml-layout.xml"); + + @Test + public void givenLoggerWithRollingFileConfig_shouldLogToXMLFile() throws Exception { + Logger logger = contextRule.getLogger(getClass().getSimpleName()); + final int count = 88; + for (int i = 0; i < count; i++) { + logger.info("This is rolling file XML message #{} at INFO level.", count); + } + String[] logEvents = Files.readAllLines(Paths.get("target/logfile.xml")).stream() + .collect(Collectors.joining(System.lineSeparator())) + .split("\\n\\n+"); + assertTrue(logEvents.length == count); + } +} diff --git a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout_colored.xml b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout_colored.xml rename to logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml diff --git a/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml b/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml new file mode 100644 index 0000000000..8d47061a9e --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + From 0bd7a5d0ea944daeec8ab43d97fa1110c29864bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Mon, 3 Oct 2016 11:27:05 +0200 Subject: [PATCH 14/86] BAEL-41: Added including tests: - added JDBC appender. --- logging/log4j2/pom.xml | 12 +++++ .../log4j2/tests/JDBCAppenderTest.java | 52 +++++++++++++++++++ .../log4j2/tests/jdbc/ConnectionFactory.java | 25 +++++++++ ...log4j2-async-file-appender_json-layout.xml | 6 +-- ...log4j2-console-appender_pattern-layout.xml | 4 +- ...syslog-console-appender_pattern-layout.xml | 8 +-- ...onsole-appender_pattern-layout_colored.xml | 2 +- .../test/resources/log4j2-jdbc-appender.xml | 19 +++++++ ...og4j2-rolling-file-appender_xml-layout.xml | 7 +-- logging/log4j2/src/test/resources/log4j2.xml | 6 +-- 10 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java create mode 100644 logging/log4j2/src/test/resources/log4j2-jdbc-appender.xml diff --git a/logging/log4j2/pom.xml b/logging/log4j2/pom.xml index 01cdfc5872..d386836b6c 100644 --- a/logging/log4j2/pom.xml +++ b/logging/log4j2/pom.xml @@ -38,6 +38,18 @@ 2.8.2 + + + com.h2database + h2 + 1.4.192 + + + org.apache.commons + commons-dbcp2 + 2.1.1 + + org.apache.logging.log4j diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java new file mode 100644 index 0000000000..2ceda2083b --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java @@ -0,0 +1,52 @@ +package com.baeldung.logging.log4j2.tests; + +import com.baeldung.logging.log4j2.tests.jdbc.ConnectionFactory; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.sql.Connection; +import java.sql.ResultSet; + +import static org.junit.Assert.assertTrue; + +@RunWith(JUnit4.class) +public class JDBCAppenderTest { + + @Rule + public LoggerContextRule contextRule = new LoggerContextRule("log4j2-jdbc-appender.xml"); + + @BeforeClass + public static void setup() throws Exception { + Connection connection = ConnectionFactory.getConnection(); + connection.createStatement() + .execute("CREATE TABLE logs(" + + "when TIMESTAMP," + + "logger VARCHAR(255)," + + "level VARCHAR(255)," + + "message VARCHAR(4096)," + + "throwable TEXT)"); + //connection.commit(); + } + + @Test + public void givenLoggerWithJdbcConfig_shouldLogToDataSource() throws Exception { + Logger logger = contextRule.getLogger(getClass().getSimpleName()); + final int count = 88; + for (int i = 0; i < count; i++) { + logger.info("This is JDBC message #{} at INFO level.", count); + } + Connection connection = ConnectionFactory.getConnection(); + ResultSet resultSet = connection.createStatement() + .executeQuery("SELECT COUNT(*) AS ROW_COUNT FROM logs"); + int logCount = 0; + if (resultSet.next()) { + logCount = resultSet.getInt("ROW_COUNT"); + } + assertTrue(logCount == count); + } +} diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java new file mode 100644 index 0000000000..73b323f335 --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java @@ -0,0 +1,25 @@ +package com.baeldung.logging.log4j2.tests.jdbc; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.h2.Driver; + +import java.sql.Connection; +import java.sql.SQLException; + +public class ConnectionFactory { + private interface Singleton { + ConnectionFactory INSTANCE = new ConnectionFactory(); + } + + private BasicDataSource dataSource; + + private ConnectionFactory() { + dataSource = new BasicDataSource(); + dataSource.setDriver(new Driver()); + dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1"); + } + + public static Connection getConnection() throws SQLException { + return Singleton.INSTANCE.dataSource.getConnection(); + } +} diff --git a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml index 74767cfb0d..eb338dd496 100644 --- a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml @@ -4,13 +4,13 @@ - + - - + + diff --git a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml index 2c6f6a1ed0..4167fb9366 100644 --- a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml @@ -4,8 +4,8 @@ - - + + diff --git a/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml b/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml index efb4516489..62ba37f28c 100644 --- a/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml @@ -6,15 +6,15 @@ - + - + - - + + diff --git a/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml b/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml index 02f75be4de..c2b9c65430 100644 --- a/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml +++ b/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml @@ -1,4 +1,4 @@ - + diff --git a/logging/log4j2/src/test/resources/log4j2-jdbc-appender.xml b/logging/log4j2/src/test/resources/log4j2-jdbc-appender.xml new file mode 100644 index 0000000000..6b50f7d5a4 --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-jdbc-appender.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml b/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml index 8d47061a9e..059007f660 100644 --- a/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml @@ -1,7 +1,8 @@ - @@ -10,8 +11,8 @@ - - + + diff --git a/logging/log4j2/src/test/resources/log4j2.xml b/logging/log4j2/src/test/resources/log4j2.xml index 3f214e230a..8f7608aa78 100644 --- a/logging/log4j2/src/test/resources/log4j2.xml +++ b/logging/log4j2/src/test/resources/log4j2.xml @@ -1,13 +1,13 @@ - + - - + + From 8bab22bdca7b6178b1d2802e7c780eba9e1593aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Mon, 3 Oct 2016 13:07:45 +0200 Subject: [PATCH 15/86] BAEL-41: Added including tests: - burst filter --- .../AsyncFileAppenderUsingJsonLayoutTest.java | 2 +- ...derUsingJsonLayoutWithBurstFilterTest.java | 33 +++++++++++++++++++ ...log4j2-async-file-appender_json-layout.xml | 4 +-- ...file-appender_json-layout_burst-filter.xml | 14 ++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java create mode 100644 logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java index 1006b38b14..db3a4d2458 100644 --- a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java @@ -26,6 +26,6 @@ public class AsyncFileAppenderUsingJsonLayoutTest { logger.info("This is async JSON message #{} at INFO level.", count); } long logEventsCount = Files.lines(Paths.get("target/logfile.json")).count(); - assertTrue(logEventsCount == count); + assertTrue(logEventsCount > 0 && logEventsCount <= count); } } diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java new file mode 100644 index 0000000000..4ff22c821b --- /dev/null +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java @@ -0,0 +1,33 @@ +package com.baeldung.logging.log4j2.tests; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; + +@RunWith(JUnit4.class) +public class FileAppenderUsingJsonLayoutWithBurstFilterTest { + + @Rule + public LoggerContextRule contextRule = new LoggerContextRule("log4j2-file-appender_json-layout_burst-filter.xml"); + + @Test + public void givenLoggerWithBurstFileConfig_shouldLogToJsonFile() throws Exception { + Logger logger = contextRule.getLogger(getClass().getSimpleName()); + final int count = 88; + for (int i = 0; i < count; i++) { + logger.info("This is burst JSON message #{} at INFO level.", count); + TimeUnit.MILLISECONDS.sleep(100); + } + long logEventsCount = Files.lines(Paths.get("target/logfile-burst.json")).count(); + assertTrue(logEventsCount > 0 && logEventsCount < count); + } +} diff --git a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml index eb338dd496..695399ca66 100644 --- a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml @@ -1,11 +1,11 @@ - + - + diff --git a/logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml b/logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml new file mode 100644 index 0000000000..edadcbaecb --- /dev/null +++ b/logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + From b04ede30f5da9f7adf9d8fbe7483eb1c21108250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Mon, 3 Oct 2016 22:28:16 +0200 Subject: [PATCH 16/86] BAEL-41: Added including tests: - marker filter --- ...enderUsingPatternLayoutWithColorsTest.java | 15 +++++++-- ...derUsingJsonLayoutWithBurstFilterTest.java | 33 ------------------- ...log4j2-async-file-appender_json-layout.xml | 1 + ...log4j2-console-appender_pattern-layout.xml | 9 ++++- ...file-appender_json-layout_burst-filter.xml | 14 -------- 5 files changed, 22 insertions(+), 50 deletions(-) delete mode 100644 logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java delete mode 100644 logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java index c8d017122e..635e05c841 100644 --- a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java @@ -1,6 +1,8 @@ package com.baeldung.logging.log4j2.tests; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; import org.apache.logging.log4j.junit.LoggerContextRule; import org.junit.Rule; import org.junit.Test; @@ -16,12 +18,21 @@ public class ConsoleAppenderUsingPatternLayoutWithColorsTest { @Test public void givenLoggerWithConsoleConfig_shouldLogToConsoleInColors() throws Exception { Logger logger = contextRule.getLogger(getClass().getSimpleName()); - logger.trace("This is a colored message at TRACE level. This is the minimum visible level."); - logger.debug("This is a colored message at DEBUG level."); + logger.trace("This is a colored message at TRACE level."); + logger.debug("This is a colored message at DEBUG level. This is the minimum visible level."); logger.info("This is a colored message at INFO level."); logger.warn("This is a colored message at WARN level."); Exception e = new RuntimeException("This is only a test!"); logger.error("This is a colored message at ERROR level.", e); logger.fatal("This is a colored message at FATAL level."); } + + @Test + public void givenLoggerWithConsoleConfig_shouldFilterByMarker() throws Exception { + Logger logger = contextRule.getLogger("ConnTrace"); + Marker appError = MarkerManager.getMarker("APP_ERROR"); + logger.error(appError, "This marker message at ERROR level should be hidden."); + Marker connectionTrace = MarkerManager.getMarker("CONN_TRACE"); + logger.trace(connectionTrace, "This is a marker message at TRACE level."); + } } diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java deleted file mode 100644 index 4ff22c821b..0000000000 --- a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FileAppenderUsingJsonLayoutWithBurstFilterTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.logging.log4j2.tests; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.junit.LoggerContextRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertTrue; - -@RunWith(JUnit4.class) -public class FileAppenderUsingJsonLayoutWithBurstFilterTest { - - @Rule - public LoggerContextRule contextRule = new LoggerContextRule("log4j2-file-appender_json-layout_burst-filter.xml"); - - @Test - public void givenLoggerWithBurstFileConfig_shouldLogToJsonFile() throws Exception { - Logger logger = contextRule.getLogger(getClass().getSimpleName()); - final int count = 88; - for (int i = 0; i < count; i++) { - logger.info("This is burst JSON message #{} at INFO level.", count); - TimeUnit.MILLISECONDS.sleep(100); - } - long logEventsCount = Files.lines(Paths.get("target/logfile-burst.json")).count(); - assertTrue(logEventsCount > 0 && logEventsCount < count); - } -} diff --git a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml index 695399ca66..c291eacd59 100644 --- a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml @@ -3,6 +3,7 @@ + diff --git a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml index 4167fb9366..9cd3ccea50 100644 --- a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml @@ -2,9 +2,16 @@ + + + + - + + + + diff --git a/logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml b/logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml deleted file mode 100644 index edadcbaecb..0000000000 --- a/logging/log4j2/src/test/resources/log4j2-file-appender_json-layout_burst-filter.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - From cf335e30a4af3bdf59db07eb3cb25accf309240a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Tue, 4 Oct 2016 02:28:27 +0200 Subject: [PATCH 17/86] BAEL-41: Added including tests: - thread context filter and pattern --- ...nsoleAppenderUsingPatternLayoutWithColorsTest.java | 11 +++++++++++ .../log4j2-console-appender_pattern-layout.xml | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java index 635e05c841..1e16ba7d0b 100644 --- a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java +++ b/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java @@ -3,6 +3,7 @@ package com.baeldung.logging.log4j2.tests; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; +import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.junit.LoggerContextRule; import org.junit.Rule; import org.junit.Test; @@ -35,4 +36,14 @@ public class ConsoleAppenderUsingPatternLayoutWithColorsTest { Marker connectionTrace = MarkerManager.getMarker("CONN_TRACE"); logger.trace(connectionTrace, "This is a marker message at TRACE level."); } + + @Test + public void givenLoggerWithConsoleConfig_shouldFilterByThreadContext() throws Exception { + Logger logger = contextRule.getLogger("UserAudit"); + ThreadContext.put("userId", "1000"); + logger.info("This is a log-visible user login. Maybe from an admin account?"); + ThreadContext.put("userId", "1001"); + logger.info("This is a log-invisible user login."); + boolean b = true; + } } diff --git a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml index 9cd3ccea50..d6621f9166 100644 --- a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml +++ b/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml @@ -6,11 +6,20 @@ + + + + + + + + + From 309e1a2da75e769bd2ff5bb9ec747e55bc2ac581 Mon Sep 17 00:00:00 2001 From: oreva Date: Thu, 6 Oct 2016 12:53:00 +0300 Subject: [PATCH 18/86] Options to send different types of emails were moved to the home page. --- .../spring/controllers/MailController.java | 2 +- .../src/main/webapp/WEB-INF/views/home.jsp | 24 ++++++++++++++++--- .../main/webapp/WEB-INF/views/mail/send.jsp | 4 +--- 3 files changed, 23 insertions(+), 7 deletions(-) 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 832a60ba5d..1f536e3297 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 @@ -31,7 +31,7 @@ public class MailController { @Qualifier("templateSimpleMessage") public SimpleMailMessage template; - @RequestMapping(value = "/send", method = RequestMethod.GET) + @RequestMapping(value = {"/send", "/sendTemplate", "/sendAttachment"}, method = RequestMethod.GET) public String createMail(Model model) { model.addAttribute("mailObject", new MailObject()); return "mail/send"; diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp b/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp index 74165f2626..63351bbf3a 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp +++ b/spring-mvc-email/src/main/webapp/WEB-INF/views/home.jsp @@ -15,9 +15,27 @@
-

Send Email

-
- +

Select any of the options below to send sample email:

+ +
+ + + + + + + + + + +
+ +
+ +
+ +
+
diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp index 1307fc2baf..294cb2c49c 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp +++ b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp @@ -43,9 +43,7 @@ - - - + From 2892e9347673c2e47b0930f0f6c89558c806c833 Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Wed, 19 Oct 2016 11:01:40 +0200 Subject: [PATCH 19/86] Code improvement --- .../baeldung/okhttp/OkHttpGetLiveTest.java | 3 ++ .../baeldung/okhttp/OkHttpMiscLiveTest.java | 28 +++++++------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java index 9a49c8d9a2..dc80ce7cf5 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java @@ -14,6 +14,9 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; +//@RunWith(SpringJUnit4ClassRunner.class) +//@WebAppConfiguration +//@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/api-servlet.xml") public class OkHttpGetLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java index c44500f4be..dcdb4e328c 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java @@ -37,7 +37,7 @@ public class OkHttpMiscLiveTest { response.close(); } - @Test + @Test(expected = IOException.class) public void whenCancelRequest_thenCorrect() throws IOException { ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); @@ -49,30 +49,22 @@ public class OkHttpMiscLiveTest { .build(); final int seconds = 1; - final long startNanos = System.nanoTime(); + final Call call = client.newCall(request); // Schedule a job to cancel the call in 1 second. - executor.schedule(new Runnable() { - public void run() { + executor.schedule(() -> { + + logger.debug("Canceling call: " + (System.nanoTime() - startNanos) / 1e9f); + call.cancel(); + logger.debug("Canceled call: " + (System.nanoTime() - startNanos) / 1e9f); - logger.debug("Canceling call: " + (System.nanoTime() - startNanos) / 1e9f); - call.cancel(); - logger.debug("Canceled call: " + (System.nanoTime() - startNanos) / 1e9f); - } }, seconds, TimeUnit.SECONDS); - try { - - logger.debug("Executing call: " + (System.nanoTime() - startNanos) / 1e9f); - Response response = call.execute(); - logger.debug("Call was expected to fail, but completed: " + (System.nanoTime() - startNanos) / 1e9f, response); - - } catch (IOException e) { - - logger.debug("Call failed as expected: " + (System.nanoTime() - startNanos) / 1e9f, e); - } + logger.debug("Executing call: " + (System.nanoTime() - startNanos) / 1e9f); + Response response = call.execute(); + logger.debug("Call completed: " + (System.nanoTime() - startNanos) / 1e9f, response); } @Test From 35dbb1cfb0206f2c518597b52a77c13c2ba3b6ea Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Wed, 19 Oct 2016 12:18:03 +0200 Subject: [PATCH 20/86] Code improvement --- .../java/org/baeldung/okhttp/OkHttpGetLiveTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java index dc80ce7cf5..8049e23784 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java @@ -2,6 +2,7 @@ package org.baeldung.okhttp; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.io.IOException; @@ -21,7 +22,7 @@ public class OkHttpGetLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; - @Test + //@Test public void whenGetRequest_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -36,7 +37,7 @@ public class OkHttpGetLiveTest { assertThat(response.code(), equalTo(200)); } - @Test + //@Test public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -57,7 +58,7 @@ public class OkHttpGetLiveTest { } @Test - public void whenAsynchronousGetRequest_thenCorrect() { + public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException { OkHttpClient client = new OkHttpClient(); @@ -70,12 +71,16 @@ public class OkHttpGetLiveTest { call.enqueue(new Callback() { public void onResponse(Call call, Response response) throws IOException { + assertThat(response.code(), equalTo(200)); } public void onFailure(Call call, IOException e) { + fail(); } }); + + Thread.sleep(3000); } } From 91faa251d51a76cff2451c19ec6404166446bae4 Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Wed, 19 Oct 2016 12:23:03 +0200 Subject: [PATCH 21/86] Code improvement --- .../test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java index 8049e23784..632d7577a4 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java @@ -22,7 +22,7 @@ public class OkHttpGetLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; - //@Test + @Test public void whenGetRequest_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -37,7 +37,7 @@ public class OkHttpGetLiveTest { assertThat(response.code(), equalTo(200)); } - //@Test + @Test public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -71,12 +71,10 @@ public class OkHttpGetLiveTest { call.enqueue(new Callback() { public void onResponse(Call call, Response response) throws IOException { - assertThat(response.code(), equalTo(200)); } public void onFailure(Call call, IOException e) { - fail(); } }); From 13f7d5dfdf01d45807b5568b54758af785bb4c2c Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Fri, 28 Oct 2016 22:26:56 +0530 Subject: [PATCH 22/86] Updating the Selenium version --- selenium-junit-testng/pom.xml | 2 +- .../java/com/baeldung/selenium/SeleniumExample.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml index 861c0b1986..cc96ea8529 100644 --- a/selenium-junit-testng/pom.xml +++ b/selenium-junit-testng/pom.xml @@ -53,7 +53,7 @@ org.seleniumhq.selenium selenium-java - 2.53.1 + 3.0.1 junit 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 ce60a1f638..58d47c0162 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 @@ -15,6 +15,7 @@ public class SeleniumExample { private String url = "http://www.baeldung.com/"; public SeleniumExample() { + System.setProperty("webdriver.firefox.marionette", "C:\\selenium\\geckodriver.exe"); webDriver = new FirefoxDriver(); webDriver.manage().window().maximize(); webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); @@ -29,16 +30,20 @@ public class SeleniumExample { return webDriver.getTitle(); } - public void getAboutBaeldungPage() throws Exception { + public void getAboutBaeldungPage() { closeOverlay(); clickAboutLink(); clickAboutUsLink(); } - private void closeOverlay() throws Exception { + private void closeOverlay() { List webElementList = webDriver.findElements(By.tagName("a")); - if (webElementList != null && !webElementList.isEmpty() && webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().isPresent()) { - webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click(); + 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(); } } From 1646eb9813c3b4f6e0e52f26c39f7591d0205aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Fri, 28 Oct 2016 21:04:41 +0200 Subject: [PATCH 23/86] BAEL-41: Moved module location. --- {logging/log4j2 => log4j2}/pom.xml | 32 ++++++++------- .../AsyncFileAppenderUsingJsonLayoutTest.java | 0 ...ConsoleAppenderUsingDefaultLayoutTest.java | 0 ...enderUsingPatternLayoutWithColorsTest.java | 0 .../FailoverSyslogConsoleAppenderTest.java | 0 .../log4j2/tests/JDBCAppenderTest.java | 0 ...RollingFileAppenderUsingXMLLayoutTest.java | 2 +- .../log4j2/tests/jdbc/ConnectionFactory.java | 0 ...log4j2-async-file-appender_json-layout.xml | 0 ...log4j2-console-appender_pattern-layout.xml | 0 ...syslog-console-appender_pattern-layout.xml | 0 ...onsole-appender_pattern-layout_colored.xml | 0 .../test/resources/log4j2-jdbc-appender.xml | 0 ...og4j2-rolling-file-appender_xml-layout.xml | 0 .../src/test/resources/log4j2.xml | 0 logging/pom.xml | 40 ------------------- 16 files changed, 18 insertions(+), 56 deletions(-) rename {logging/log4j2 => log4j2}/pom.xml (80%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java (100%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java (100%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java (100%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java (100%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java (100%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java (98%) rename {logging/log4j2 => log4j2}/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2-async-file-appender_json-layout.xml (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2-console-appender_pattern-layout.xml (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2-jdbc-appender.xml (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml (100%) rename {logging/log4j2 => log4j2}/src/test/resources/log4j2.xml (100%) delete mode 100644 logging/pom.xml diff --git a/logging/log4j2/pom.xml b/log4j2/pom.xml similarity index 80% rename from logging/log4j2/pom.xml rename to log4j2/pom.xml index d386836b6c..83904f2075 100644 --- a/logging/log4j2/pom.xml +++ b/log4j2/pom.xml @@ -2,40 +2,37 @@ - - logging - com.baeldung.logging - 1.0.0-SNAPSHOT - 4.0.0 log4j2 + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + - - - org.apache.logging.log4j - log4j-api - 2.6.2 - + org.apache.logging.log4j log4j-core - 2.6.2 + 2.7 com.fasterxml.jackson.core jackson-databind - 2.8.2 + 2.8.4 com.fasterxml.jackson.dataformat jackson-dataformat-xml - 2.8.2 + 2.8.4 @@ -54,7 +51,7 @@ org.apache.logging.log4j log4j-core - 2.6.2 + 2.7 test-jar test @@ -71,6 +68,11 @@ org.apache.maven.plugins maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java similarity index 100% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java similarity index 100% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java similarity index 100% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java similarity index 100% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java similarity index 100% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java similarity index 98% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java index f455003b08..2ebdccfc75 100644 --- a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java @@ -24,7 +24,7 @@ public class RollingFileAppenderUsingXMLLayoutTest { Logger logger = contextRule.getLogger(getClass().getSimpleName()); final int count = 88; for (int i = 0; i < count; i++) { - logger.info("This is rolling file XML message #{} at INFO level.", count); + logger.info("This is rolling file XML message #{} at INFO level.", i); } String[] logEvents = Files.readAllLines(Paths.get("target/logfile.xml")).stream() .collect(Collectors.joining(System.lineSeparator())) diff --git a/logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java similarity index 100% rename from logging/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java rename to log4j2/src/test/java/com/baeldung/logging/log4j2/tests/jdbc/ConnectionFactory.java diff --git a/logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml b/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml rename to log4j2/src/test/resources/log4j2-async-file-appender_json-layout.xml diff --git a/logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml b/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml rename to log4j2/src/test/resources/log4j2-console-appender_pattern-layout.xml diff --git a/logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml b/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml rename to log4j2/src/test/resources/log4j2-failover-syslog-console-appender_pattern-layout.xml diff --git a/logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml b/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml rename to log4j2/src/test/resources/log4j2-includes/console-appender_pattern-layout_colored.xml diff --git a/logging/log4j2/src/test/resources/log4j2-jdbc-appender.xml b/log4j2/src/test/resources/log4j2-jdbc-appender.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-jdbc-appender.xml rename to log4j2/src/test/resources/log4j2-jdbc-appender.xml diff --git a/logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml b/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml rename to log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml diff --git a/logging/log4j2/src/test/resources/log4j2.xml b/log4j2/src/test/resources/log4j2.xml similarity index 100% rename from logging/log4j2/src/test/resources/log4j2.xml rename to log4j2/src/test/resources/log4j2.xml diff --git a/logging/pom.xml b/logging/pom.xml deleted file mode 100644 index 535c9e1c54..0000000000 --- a/logging/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - 4.0.0 - - com.baeldung.logging - logging - 1.0.0-SNAPSHOT - - log4j2 - - pom - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - .. - - - - UTF-8 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.8 - 1.8 - - - - - - From 771a81d5bd3a409c00279e8acddcdf9535fde3a9 Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 29 Oct 2016 21:46:34 +0800 Subject: [PATCH 24/86] Spring Data Solr project created --- spring-data-solr/pom.xml | 78 ++++++++++++ .../spring/data/solr/config/SolrConfig.java | 25 ++++ .../spring/data/solr/model/Product.java | 62 ++++++++++ .../solr/repository/ProductRepository.java | 24 ++++ .../resources/solr-named-queries.properties | 1 + .../ProductRepositoryIntegrationTest.java | 117 ++++++++++++++++++ 6 files changed, 307 insertions(+) create mode 100644 spring-data-solr/pom.xml create mode 100644 spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java create mode 100644 spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java create mode 100644 spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java create mode 100644 spring-data-solr/src/main/resources/solr-named-queries.properties create mode 100644 spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml new file mode 100644 index 0000000000..9ec017e376 --- /dev/null +++ b/spring-data-solr/pom.xml @@ -0,0 +1,78 @@ + + 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 + spring-core + ${spring.version} + + + + org.springframework.data + spring-data-solr + ${spring-data-solr} + + + + + org.springframework + spring-context + ${spring.version} + + + + + log4j + log4j + 1.2.16 + + + + + junit + junit + 4.12 + test + + + + org.springframework + spring-test + ${spring.version} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + + + + + + diff --git a/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java new file mode 100644 index 0000000000..1fe1e5468b --- /dev/null +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java @@ -0,0 +1,25 @@ +package com.baeldung.spring.data.solr.config; + +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.solr.core.SolrTemplate; +import org.springframework.data.solr.repository.config.EnableSolrRepositories; + +@Configuration +@EnableSolrRepositories(basePackages = "com.baeldung.spring.data.solr.repository", namedQueriesLocation = "classpath:solr-named-queries.properties", multicoreSupport = true) +@ComponentScan +public class SolrConfig { + + @Bean + public SolrClient solrClient() { + return new HttpSolrClient("http://localhost:8983/solr"); + } + + @Bean + public SolrTemplate solrTemplate(SolrClient client) throws Exception { + return new SolrTemplate(client); + } +} 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 new file mode 100644 index 0000000000..2c16a2cdbf --- /dev/null +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/model/Product.java @@ -0,0 +1,62 @@ +package com.baeldung.spring.data.solr.model; + +import org.apache.solr.client.solrj.beans.Field; +import org.springframework.data.annotation.Id; +import org.springframework.data.solr.core.mapping.SolrDocument; + +@SolrDocument(solrCoreName="product") +public class Product { + + @Id + @Field("id") + private String id; + + @Field("name") + private String name; + + @Field("category") + private String category; + + @Field("description") + private String description; + + + public Product(String id,String name,String category){ + this.id = id; + this.name = name; + this.category = category; + } + + 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 new file mode 100644 index 0000000000..1f57816dd6 --- /dev/null +++ b/spring-data-solr/src/main/java/com/baeldung/spring/data/solr/repository/ProductRepository.java @@ -0,0 +1,24 @@ +package com.baeldung.spring.data.solr.repository; + + +import java.util.List; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.solr.repository.Query; +import org.springframework.data.solr.repository.SolrCrudRepository; + +import com.baeldung.spring.data.solr.model.Product; + +public interface ProductRepository extends SolrCrudRepository{ + + public List findByName(String name); + + @Query("name:*?0* OR category:*?0* OR description:*?0*") + public Page findByCustomQuery(String searchTerm,Pageable pageable); + + + // @Query(name="Product.findByNamedQuery") + public Page findByNamedQuery(String searchTerm,Pageable pageable); + +} diff --git a/spring-data-solr/src/main/resources/solr-named-queries.properties b/spring-data-solr/src/main/resources/solr-named-queries.properties new file mode 100644 index 0000000000..cec59cbebd --- /dev/null +++ b/spring-data-solr/src/main/resources/solr-named-queries.properties @@ -0,0 +1 @@ +Product.findByNamedQuery=name:*?0* OR category:*?0* OR description:*?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 new file mode 100644 index 0000000000..52a1a2837d --- /dev/null +++ b/spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java @@ -0,0 +1,117 @@ +package com.baeldung.spring.data.solr.repo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.spring.data.solr.config.SolrConfig; +import com.baeldung.spring.data.solr.model.Product; +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("P00001","Desk","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("P0001", "T-Shirt","Kitchen"); + product.setDescription("New T-Shirt"); + productRepository.save(product); + + product.setCategory("Clothes"); + productRepository.save(product); + + final Product retrievedProduct = productRepository.findOne(product.getId()); + assertEquals(product.getCategory(), retrievedProduct.getCategory()); + } + + + + @Test + public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { + final Product product = new Product("P0001", "Desk","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{ + final Product phone = new Product("P0001", "Phone", "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("P0001", "Smart Phone", "Electronics"); + phone.setDescription("New Item"); + productRepository.save(phone); + + final Product phoneCover = new Product("P0002", "Cover", "Phone"); + phoneCover.setDescription("New Product"); + productRepository.save(phoneCover); + + final Product wirelessCharger = new Product("P0003", "Charging Cable", "Cable"); + wirelessCharger.setDescription("Wireless Charger for Phone"); + productRepository.save(wirelessCharger); + + Page result = productRepository.findByCustomQuery("Pho", new PageRequest(0, 10)); + assertEquals(3, result.getNumberOfElements()); + } + + @Test + public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception { + final Product phone = new Product("P0001", "Smart Phone", "Electronics"); + phone.setDescription("New Item"); + productRepository.save(phone); + + final Product phoneCover = new Product("P0002", "Cover", "Phone"); + phoneCover.setDescription("New Product"); + productRepository.save(phoneCover); + + final Product wirelessCharger = new Product("P0003", "Charging Cable", "Cable"); + wirelessCharger.setDescription("Wireless Charger for Phone"); + productRepository.save(wirelessCharger); + + Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); + assertEquals(3, result.getNumberOfElements()); + } + +} From 74fccfb5247345dce41afe29cec3cbcb632a0061 Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 29 Oct 2016 21:51:11 +0800 Subject: [PATCH 25/86] pom.xml format changed --- spring-data-solr/pom.xml | 79 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml index 9ec017e376..437bc2b277 100644 --- a/spring-data-solr/pom.xml +++ b/spring-data-solr/pom.xml @@ -1,37 +1,36 @@ - 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 - spring-core - ${spring.version} - - - - org.springframework.data - spring-data-solr - ${spring-data-solr} - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + 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 + spring-core + ${spring.version} + + + + org.springframework.data + spring-data-solr + ${spring-data-solr} + + + org.springframework spring-context @@ -45,24 +44,25 @@ 1.2.16 - + junit junit 4.12 test - + org.springframework spring-test ${spring.version} test - - - - + + + + + org.apache.maven.plugins maven-surefire-plugin @@ -75,4 +75,5 @@ + From 5876c981aa16a764f9390048ef1eb5304f5c534c Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 29 Oct 2016 21:53:04 +0800 Subject: [PATCH 26/86] pom.xml format changed --- spring-data-solr/pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml index 437bc2b277..bd48a53d06 100644 --- a/spring-data-solr/pom.xml +++ b/spring-data-solr/pom.xml @@ -17,48 +17,38 @@
- org.springframework spring-core ${spring.version} - org.springframework.data spring-data-solr ${spring-data-solr} - - org.springframework spring-context ${spring.version} - - log4j log4j 1.2.16 - - junit junit 4.12 test - org.springframework spring-test ${spring.version} test - From d9eeb7c21a921a2a806fa0cd3f9fb23a956ef130 Mon Sep 17 00:00:00 2001 From: mujah Date: Sun, 30 Oct 2016 17:03:26 +0800 Subject: [PATCH 27/86] spring-data-solr module added --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 95182ab63c..182b2d5147 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,7 @@ spring-data-mongodb spring-data-redis spring-data-rest + spring-data-solr spring-exceptions spring-freemarker From b3976c7fb59be85afb7ad1ff153b9b09346373e2 Mon Sep 17 00:00:00 2001 From: mujah Date: Sun, 30 Oct 2016 17:12:50 +0800 Subject: [PATCH 28/86] formatting format changes --- .../spring/data/solr/model/Product.java | 7 ++- .../solr/repository/ProductRepository.java | 18 ++++---- .../ProductRepositoryIntegrationTest.java | 45 +++++++++---------- 3 files changed, 32 insertions(+), 38 deletions(-) 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 2c16a2cdbf..d08640123a 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 @@ -4,7 +4,7 @@ import org.apache.solr.client.solrj.beans.Field; import org.springframework.data.annotation.Id; import org.springframework.data.solr.core.mapping.SolrDocument; -@SolrDocument(solrCoreName="product") +@SolrDocument(solrCoreName = "product") public class Product { @Id @@ -20,13 +20,12 @@ public class Product { @Field("description") private String description; - - public Product(String id,String name,String category){ + public Product(String id, String name, String category) { this.id = id; this.name = name; this.category = category; } - + public String getId() { return id; } 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 1f57816dd6..01ec1fb909 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 @@ -1,6 +1,5 @@ package com.baeldung.spring.data.solr.repository; - import java.util.List; import org.springframework.data.domain.Page; @@ -10,15 +9,14 @@ import org.springframework.data.solr.repository.SolrCrudRepository; import com.baeldung.spring.data.solr.model.Product; -public interface ProductRepository extends SolrCrudRepository{ - +public interface ProductRepository extends SolrCrudRepository { + public List findByName(String name); - + @Query("name:*?0* OR category:*?0* OR description:*?0*") - public Page findByCustomQuery(String searchTerm,Pageable pageable); - - - // @Query(name="Product.findByNamedQuery") - public Page findByNamedQuery(String searchTerm,Pageable pageable); - + public Page findByCustomQuery(String searchTerm, Pageable pageable); + + @Query(name = "Product.findByNamedQuery") + public Page findByNamedQuery(String searchTerm, Pageable pageable); + } 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 52a1a2837d..b55e65e04a 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 @@ -18,59 +18,56 @@ import com.baeldung.spring.data.solr.config.SolrConfig; import com.baeldung.spring.data.solr.model.Product; 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(){ + public void clearSolrData() { productRepository.deleteAll(); } - + @Test - public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception{ - final Product product = new Product("P00001","Desk","Furniture"); + public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception { + final Product product = new Product("P00001", "Desk", "Furniture"); product.setDescription("New Desk"); productRepository.save(product); final Product retrievedProduct = productRepository.findOne(product.getId()); - assertEquals(product.getId(),retrievedProduct.getId()); + assertEquals(product.getId(), retrievedProduct.getId()); } - + @Test public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception { - final Product product = new Product("P0001", "T-Shirt","Kitchen"); + final Product product = new Product("P0001", "T-Shirt", "Kitchen"); product.setDescription("New T-Shirt"); productRepository.save(product); - + product.setCategory("Clothes"); productRepository.save(product); - + final Product retrievedProduct = productRepository.findOne(product.getId()); assertEquals(product.getCategory(), retrievedProduct.getCategory()); } - - - + @Test public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { - final Product product = new Product("P0001", "Desk","Furniture"); + final Product product = new Product("P0001", "Desk", "Furniture"); product.setDescription("New Desk"); productRepository.save(product); - + productRepository.delete(product); - - Product retrievedProduct = productRepository.findOne(product.getId()); + + Product retrievedProduct = productRepository.findOne(product.getId()); assertNull(retrievedProduct); - + } - + @Test - public void whenFindByName_thenAvailableOnRetrieval() throws Exception{ - final Product phone = new Product("P0001", "Phone", "Electronics"); + public void whenFindByName_thenAvailableOnRetrieval() throws Exception { + Product phone = new Product("P0001", "Phone", "Electronics"); phone.setDescription("New Phone"); productRepository.save(phone); @@ -92,7 +89,7 @@ public class ProductRepositoryIntegrationTest { wirelessCharger.setDescription("Wireless Charger for Phone"); productRepository.save(wirelessCharger); - Page result = productRepository.findByCustomQuery("Pho", new PageRequest(0, 10)); + Page result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10)); assertEquals(3, result.getNumberOfElements()); } From 62de84bb5285f1f094837a8319e5d8b27e0a424e Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 31 Oct 2016 16:43:48 +0100 Subject: [PATCH 29/86] Log4J MDC, Log4J2 MDC samples added. --- log-mdc-ndc/README.md | 13 +++++++ log-mdc-ndc/pom.xml | 39 +++++++++++++++++++ .../com/baeldung/mdc/BusinessService.java | 7 ++++ .../com/baeldung/mdc/TransactionContext.java | 29 ++++++++++++++ .../mdc/log4j/Log4jBusinessService.java | 16 ++++++++ .../com/baeldung/mdc/log4j/Log4jDemo.java | 17 ++++++++ .../com/baeldung/mdc/log4j/Log4jExecutor.java | 23 +++++++++++ .../mdc/log4j2/Log4j2BusinessService.java | 19 +++++++++ .../com/baeldung/mdc/log4j2/Log4j2Demo.java | 17 ++++++++ .../baeldung/mdc/log4j2/Log4j2Executor.java | 22 +++++++++++ .../src/main/resources/log4j.properties | 12 ++++++ log-mdc-ndc/src/main/resources/log4j2.xml | 32 +++++++++++++++ 12 files changed, 246 insertions(+) create mode 100644 log-mdc-ndc/README.md create mode 100644 log-mdc-ndc/pom.xml create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java create mode 100644 log-mdc-ndc/src/main/resources/log4j.properties create mode 100644 log-mdc-ndc/src/main/resources/log4j2.xml diff --git a/log-mdc-ndc/README.md b/log-mdc-ndc/README.md new file mode 100644 index 0000000000..29b0c95996 --- /dev/null +++ b/log-mdc-ndc/README.md @@ -0,0 +1,13 @@ +### Relevant Articles: +- TBD + +### References + +_Log4j MDC_ +* +* + +_Log4j2_ +* + + diff --git a/log-mdc-ndc/pom.xml b/log-mdc-ndc/pom.xml new file mode 100644 index 0000000000..b82285a283 --- /dev/null +++ b/log-mdc-ndc/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + com.baeldug + logmdcndc + 0.0.1-SNAPSHOT + logmdcndc + tutorial on logging with MDC and NDC + + + + + log4j + log4j + 1.2.17 + + + + + org.apache.logging.log4j + log4j-api + 2.7 + + + org.apache.logging.log4j + log4j-core + 2.7 + + + + + com.lmax + disruptor + 3.3.4 + + + + + \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java new file mode 100644 index 0000000000..dc33580aca --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java @@ -0,0 +1,7 @@ +package com.baeldung.mdc; + +public interface BusinessService { + + void businessMethod(String transactionId); + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java new file mode 100644 index 0000000000..f5694d0df0 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java @@ -0,0 +1,29 @@ +package com.baeldung.mdc; + +import java.util.Date; + +public class TransactionContext { + + private String transactionId; + private String owner; + private Date createdAt; + + public TransactionContext(String transactionId, String owner) { + this.transactionId = transactionId; + this.owner = owner; + this.createdAt = new Date(); + } + + public String getOwner() { + return owner; + } + + public String getTransactionId() { + return transactionId; + } + + public Date getCreatedAt() { + return createdAt; + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java new file mode 100644 index 0000000000..4587f49be4 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java @@ -0,0 +1,16 @@ +package com.baeldung.mdc.log4j; + +import org.apache.log4j.Logger; + +import com.baeldung.mdc.BusinessService; + +public class Log4jBusinessService implements BusinessService { + + private final static Logger logger = Logger.getLogger(Log4jBusinessService.class); + + @Override + public void businessMethod(String transactionId) { + logger.info("Executing transaction #" + transactionId ); + } + +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java new file mode 100644 index 0000000000..de3945020b --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java @@ -0,0 +1,17 @@ +package com.baeldung.mdc.log4j; + +public class Log4jDemo { + + public static void main(String[] args) throws InterruptedException { + Log4jExecutor greeter = new Log4jExecutor(); + Thread thread1 = new Thread(greeter); + Thread thread2 = new Thread(greeter); + + thread1.start(); + thread2.start(); + + thread1.join(); + thread2.join(); + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java new file mode 100644 index 0000000000..fb949aa4ef --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java @@ -0,0 +1,23 @@ +package com.baeldung.mdc.log4j; + +import org.apache.log4j.Logger; +import org.apache.log4j.MDC; + +import com.baeldung.mdc.TransactionContext; + +public class Log4jExecutor implements Runnable { + + public void run() { + + String transactionId = "" + Math.random(); + String owner = "owner" + Math.random(); + TransactionContext ctx = new TransactionContext(transactionId, owner); + + MDC.put("transaction.id", transactionId); + MDC.put("transaction.owner", owner); + MDC.put("transaction.createdAt", ctx.getCreatedAt()); + + new Log4jBusinessService().businessMethod(ctx.getTransactionId()); + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java new file mode 100644 index 0000000000..e9e0461a0a --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java @@ -0,0 +1,19 @@ +package com.baeldung.mdc.log4j2; + + + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.baeldung.mdc.BusinessService; + +public class Log4j2BusinessService implements BusinessService { + + private static final Logger logger = LogManager.getLogger(); //Log4j2BusinessService.class); + + @Override + public void businessMethod(String transactionId) { + logger.info("Executing transaction #{}", transactionId ); + } + +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java new file mode 100644 index 0000000000..0dec8a9a18 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java @@ -0,0 +1,17 @@ +package com.baeldung.mdc.log4j2; + +public class Log4j2Demo { + + public static void main(String[] args) throws InterruptedException { + Log4j2Executor greeter = new Log4j2Executor(); + Thread thread1 = new Thread(greeter); + Thread thread2 = new Thread(greeter); + + thread1.start(); + thread2.start(); + + thread1.join(); + thread2.join(); + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java new file mode 100644 index 0000000000..b206638ceb --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java @@ -0,0 +1,22 @@ +package com.baeldung.mdc.log4j2; + +import org.apache.logging.log4j.ThreadContext; + +import com.baeldung.mdc.TransactionContext; + +public class Log4j2Executor implements Runnable { + + public void run() { + + String transactionId = "" + Math.random(); + String owner = "owner" + Math.random(); + TransactionContext ctx = new TransactionContext(transactionId, owner); + + ThreadContext.put("transaction.id", transactionId); + ThreadContext.put("transaction.owner", owner); + ThreadContext.put("transaction.createdAt", ctx.getCreatedAt().toString()); + + new Log4j2BusinessService().businessMethod(ctx.getTransactionId()); + } + +} diff --git a/log-mdc-ndc/src/main/resources/log4j.properties b/log-mdc-ndc/src/main/resources/log4j.properties new file mode 100644 index 0000000000..dac8abf6b8 --- /dev/null +++ b/log-mdc-ndc/src/main/resources/log4j.properties @@ -0,0 +1,12 @@ +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout + +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=/tmp/$X{transaction.owner} +log4j.appender.file.layout=org.apache.log4j.PatternLayout + +#note the %X{userName} - this is how you fetch data from Mapped Diagnostic Context (MDC) +log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n +log4j.appender.file.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n + +log4j.rootLogger = ALL, consoleAppender, file \ No newline at end of file diff --git a/log-mdc-ndc/src/main/resources/log4j2.xml b/log-mdc-ndc/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..f9a2bdcf1a --- /dev/null +++ b/log-mdc-ndc/src/main/resources/log4j2.xml @@ -0,0 +1,32 @@ + + + + # Console appender + + # Pattern of log message for console appender + + + + # File appender + + + + + # Override log level for specified package + + + + + + + + \ No newline at end of file From be967daeb39f0f4a0f42a11568d3c4f278cb7a0b Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 31 Oct 2016 17:02:30 +0100 Subject: [PATCH 30/86] Logback demo added --- log-mdc-ndc/README.md | 5 ++++- log-mdc-ndc/pom.xml | 7 ++++++ .../mdc/logback/LogbackBusinessService.java | 17 ++++++++++++++ .../com/baeldung/mdc/logback/LogbackDemo.java | 17 ++++++++++++++ .../baeldung/mdc/logback/LogbackExecutor.java | 22 +++++++++++++++++++ log-mdc-ndc/src/main/resources/logback.xml | 14 ++++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java create mode 100644 log-mdc-ndc/src/main/resources/logback.xml diff --git a/log-mdc-ndc/README.md b/log-mdc-ndc/README.md index 29b0c95996..c271cbc63a 100644 --- a/log-mdc-ndc/README.md +++ b/log-mdc-ndc/README.md @@ -7,7 +7,10 @@ _Log4j MDC_ * * -_Log4j2_ +_Log4j2 MDC_ * +_Logback MDC_ +* + diff --git a/log-mdc-ndc/pom.xml b/log-mdc-ndc/pom.xml index b82285a283..9f1d48cae4 100644 --- a/log-mdc-ndc/pom.xml +++ b/log-mdc-ndc/pom.xml @@ -34,6 +34,13 @@ 3.3.4 + + + ch.qos.logback + logback-classic + 1.1.7 + + \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java new file mode 100644 index 0000000000..d15016c5c9 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java @@ -0,0 +1,17 @@ +package com.baeldung.mdc.logback; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.baeldung.mdc.BusinessService; + +public class LogbackBusinessService implements BusinessService { + + private static final Logger logger = LoggerFactory.getLogger(LogbackBusinessService.class); + + @Override + public void businessMethod(String transactionId) { + logger.info("Executing transaction #{}", transactionId); + } + +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java new file mode 100644 index 0000000000..877ded8cc3 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java @@ -0,0 +1,17 @@ +package com.baeldung.mdc.logback; + +public class LogbackDemo { + + public static void main(String[] args) throws InterruptedException { + LogbackExecutor greeter = new LogbackExecutor(); + Thread thread1 = new Thread(greeter); + Thread thread2 = new Thread(greeter); + + thread1.start(); + thread2.start(); + + thread1.join(); + thread2.join(); + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java new file mode 100644 index 0000000000..1e53ef9585 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java @@ -0,0 +1,22 @@ +package com.baeldung.mdc.logback; + +import org.slf4j.MDC; + +import com.baeldung.mdc.TransactionContext; + +public class LogbackExecutor implements Runnable { + + public void run() { + + String transactionId = "" + Math.random(); + String owner = "owner" + Math.random(); + TransactionContext ctx = new TransactionContext(transactionId, owner); + + MDC.put("transaction.id", transactionId); + MDC.put("transaction.owner", owner); + MDC.put("transaction.createdAt", ctx.getCreatedAt().toString()); + + new LogbackBusinessService().businessMethod(ctx.getTransactionId()); + } + +} diff --git a/log-mdc-ndc/src/main/resources/logback.xml b/log-mdc-ndc/src/main/resources/logback.xml new file mode 100644 index 0000000000..7bea9976e7 --- /dev/null +++ b/log-mdc-ndc/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + # Console appender + + + logback %d{yyyy-MM-dd HH:mm:ss} %p %m %X{transaction.owner} %X{transaction.createdAt} %n + + + + + + + + \ No newline at end of file From 189bee78720d88d6c5e28c34157df28d6a27c3fd Mon Sep 17 00:00:00 2001 From: danidemi Date: Tue, 1 Nov 2016 22:49:32 +0100 Subject: [PATCH 31/86] Intermediate work --- log-mdc-ndc/pom.xml | 22 +++++++++ .../com/baeldung/mdc/BusinessService.java | 2 +- .../baeldung/mdc/DefaultBusinessService.java | 15 ++++++ .../com/baeldung/mdc/DelegateBusiness.java | 30 ++++++++++++ .../java/com/baeldung/mdc/GenericApp.java | 46 +++++++++++++++++++ .../com/baeldung/mdc/TransactionContext.java | 6 +++ .../com/baeldung/mdc/TransactionFactory.java | 10 ++++ .../mdc/log4j/Log4jBusinessService.java | 5 +- .../com/baeldung/mdc/log4j/Log4jExecutor.java | 12 ++--- .../mdc/log4j2/Log4j2BusinessService.java | 5 +- .../baeldung/mdc/log4j2/Log4j2Executor.java | 11 ++--- .../mdc/logback/LogbackBusinessService.java | 5 +- .../baeldung/mdc/logback/LogbackExecutor.java | 13 +++--- .../java/com/baeldung/web/Application.java | 12 +++++ .../com/baeldung/web/GreetingController.java | 18 ++++++++ 15 files changed, 186 insertions(+), 26 deletions(-) create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/web/Application.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java diff --git a/log-mdc-ndc/pom.xml b/log-mdc-ndc/pom.xml index 9f1d48cae4..7e973b940e 100644 --- a/log-mdc-ndc/pom.xml +++ b/log-mdc-ndc/pom.xml @@ -6,8 +6,30 @@ 0.0.1-SNAPSHOT logmdcndc tutorial on logging with MDC and NDC + + + org.springframework.boot + spring-boot-starter-parent + 1.4.1.RELEASE + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + com.jayway.jsonpath + json-path + test + + log4j diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java index dc33580aca..21d065dc90 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java @@ -2,6 +2,6 @@ package com.baeldung.mdc; public interface BusinessService { - void businessMethod(String transactionId); + boolean transfer(Long amount); } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java new file mode 100644 index 0000000000..1df6783185 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java @@ -0,0 +1,15 @@ +package com.baeldung.mdc; + +public class DefaultBusinessService implements BusinessService { + + @Override + public boolean transfer(Long amount) { + try { + Thread.sleep((long) (Math.random()*1000)); + } catch (InterruptedException e) { + // should not happen + } + return Math.random() >= 0.5; + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java new file mode 100644 index 0000000000..ada8f79b62 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java @@ -0,0 +1,30 @@ +package com.baeldung.mdc; + +public abstract class DelegateBusiness { + + private BusinessService delegate = null; + + public DelegateBusiness(BusinessService delegate) { + super(); + this.delegate = delegate; + } + + + public DelegateBusiness() { + this( new DefaultBusinessService() ); + } + + public boolean transfer(Long amount) { + preTransfer(); + boolean outcome = delegate.transfer(amount); + postTransfer(outcome); + return outcome; + } + + abstract protected void postTransfer(boolean outcome); + + abstract protected void preTransfer(); + + + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java new file mode 100644 index 0000000000..3eee17ba5d --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java @@ -0,0 +1,46 @@ +package com.baeldung.mdc; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.apache.log4j.MDC; + +import com.baeldung.mdc.log4j.Log4jBusinessService; + +public class GenericApp { + public static void main(String[] args) { + + ExecutorService executor = Executors.newFixedThreadPool(3); + TransactionFactory transactionFactory = new TransactionFactory(); + + for(int i=0; i<10; i++){ + + TransactionContext tx = transactionFactory.buildTransaction(); + + executor.submit(new Runnable() { + @Override + public void run() { + new DelegateBusiness() { + + @Override + protected void preTransfer() { + MDC.put("transaction.id", tx.getTransactionId()); + MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.createdAt", tx.getCreatedAt()); + } + + @Override + protected void postTransfer(boolean outcome) { + // TODO Auto-generated method stub + + } + }.transfer( + tx.getAmount() + ); + } + }); + } + + } +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java index f5694d0df0..c6750edfda 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java @@ -7,11 +7,13 @@ public class TransactionContext { private String transactionId; private String owner; private Date createdAt; + private Long amount; public TransactionContext(String transactionId, String owner) { this.transactionId = transactionId; this.owner = owner; this.createdAt = new Date(); + this.amount = (long) (Math.random()*100); } public String getOwner() { @@ -26,4 +28,8 @@ public class TransactionContext { return createdAt; } + public Long getAmount() { + return amount; + } + } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java new file mode 100644 index 0000000000..4631c662c0 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java @@ -0,0 +1,10 @@ +package com.baeldung.mdc; + +public class TransactionFactory { + + public TransactionContext buildTransaction() { + TransactionContext ctx = new TransactionContext("" + Math.random(), "owner" + Math.random()); + return ctx; + } + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java index 4587f49be4..415e686cae 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java @@ -9,8 +9,9 @@ public class Log4jBusinessService implements BusinessService { private final static Logger logger = Logger.getLogger(Log4jBusinessService.class); @Override - public void businessMethod(String transactionId) { - logger.info("Executing transaction #" + transactionId ); + public boolean transfer(Long amount) { + logger.info("Executing transaction #" + amount ); + return false; } } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java index fb949aa4ef..96fe63a3ed 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java @@ -1,23 +1,21 @@ package com.baeldung.mdc.log4j; -import org.apache.log4j.Logger; import org.apache.log4j.MDC; import com.baeldung.mdc.TransactionContext; +import com.baeldung.mdc.TransactionFactory; public class Log4jExecutor implements Runnable { public void run() { - String transactionId = "" + Math.random(); - String owner = "owner" + Math.random(); - TransactionContext ctx = new TransactionContext(transactionId, owner); + TransactionContext ctx = new TransactionFactory().buildTransaction(); - MDC.put("transaction.id", transactionId); - MDC.put("transaction.owner", owner); + MDC.put("transaction.id", ctx.getTransactionId()); + MDC.put("transaction.owner", ctx.getOwner()); MDC.put("transaction.createdAt", ctx.getCreatedAt()); - new Log4jBusinessService().businessMethod(ctx.getTransactionId()); + new Log4jBusinessService().transfer(ctx.getAmount()); } } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java index e9e0461a0a..d1a8dca518 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java @@ -12,8 +12,9 @@ public class Log4j2BusinessService implements BusinessService { private static final Logger logger = LogManager.getLogger(); //Log4j2BusinessService.class); @Override - public void businessMethod(String transactionId) { - logger.info("Executing transaction #{}", transactionId ); + public boolean transfer(Long amount) { + logger.info("Executing transaction #{}", amount ); + return false; } } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java index b206638ceb..a686486e8e 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java @@ -3,20 +3,19 @@ package com.baeldung.mdc.log4j2; import org.apache.logging.log4j.ThreadContext; import com.baeldung.mdc.TransactionContext; +import com.baeldung.mdc.TransactionFactory; public class Log4j2Executor implements Runnable { public void run() { - String transactionId = "" + Math.random(); - String owner = "owner" + Math.random(); - TransactionContext ctx = new TransactionContext(transactionId, owner); + TransactionContext ctx = new TransactionFactory().buildTransaction(); - ThreadContext.put("transaction.id", transactionId); - ThreadContext.put("transaction.owner", owner); + ThreadContext.put("transaction.id", ctx.getTransactionId()); + ThreadContext.put("transaction.owner", ctx.getOwner()); ThreadContext.put("transaction.createdAt", ctx.getCreatedAt().toString()); - new Log4j2BusinessService().businessMethod(ctx.getTransactionId()); + new Log4j2BusinessService().transfer(ctx.getAmount()); } } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java index d15016c5c9..74f96ef15e 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java @@ -10,8 +10,9 @@ public class LogbackBusinessService implements BusinessService { private static final Logger logger = LoggerFactory.getLogger(LogbackBusinessService.class); @Override - public void businessMethod(String transactionId) { - logger.info("Executing transaction #{}", transactionId); + public boolean transfer(Long amount) { + logger.info("Executing transaction #{}", amount); + return false; } } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java index 1e53ef9585..614188b757 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java @@ -3,20 +3,21 @@ package com.baeldung.mdc.logback; import org.slf4j.MDC; import com.baeldung.mdc.TransactionContext; +import com.baeldung.mdc.TransactionFactory; public class LogbackExecutor implements Runnable { public void run() { - String transactionId = "" + Math.random(); - String owner = "owner" + Math.random(); - TransactionContext ctx = new TransactionContext(transactionId, owner); + TransactionContext ctx = new TransactionFactory().buildTransaction(); - MDC.put("transaction.id", transactionId); - MDC.put("transaction.owner", owner); + MDC.put("transaction.id", ctx.getTransactionId()); + MDC.put("transaction.owner", ctx.getOwner()); MDC.put("transaction.createdAt", ctx.getCreatedAt().toString()); - new LogbackBusinessService().businessMethod(ctx.getTransactionId()); + new LogbackBusinessService().transfer(ctx.getAmount()); } + + } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/web/Application.java b/log-mdc-ndc/src/main/java/com/baeldung/web/Application.java new file mode 100644 index 0000000000..a700e345db --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/web/Application.java @@ -0,0 +1,12 @@ +package com.baeldung.web; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java b/log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java new file mode 100644 index 0000000000..760e26a705 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java @@ -0,0 +1,18 @@ +package com.baeldung.web; + +import java.util.concurrent.atomic.AtomicLong; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class GreetingController { + + @GetMapping("/echo") + public String echo(@RequestBody String body) { + return body; + } +} \ No newline at end of file From 41da06a7bc7a203e3bb22e27767649a417753a84 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Wed, 2 Nov 2016 07:56:47 +0530 Subject: [PATCH 32/86] Remove try-catch from Test classes --- .../selenium/junit/SeleniumWithJUnitLiveTest.java | 5 ----- .../testng/SeleniumWithTestNGLiveTest.java | 15 +++++---------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java b/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java index f8d9a5dada..180b3d9d33 100644 --- a/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java +++ b/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java @@ -26,16 +26,11 @@ public class SeleniumWithJUnitLiveTest { @Test public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() { - try { seleniumExample.getAboutBaeldungPage(); String actualTitle = seleniumExample.getTitle(); assertNotNull(actualTitle); assertEquals(actualTitle, expecteTilteAboutBaeldungPage); assertTrue(seleniumExample.isAuthorInformationAvailable()); - } catch (Exception exception) { - exception.printStackTrace(); - seleniumExample.closeWindow(); - } } } diff --git a/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java b/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java index 5ec9ade39f..bc8fc712bf 100644 --- a/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java +++ b/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java @@ -26,15 +26,10 @@ public class SeleniumWithTestNGLiveTest { @Test public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() { - try { - seleniumExample.getAboutBaeldungPage(); - String actualTitle = seleniumExample.getTitle(); - assertNotNull(actualTitle); - assertEquals(actualTitle, expecteTilteAboutBaeldungPage); - assertTrue(seleniumExample.isAuthorInformationAvailable()); - } catch (Exception exception) { - exception.printStackTrace(); - seleniumExample.closeWindow(); - } + seleniumExample.getAboutBaeldungPage(); + String actualTitle = seleniumExample.getTitle(); + assertNotNull(actualTitle); + assertEquals(actualTitle, expecteTilteAboutBaeldungPage); + assertTrue(seleniumExample.isAuthorInformationAvailable()); } } From 108adf84f6847cc4221c59024dfb0567748e00d3 Mon Sep 17 00:00:00 2001 From: "nguyenminhtuanfit@gmail.com" Date: Fri, 4 Nov 2016 07:57:11 +0700 Subject: [PATCH 33/86] aspectj introduction --- aspectj/pom.xml | 131 ++++++++++++++++++ .../java/com/baeldung/aspectj/Account.java | 13 ++ .../com/baeldung/aspectj/AccountAspect.aj | 30 ++++ .../java/com/baeldung/aspectj/Secured.java | 12 ++ .../com/baeldung/aspectj/SecuredMethod.java | 23 +++ .../baeldung/aspectj/SecuredMethodAspect.java | 27 ++++ aspectj/src/main/resources/META-INF/aop.xml | 8 ++ aspectj/src/main/resources/logback.xml | 18 +++ .../baeldung/aspectj/test/AccountTest.java | 27 ++++ .../aspectj/test/SecuredMethodTest.java | 14 ++ 10 files changed, 303 insertions(+) create mode 100644 aspectj/pom.xml create mode 100644 aspectj/src/main/java/com/baeldung/aspectj/Account.java create mode 100644 aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj create mode 100644 aspectj/src/main/java/com/baeldung/aspectj/Secured.java create mode 100644 aspectj/src/main/java/com/baeldung/aspectj/SecuredMethod.java create mode 100644 aspectj/src/main/java/com/baeldung/aspectj/SecuredMethodAspect.java create mode 100644 aspectj/src/main/resources/META-INF/aop.xml create mode 100644 aspectj/src/main/resources/logback.xml create mode 100644 aspectj/src/test/java/com/baeldung/aspectj/test/AccountTest.java create mode 100644 aspectj/src/test/java/com/baeldung/aspectj/test/SecuredMethodTest.java diff --git a/aspectj/pom.xml b/aspectj/pom.xml new file mode 100644 index 0000000000..2a1cff11c8 --- /dev/null +++ b/aspectj/pom.xml @@ -0,0 +1,131 @@ + + 4.0.0 + com.baeldung + aspectj + 0.0.1-SNAPSHOT + aspectj + + + + org.aspectj + aspectjrt + ${aspectj.version} + + + + org.aspectj + aspectjweaver + ${aspectj.version} + + + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + + + + junit + junit + ${junit.version} + + + + + + aspectj + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${source.version} + ${source.version} + + + + + + org.codehaus.mojo + aspectj-maven-plugin + 1.7 + + ${source.version} + ${source.version} + ${source.version} + true + true + ignore + ${project.build.sourceEncoding} + + + + + + + compile + test-compile + + + + + + + + + + + 1.8 + 1.6.11 + UTF-8 + 1.8.9 + 1.7.21 + 1.1.7 + 3.5.1 + 4.12 + + + \ No newline at end of file diff --git a/aspectj/src/main/java/com/baeldung/aspectj/Account.java b/aspectj/src/main/java/com/baeldung/aspectj/Account.java new file mode 100644 index 0000000000..59cab72ebf --- /dev/null +++ b/aspectj/src/main/java/com/baeldung/aspectj/Account.java @@ -0,0 +1,13 @@ +package com.baeldung.aspectj; + +public class Account { + int balance = 20; + + public boolean withdraw(int amount) { + if (balance - amount > 0) { + balance = balance - amount; + return true; + } else + return false; + } +} diff --git a/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj b/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj new file mode 100644 index 0000000000..3bdddd22a8 --- /dev/null +++ b/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj @@ -0,0 +1,30 @@ +package com.baeldung.aspectj; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public aspect AccountAspect { + private static final Logger logger = LoggerFactory.getLogger(AccountAspect.class); + final int MIN_BALANCE = 10; + + pointcut callWithDraw(int amount, Account account): + call(boolean Account.withdraw(int)) && args(amount) && target(account); + + before(int amount, Account account) : callWithDraw(amount, account) { + logger.info(" Balance before withdrawal: {}", account.balance); + logger.info(" Withdraw ammout: {}", amount); + } + + boolean around(int amount, Account account) : callWithDraw(amount, account) { + if (account.balance - amount >= MIN_BALANCE) + return proceed(amount, account); + else { + logger.info("Withdrawal Rejected!"); + return false; + } + } + + after(int amount, Account balance) : callAtWithDraw(amount, balance) { + logger.info("Balance after withdrawal : {}", balance.balance); + } +} diff --git a/aspectj/src/main/java/com/baeldung/aspectj/Secured.java b/aspectj/src/main/java/com/baeldung/aspectj/Secured.java new file mode 100644 index 0000000000..923f208c2f --- /dev/null +++ b/aspectj/src/main/java/com/baeldung/aspectj/Secured.java @@ -0,0 +1,12 @@ +package com.baeldung.aspectj; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Secured { + public boolean isLocked() default false; +} diff --git a/aspectj/src/main/java/com/baeldung/aspectj/SecuredMethod.java b/aspectj/src/main/java/com/baeldung/aspectj/SecuredMethod.java new file mode 100644 index 0000000000..aa4b733a00 --- /dev/null +++ b/aspectj/src/main/java/com/baeldung/aspectj/SecuredMethod.java @@ -0,0 +1,23 @@ +package com.baeldung.aspectj; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SecuredMethod { + private static final Logger logger = LoggerFactory.getLogger(SecuredMethod.class); + + @Secured(isLocked = true) + public void lockedMethod() throws Exception { + logger.info("lockedMethod"); + } + + @Secured(isLocked = false) + public void unlockedMethod() { + logger.info("unlockedMethod"); + } + + public static void main(String[] args) throws Exception { + SecuredMethod sv = new SecuredMethod(); + sv.lockedMethod(); + } +} \ No newline at end of file diff --git a/aspectj/src/main/java/com/baeldung/aspectj/SecuredMethodAspect.java b/aspectj/src/main/java/com/baeldung/aspectj/SecuredMethodAspect.java new file mode 100644 index 0000000000..9ea45ec43b --- /dev/null +++ b/aspectj/src/main/java/com/baeldung/aspectj/SecuredMethodAspect.java @@ -0,0 +1,27 @@ +package com.baeldung.aspectj; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Aspect +public class SecuredMethodAspect { + private static final Logger logger = LoggerFactory.getLogger(SecuredMethodAspect.class); + + @Pointcut("@annotation(secured)") + public void callAt(Secured secured) { + } + + @Around("callAt(secured)") + public Object around(ProceedingJoinPoint pjp, Secured secured) throws Throwable { + if (secured.isLocked()) { + logger.info(pjp.getSignature().toLongString() + " is locked"); + return null; + } else { + return pjp.proceed(); + } + } +} diff --git a/aspectj/src/main/resources/META-INF/aop.xml b/aspectj/src/main/resources/META-INF/aop.xml new file mode 100644 index 0000000000..f930cde942 --- /dev/null +++ b/aspectj/src/main/resources/META-INF/aop.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/aspectj/src/main/resources/logback.xml b/aspectj/src/main/resources/logback.xml new file mode 100644 index 0000000000..8b566286b8 --- /dev/null +++ b/aspectj/src/main/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg %n + + + + + + + + + + + + \ No newline at end of file diff --git a/aspectj/src/test/java/com/baeldung/aspectj/test/AccountTest.java b/aspectj/src/test/java/com/baeldung/aspectj/test/AccountTest.java new file mode 100644 index 0000000000..d90793f681 --- /dev/null +++ b/aspectj/src/test/java/com/baeldung/aspectj/test/AccountTest.java @@ -0,0 +1,27 @@ +package com.baeldung.aspectj.test; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.aspectj.Account; + +public class AccountTest { + private Account account; + + @Before + public void before() { + account = new Account(); + } + + @Test + public void givenBalance20AndMinBalance10_whenWithdraw5_thenSuccess() { + assertTrue(account.withdraw(5)); + } + + @Test + public void givenBalance20AndMinBalance10_whenWithdraw100_thenFail() { + assertFalse(account.withdraw(100)); + } +} diff --git a/aspectj/src/test/java/com/baeldung/aspectj/test/SecuredMethodTest.java b/aspectj/src/test/java/com/baeldung/aspectj/test/SecuredMethodTest.java new file mode 100644 index 0000000000..924bb279fd --- /dev/null +++ b/aspectj/src/test/java/com/baeldung/aspectj/test/SecuredMethodTest.java @@ -0,0 +1,14 @@ +package com.baeldung.aspectj.test; + +import org.junit.Test; + +import com.baeldung.aspectj.SecuredMethod; + +public class SecuredMethodTest { + @Test + public void testMethod() throws Exception { + SecuredMethod service = new SecuredMethod(); + service.unlockedMethod(); + service.lockedMethod(); + } +} \ No newline at end of file From 4d46d5273386270c738f910036f9b0c500d9dfa6 Mon Sep 17 00:00:00 2001 From: oreva Date: Sun, 6 Nov 2016 10:23:19 +0200 Subject: [PATCH 34/86] Patch 0001-Code-cleanup.patch applied. --- .../baeldung/spring/app/config/AppConfig.java | 10 ----- .../spring/mail/EmailServiceImpl.java | 3 +- .../java/com/baeldung/spring/mail/Order.java | 43 ------------------- .../baeldung/spring/mail/OrderManager.java | 31 ------------- 4 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java delete mode 100644 spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java index 9f8339c2fe..9078d44764 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/app/config/AppConfig.java @@ -45,16 +45,6 @@ public class AppConfig extends WebMvcConfigurerAdapter { return resolver; } - @Bean - public SimpleMailMessage templateOrderMessage() { - SimpleMailMessage message = new SimpleMailMessage(); - message.setText("Dear %s %s, \nthank you for placing order.\n" + - "\n" + - "Sincerely yours,\n" + - "Yourcompany."); - return message; - } - @Bean public SimpleMailMessage templateSimpleMessage() { SimpleMailMessage message = new SimpleMailMessage(); diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java index dab5400d25..ca418a7d90 100644 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java +++ b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java @@ -24,7 +24,6 @@ public class EmailServiceImpl implements EmailService { public void sendSimpleMessage(String to, String subject, String text) { try { SimpleMailMessage message = new SimpleMailMessage(); - message.setTo(to); message.setSubject(subject); message.setText(text); @@ -40,7 +39,7 @@ public class EmailServiceImpl implements EmailService { String subject, SimpleMailMessage template, String ...templateArgs) { - String text = String.format(template.getText(), templateArgs); + String text = String.format(template.getText(), templateArgs); sendSimpleMessage(to, subject, text); } diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java deleted file mode 100644 index cd1448b84b..0000000000 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/Order.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.spring.mail; - -/** - * Created by Olga on 8/22/2016. - */ -public class Order { - - public Order(String customerEmail, - String customerFirstName, - String customerLastName) { - this.customerEmail = customerEmail; - this.customerFirstName = customerFirstName; - this.customerLastName = customerLastName; - } - - private String customerEmail; - private String customerFirstName; - private String customerLastName; - - public String getCustomerEmail() { - return customerEmail; - } - - public void setCustomerEmail(String customerEmail) { - this.customerEmail = customerEmail; - } - - public String getCustomerFirstName() { - return customerFirstName; - } - - public void setCustomerFirstName(String customerFirstName) { - this.customerFirstName = customerFirstName; - } - - public String getCustomerLastName() { - return customerLastName; - } - - public void setCustomerLastName(String customerLastName) { - this.customerLastName = customerLastName; - } -} diff --git a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java b/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java deleted file mode 100644 index 5dfe25f20f..0000000000 --- a/spring-mvc-email/src/main/java/com/baeldung/spring/mail/OrderManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.spring.mail; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.stereotype.Component; - -/** - * Created by Olga on 8/22/2016. - */ -@Component -public class OrderManager { - @Autowired - public EmailService emailService; - - @Value("${attachment.invoice}") - private String invoiceAttachmentPath; - - @Autowired() - @Qualifier("templateOrderMessage") - public SimpleMailMessage template; - - public void placeOrder(Order order) { - emailService.sendSimpleMessageUsingTemplate(order.getCustomerEmail(), - "Order Confirmation", - template, - order.getCustomerFirstName(), - order.getCustomerLastName()); - } -} From 807a4d2db9fadd1df4976d8b5b3e0d9fd0c30813 Mon Sep 17 00:00:00 2001 From: oreva Date: Sun, 6 Nov 2016 12:07:51 +0200 Subject: [PATCH 35/86] Implemented changes regarding the latest review. --- .../spring/controllers/MailController.java | 49 ++++++++++++- .../src/main/resources/application.properties | 3 +- .../main/webapp/WEB-INF/views/mail/send.jsp | 70 ++++++++++--------- 3 files changed, 86 insertions(+), 36 deletions(-) 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 1f536e3297..768a0f8e7b 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 @@ -13,7 +13,12 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; /** * Created by Olga on 7/20/2016. @@ -31,8 +36,50 @@ public class MailController { @Qualifier("templateSimpleMessage") public SimpleMailMessage template; + private static final Map> labels; + + static { + labels = new HashMap<>(); + + //Simple email + Map props = new HashMap<>(); + props.put("headerText", "Send Simple Email"); + props.put("messageLabel", "Message"); + props.put("additionalInfo", ""); + labels.put("send", props); + + //Email with template + props = new HashMap<>(); + props.put("headerText", "Send Email Using Template"); + props.put("messageLabel", "Template Parameter"); + props.put("additionalInfo", + "The parameter value will be added to the following message template:
" + + "This is the test email template for your email:
'Template Parameter'
" + ); + labels.put("sendTemplate", props); + + //Email with attachment + props = new HashMap<>(); + props.put("headerText", "Send Email With Attachment"); + props.put("messageLabel", "Message"); + props.put("additionalInfo", "To make sure that you send an attachment with this email, change the value for the 'attachment.invoice' in the application.properties file to the path to the attachment."); + labels.put("sendAttachment", props); + } + @RequestMapping(value = {"/send", "/sendTemplate", "/sendAttachment"}, method = RequestMethod.GET) - public String createMail(Model model) { + public String createMail(Model model, + HttpServletRequest request) { + String action = request.getRequestURL().substring( + request.getRequestURL().lastIndexOf("/") + 1 + ); + Map props = labels.get(action); + Set keys = props.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + String key = iterator.next(); + model.addAttribute(key, props.get(key)); + } + model.addAttribute("mailObject", new MailObject()); return "mail/send"; } diff --git a/spring-mvc-email/src/main/resources/application.properties b/spring-mvc-email/src/main/resources/application.properties index ba0608c3af..61a42050e5 100644 --- a/spring-mvc-email/src/main/resources/application.properties +++ b/spring-mvc-email/src/main/resources/application.properties @@ -17,5 +17,4 @@ spring.mail.properties.mail.smtp.starttls.enable=true #spring.mail.properties.mail.smtp.starttls.required=true # path to attachment file -attachment.invoice=path_to_file -#attachment.invoice=c:/invoice.jpg \ No newline at end of file +attachment.invoice=path_to_file \ No newline at end of file diff --git a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp index 294cb2c49c..d27aa09d9a 100644 --- a/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp +++ b/spring-mvc-email/src/main/webapp/WEB-INF/views/mail/send.jsp @@ -13,40 +13,44 @@
-

Create Email

- +

${headerText}

+
- - - - - - - - - - - - - - - - - -
- Enter email address
- -
- Enter the subject
- -
- Enter message text
- -
- -
+
+ + + + + + + + + + + + + + + + + +
+ Enter email address
+ +
+ Enter the subject
+ +
+ +
+ +
+
+
+ ${additionalInfo} +
From 9bd83d921cff2b0ccfb0b575a06a5daf2f72dc1b Mon Sep 17 00:00:00 2001 From: danidemi Date: Sun, 6 Nov 2016 15:57:07 +0100 Subject: [PATCH 36/86] Examples done. --- log-mdc-ndc/pom.xml | 32 ++++++----------- .../com/baeldung/mdc/BusinessService.java | 4 ++- .../baeldung/mdc/DefaultBusinessService.java | 14 +++++--- .../com/baeldung/mdc/DelegateBusiness.java | 11 +++--- .../java/com/baeldung/mdc/GenericApp.java | 35 ++++--------------- ...ansactionContext.java => Transaction.java} | 6 ++-- .../com/baeldung/mdc/TransactionFactory.java | 16 +++++++-- .../mdc/log4j/Log4JBusinessService.java | 22 ++++++++++++ .../com/baeldung/mdc/log4j/Log4JRunnable.java | 25 +++++++++++++ .../mdc/log4j/Log4jBusinessService.java | 17 --------- .../com/baeldung/mdc/log4j/Log4jDemo.java | 17 --------- .../com/baeldung/mdc/log4j/Log4jExecutor.java | 21 ----------- .../mdc/log4j2/Log4J2BusinessService.java | 21 +++++++++++ .../baeldung/mdc/log4j2/Log4J2Runnable.java | 25 +++++++++++++ .../mdc/log4j2/Log4j2BusinessService.java | 20 ----------- .../com/baeldung/mdc/log4j2/Log4j2Demo.java | 17 --------- .../baeldung/mdc/log4j2/Log4j2Executor.java | 21 ----------- .../mdc/logback/LogbackBusinessService.java | 18 ---------- .../com/baeldung/mdc/logback/LogbackDemo.java | 17 --------- .../baeldung/mdc/logback/LogbackExecutor.java | 23 ------------ .../mdc/slf4j/Slf4jBusinessService.java | 22 ++++++++++++ .../com/baeldung/mdc/slf4j/Slf4jRunnable.java | 25 +++++++++++++ .../java/com/baeldung/web/Application.java | 12 ------- .../com/baeldung/web/GreetingController.java | 18 ---------- .../src/main/resources/log4j.properties | 10 +++--- 25 files changed, 197 insertions(+), 272 deletions(-) rename log-mdc-ndc/src/main/java/com/baeldung/mdc/{TransactionContext.java => Transaction.java} (76%) create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/web/Application.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java diff --git a/log-mdc-ndc/pom.xml b/log-mdc-ndc/pom.xml index 7e973b940e..8e9d52a750 100644 --- a/log-mdc-ndc/pom.xml +++ b/log-mdc-ndc/pom.xml @@ -7,28 +7,18 @@ logmdcndc tutorial on logging with MDC and NDC - - org.springframework.boot - spring-boot-starter-parent - 1.4.1.RELEASE - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - com.jayway.jsonpath - json-path - test - + + + org.springframework + spring-context + 4.3.3.RELEASE + + + org.springframework + spring-webmvc + 4.3.3.RELEASE + diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java index 21d065dc90..51bebeb713 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java @@ -2,6 +2,8 @@ package com.baeldung.mdc; public interface BusinessService { - boolean transfer(Long amount); + /** Sample service transferring a given amount of money. + * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ + boolean transfer(long amount); } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java index 1df6783185..d5bb94d21a 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java @@ -1,15 +1,19 @@ package com.baeldung.mdc; +/** + * A fake {@link BusinessService} simulating an actual one. + */ public class DefaultBusinessService implements BusinessService { - @Override - public boolean transfer(Long amount) { + public boolean transfer(long amount) { try { - Thread.sleep((long) (Math.random()*1000)); + // let's pause randomly to properly simulate an actual system. + Thread.sleep((long) (500 + Math.random()*500)); } catch (InterruptedException e) { - // should not happen + // should never happen } - return Math.random() >= 0.5; + // let's simulate both failing and successful transfers + return Math.random() >= 0.25; } } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java index ada8f79b62..d7aab0e284 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java @@ -9,21 +9,20 @@ public abstract class DelegateBusiness { this.delegate = delegate; } - public DelegateBusiness() { this( new DefaultBusinessService() ); } - public boolean transfer(Long amount) { - preTransfer(); + public boolean transfer(long amount) { + preTransfer(amount); boolean outcome = delegate.transfer(amount); - postTransfer(outcome); + postTransfer(amount, outcome); return outcome; } - abstract protected void postTransfer(boolean outcome); + abstract protected void postTransfer(long amount, boolean outcome); - abstract protected void preTransfer(); + abstract protected void preTransfer(long amount); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java index 3eee17ba5d..3652032e0e 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java @@ -1,46 +1,25 @@ package com.baeldung.mdc; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.log4j.MDC; +import org.apache.log4j.Logger; -import com.baeldung.mdc.log4j.Log4jBusinessService; +import com.baeldung.mdc.log4j.Log4JRunnable; public class GenericApp { + public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(3); TransactionFactory transactionFactory = new TransactionFactory(); for(int i=0; i<10; i++){ - - TransactionContext tx = transactionFactory.buildTransaction(); - - executor.submit(new Runnable() { - @Override - public void run() { - new DelegateBusiness() { - - @Override - protected void preTransfer() { - MDC.put("transaction.id", tx.getTransactionId()); - MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt()); - } - - @Override - protected void postTransfer(boolean outcome) { - // TODO Auto-generated method stub - - } - }.transfer( - tx.getAmount() - ); - } - }); + final Transaction tx = transactionFactory.newInstance(); + executor.submit(new Log4JRunnable(tx)); } + executor.shutdown(); + } } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java similarity index 76% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java index c6750edfda..ac0fe75ac5 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionContext.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java @@ -2,18 +2,18 @@ package com.baeldung.mdc; import java.util.Date; -public class TransactionContext { +public class Transaction { private String transactionId; private String owner; private Date createdAt; private Long amount; - public TransactionContext(String transactionId, String owner) { + public Transaction(String transactionId, String owner, long amount) { this.transactionId = transactionId; this.owner = owner; this.createdAt = new Date(); - this.amount = (long) (Math.random()*100); + this.amount = amount; } public String getOwner() { diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java index 4631c662c0..26039ba1d4 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java @@ -1,10 +1,20 @@ package com.baeldung.mdc; +import static java.lang.Math.floor; +import static java.lang.Math.random; + +import java.util.UUID; + public class TransactionFactory { - public TransactionContext buildTransaction() { - TransactionContext ctx = new TransactionContext("" + Math.random(), "owner" + Math.random()); - return ctx; + private static final String[] NAMES = {"John", "Susan", "Marc", "Samantha"}; + + public Transaction newInstance() { + String transactionId = UUID.randomUUID().toString(); + String owner = NAMES[ (int) floor(random()*NAMES.length) ]; + long amount = (long) (random()*1500 + 500); + Transaction tx = new Transaction(transactionId, owner, amount); + return tx; } } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java new file mode 100644 index 0000000000..52439a25f7 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java @@ -0,0 +1,22 @@ +package com.baeldung.mdc.log4j; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.baeldung.mdc.DelegateBusiness; + +final class Log4JBusinessService extends DelegateBusiness { + + private static final Logger logger = LogManager.getLogger(); + + @Override + protected void preTransfer(long amount) { + logger.info("Preparing to transfer {}$."); + } + + @Override + protected void postTransfer(long amount, boolean outcome) { + logger.info("Has transfer of {}$ completed successfully ? {}."); + } + +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java new file mode 100644 index 0000000000..2aeb75f95a --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java @@ -0,0 +1,25 @@ +package com.baeldung.mdc.log4j; + +import org.apache.log4j.MDC; + +import com.baeldung.mdc.Transaction; + +public class Log4JRunnable implements Runnable { + private final Transaction tx; + + public Log4JRunnable(Transaction tx) { + this.tx = tx; + } + + public void run() { + + MDC.put("transaction.id", tx.getTransactionId()); + MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.createdAt", tx.getCreatedAt()); + + new Log4JBusinessService().transfer(tx.getAmount()); + + MDC.clear(); + + } +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java deleted file mode 100644 index 415e686cae..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jBusinessService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.mdc.log4j; - -import org.apache.log4j.Logger; - -import com.baeldung.mdc.BusinessService; - -public class Log4jBusinessService implements BusinessService { - - private final static Logger logger = Logger.getLogger(Log4jBusinessService.class); - - @Override - public boolean transfer(Long amount) { - logger.info("Executing transaction #" + amount ); - return false; - } - -} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java deleted file mode 100644 index de3945020b..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jDemo.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.mdc.log4j; - -public class Log4jDemo { - - public static void main(String[] args) throws InterruptedException { - Log4jExecutor greeter = new Log4jExecutor(); - Thread thread1 = new Thread(greeter); - Thread thread2 = new Thread(greeter); - - thread1.start(); - thread2.start(); - - thread1.join(); - thread2.join(); - } - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java deleted file mode 100644 index 96fe63a3ed..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4jExecutor.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.mdc.log4j; - -import org.apache.log4j.MDC; - -import com.baeldung.mdc.TransactionContext; -import com.baeldung.mdc.TransactionFactory; - -public class Log4jExecutor implements Runnable { - - public void run() { - - TransactionContext ctx = new TransactionFactory().buildTransaction(); - - MDC.put("transaction.id", ctx.getTransactionId()); - MDC.put("transaction.owner", ctx.getOwner()); - MDC.put("transaction.createdAt", ctx.getCreatedAt()); - - new Log4jBusinessService().transfer(ctx.getAmount()); - } - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java new file mode 100644 index 0000000000..8e7655697e --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java @@ -0,0 +1,21 @@ +package com.baeldung.mdc.log4j2; + +import org.apache.log4j.Logger; + +import com.baeldung.mdc.DelegateBusiness; + +final class Log4J2BusinessService extends DelegateBusiness { + + private Logger logger = Logger.getLogger(Log4J2BusinessService.class); + + @Override + protected void preTransfer(long amount) { + logger .info("Preparing to transfer " + amount + "$."); + } + + @Override + protected void postTransfer(long amount, boolean outcome) { + logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); + } + +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java new file mode 100644 index 0000000000..32f2161af8 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java @@ -0,0 +1,25 @@ +package com.baeldung.mdc.log4j2; + +import org.apache.logging.log4j.ThreadContext; + +import com.baeldung.mdc.Transaction; + +final class Log4J2Runnable implements Runnable { + private final Transaction tx; + + Log4J2Runnable(Transaction tx) { + this.tx = tx; + } + + public void run() { + + ThreadContext.put("transaction.id", tx.getTransactionId()); + ThreadContext.put("transaction.owner", tx.getOwner()); + ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString()); + + new Log4J2BusinessService().transfer(tx.getAmount()); + + ThreadContext.clearAll(); + + } +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java deleted file mode 100644 index d1a8dca518..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2BusinessService.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.mdc.log4j2; - - - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.baeldung.mdc.BusinessService; - -public class Log4j2BusinessService implements BusinessService { - - private static final Logger logger = LogManager.getLogger(); //Log4j2BusinessService.class); - - @Override - public boolean transfer(Long amount) { - logger.info("Executing transaction #{}", amount ); - return false; - } - -} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java deleted file mode 100644 index 0dec8a9a18..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Demo.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.mdc.log4j2; - -public class Log4j2Demo { - - public static void main(String[] args) throws InterruptedException { - Log4j2Executor greeter = new Log4j2Executor(); - Thread thread1 = new Thread(greeter); - Thread thread2 = new Thread(greeter); - - thread1.start(); - thread2.start(); - - thread1.join(); - thread2.join(); - } - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java deleted file mode 100644 index a686486e8e..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4j2Executor.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.mdc.log4j2; - -import org.apache.logging.log4j.ThreadContext; - -import com.baeldung.mdc.TransactionContext; -import com.baeldung.mdc.TransactionFactory; - -public class Log4j2Executor implements Runnable { - - public void run() { - - TransactionContext ctx = new TransactionFactory().buildTransaction(); - - ThreadContext.put("transaction.id", ctx.getTransactionId()); - ThreadContext.put("transaction.owner", ctx.getOwner()); - ThreadContext.put("transaction.createdAt", ctx.getCreatedAt().toString()); - - new Log4j2BusinessService().transfer(ctx.getAmount()); - } - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java deleted file mode 100644 index 74f96ef15e..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackBusinessService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.mdc.logback; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.baeldung.mdc.BusinessService; - -public class LogbackBusinessService implements BusinessService { - - private static final Logger logger = LoggerFactory.getLogger(LogbackBusinessService.class); - - @Override - public boolean transfer(Long amount) { - logger.info("Executing transaction #{}", amount); - return false; - } - -} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java deleted file mode 100644 index 877ded8cc3..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackDemo.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.mdc.logback; - -public class LogbackDemo { - - public static void main(String[] args) throws InterruptedException { - LogbackExecutor greeter = new LogbackExecutor(); - Thread thread1 = new Thread(greeter); - Thread thread2 = new Thread(greeter); - - thread1.start(); - thread2.start(); - - thread1.join(); - thread2.join(); - } - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java deleted file mode 100644 index 614188b757..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/logback/LogbackExecutor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.mdc.logback; - -import org.slf4j.MDC; - -import com.baeldung.mdc.TransactionContext; -import com.baeldung.mdc.TransactionFactory; - -public class LogbackExecutor implements Runnable { - - public void run() { - - TransactionContext ctx = new TransactionFactory().buildTransaction(); - - MDC.put("transaction.id", ctx.getTransactionId()); - MDC.put("transaction.owner", ctx.getOwner()); - MDC.put("transaction.createdAt", ctx.getCreatedAt().toString()); - - new LogbackBusinessService().transfer(ctx.getAmount()); - } - - - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java new file mode 100644 index 0000000000..af14abcf0f --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java @@ -0,0 +1,22 @@ +package com.baeldung.mdc.slf4j; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.baeldung.mdc.DelegateBusiness; + +final class Slf4jBusinessService extends DelegateBusiness { + + private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); + + @Override + protected void preTransfer(long amount) { + logger.info("Preparing to transfer " + amount + "$."); + } + + @Override + protected void postTransfer(long amount, boolean outcome) { + logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); + } + +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java new file mode 100644 index 0000000000..938b18c257 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java @@ -0,0 +1,25 @@ +package com.baeldung.mdc.slf4j; + +import org.slf4j.MDC; + +import com.baeldung.mdc.Transaction; + +final class Slf4jRunnable implements Runnable { + private final Transaction tx; + + Slf4jRunnable(Transaction tx) { + this.tx = tx; + } + + public void run() { + + MDC.put("transaction.id", tx.getTransactionId()); + MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.createdAt", tx.getCreatedAt().toString()); + + new Slf4jBusinessService().transfer(tx.getAmount()); + + MDC.clear(); + + } +} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/web/Application.java b/log-mdc-ndc/src/main/java/com/baeldung/web/Application.java deleted file mode 100644 index a700e345db..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/web/Application.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.web; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } -} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java b/log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java deleted file mode 100644 index 760e26a705..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/web/GreetingController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.web; - -import java.util.concurrent.atomic.AtomicLong; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class GreetingController { - - @GetMapping("/echo") - public String echo(@RequestBody String body) { - return body; - } -} \ No newline at end of file diff --git a/log-mdc-ndc/src/main/resources/log4j.properties b/log-mdc-ndc/src/main/resources/log4j.properties index dac8abf6b8..03ae9a0c02 100644 --- a/log-mdc-ndc/src/main/resources/log4j.properties +++ b/log-mdc-ndc/src/main/resources/log4j.properties @@ -2,11 +2,13 @@ log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=/tmp/$X{transaction.owner} +log4j.appender.file.File=/tmp/baeldung.log log4j.appender.file.layout=org.apache.log4j.PatternLayout #note the %X{userName} - this is how you fetch data from Mapped Diagnostic Context (MDC) -log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n -log4j.appender.file.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n +#log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n +#log4j.appender.file.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n +log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m%n +log4j.appender.file.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m%n -log4j.rootLogger = ALL, consoleAppender, file \ No newline at end of file +log4j.rootLogger = TRACE, consoleAppender, file \ No newline at end of file From dd1679f7b0d46519c0deb5c19134e30e02c7da34 Mon Sep 17 00:00:00 2001 From: danidemi Date: Sun, 6 Nov 2016 16:30:50 +0100 Subject: [PATCH 37/86] Removed some clutter --- .../com/baeldung/mdc/BusinessService.java | 25 +++++++++++++--- .../baeldung/mdc/DefaultBusinessService.java | 19 ------------ .../com/baeldung/mdc/DelegateBusiness.java | 29 ------------------- .../com/baeldung/mdc/IBusinessService.java | 9 ++++++ .../mdc/log4j/Log4JBusinessService.java | 8 ++--- .../mdc/log4j2/Log4J2BusinessService.java | 8 ++--- .../mdc/slf4j/Slf4jBusinessService.java | 8 ++--- 7 files changed, 42 insertions(+), 64 deletions(-) delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java create mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java index 51bebeb713..a5fa940a42 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java @@ -1,9 +1,26 @@ package com.baeldung.mdc; -public interface BusinessService { +/** + * A fake {@link IBusinessService} simulating an actual one. + */ +public abstract class BusinessService implements IBusinessService { - /** Sample service transferring a given amount of money. - * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ - boolean transfer(long amount); + public boolean transfer(long amount) { + beforeTransfer(amount); + // exchange messages with a remote system to transfer the money + try { + // let's pause randomly to properly simulate an actual system. + Thread.sleep((long) (500 + Math.random() * 500)); + } catch (InterruptedException e) { + // should never happen + } + // let's simulate both failing and successful transfers + boolean outcome = Math.random() >= 0.25; + afterTransfer(amount, outcome); + return outcome; + } + abstract protected void beforeTransfer(long amount); + + abstract protected void afterTransfer(long amount, boolean outcome); } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java deleted file mode 100644 index d5bb94d21a..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DefaultBusinessService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.mdc; - -/** - * A fake {@link BusinessService} simulating an actual one. - */ -public class DefaultBusinessService implements BusinessService { - - public boolean transfer(long amount) { - try { - // let's pause randomly to properly simulate an actual system. - Thread.sleep((long) (500 + Math.random()*500)); - } catch (InterruptedException e) { - // should never happen - } - // let's simulate both failing and successful transfers - return Math.random() >= 0.25; - } - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java deleted file mode 100644 index d7aab0e284..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/DelegateBusiness.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.mdc; - -public abstract class DelegateBusiness { - - private BusinessService delegate = null; - - public DelegateBusiness(BusinessService delegate) { - super(); - this.delegate = delegate; - } - - public DelegateBusiness() { - this( new DefaultBusinessService() ); - } - - public boolean transfer(long amount) { - preTransfer(amount); - boolean outcome = delegate.transfer(amount); - postTransfer(amount, outcome); - return outcome; - } - - abstract protected void postTransfer(long amount, boolean outcome); - - abstract protected void preTransfer(long amount); - - - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java new file mode 100644 index 0000000000..a2f2fbfdb3 --- /dev/null +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java @@ -0,0 +1,9 @@ +package com.baeldung.mdc; + +public interface IBusinessService { + + /** Sample service transferring a given amount of money. + * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ + boolean transfer(long amount); + +} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java index 52439a25f7..c7d5c6904a 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java @@ -3,19 +3,19 @@ package com.baeldung.mdc.log4j; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.baeldung.mdc.DelegateBusiness; +import com.baeldung.mdc.BusinessService; -final class Log4JBusinessService extends DelegateBusiness { +class Log4JBusinessService extends BusinessService { private static final Logger logger = LogManager.getLogger(); @Override - protected void preTransfer(long amount) { + protected void beforeTransfer(long amount) { logger.info("Preparing to transfer {}$."); } @Override - protected void postTransfer(long amount, boolean outcome) { + protected void afterTransfer(long amount, boolean outcome) { logger.info("Has transfer of {}$ completed successfully ? {}."); } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java index 8e7655697e..1000b7edc2 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java @@ -2,19 +2,19 @@ package com.baeldung.mdc.log4j2; import org.apache.log4j.Logger; -import com.baeldung.mdc.DelegateBusiness; +import com.baeldung.mdc.BusinessService; -final class Log4J2BusinessService extends DelegateBusiness { +final class Log4J2BusinessService extends BusinessService { private Logger logger = Logger.getLogger(Log4J2BusinessService.class); @Override - protected void preTransfer(long amount) { + protected void beforeTransfer(long amount) { logger .info("Preparing to transfer " + amount + "$."); } @Override - protected void postTransfer(long amount, boolean outcome) { + protected void afterTransfer(long amount, boolean outcome) { logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java index af14abcf0f..b241ec4b77 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java @@ -3,19 +3,19 @@ package com.baeldung.mdc.slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.baeldung.mdc.DelegateBusiness; +import com.baeldung.mdc.BusinessService; -final class Slf4jBusinessService extends DelegateBusiness { +final class Slf4jBusinessService extends BusinessService { private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); @Override - protected void preTransfer(long amount) { + protected void beforeTransfer(long amount) { logger.info("Preparing to transfer " + amount + "$."); } @Override - protected void postTransfer(long amount, boolean outcome) { + protected void afterTransfer(long amount, boolean outcome) { logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); } From d0e95dfbdd1bb0a927fbe41436ffbdb896bc0495 Mon Sep 17 00:00:00 2001 From: danidemi Date: Sun, 6 Nov 2016 17:39:06 +0100 Subject: [PATCH 38/86] Applied formatting as defined in the rules. --- log-mdc-ndc/pom.xml | 80 +++++++++---------- .../java/com/baeldung/mdc/GenericApp.java | 35 ++++---- .../com/baeldung/mdc/TransactionFactory.java | 3 +- .../mdc/log4j/Log4JBusinessService.java | 27 +++---- .../com/baeldung/mdc/log4j/Log4JRunnable.java | 26 +++--- .../mdc/log4j2/Log4J2BusinessService.java | 27 ++++--- .../baeldung/mdc/log4j2/Log4J2Runnable.java | 34 ++++---- .../mdc/slf4j/Slf4jBusinessService.java | 22 ++--- .../com/baeldung/mdc/slf4j/Slf4jRunnable.java | 32 ++++---- .../src/main/resources/log4j.properties | 12 +-- log-mdc-ndc/src/main/resources/log4j2.xml | 39 +++------ log-mdc-ndc/src/main/resources/logback.xml | 3 +- 12 files changed, 166 insertions(+), 174 deletions(-) diff --git a/log-mdc-ndc/pom.xml b/log-mdc-ndc/pom.xml index 8e9d52a750..927473ad4e 100644 --- a/log-mdc-ndc/pom.xml +++ b/log-mdc-ndc/pom.xml @@ -6,53 +6,53 @@ 0.0.1-SNAPSHOT logmdcndc tutorial on logging with MDC and NDC - + - - - org.springframework - spring-context - 4.3.3.RELEASE - - - org.springframework - spring-webmvc - 4.3.3.RELEASE - - + + + org.springframework + spring-context + 4.3.3.RELEASE + + + org.springframework + spring-webmvc + 4.3.3.RELEASE + + log4j log4j 1.2.17 - - - - org.apache.logging.log4j - log4j-api - 2.7 - - - org.apache.logging.log4j - log4j-core - 2.7 - - - - - com.lmax - disruptor - 3.3.4 - - - - - ch.qos.logback - logback-classic - 1.1.7 - - + + + + org.apache.logging.log4j + log4j-api + 2.7 + + + org.apache.logging.log4j + log4j-core + 2.7 + + + + + com.lmax + disruptor + 3.3.4 + + + + + ch.qos.logback + logback-classic + 1.1.7 + + \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java index 3652032e0e..9f08e33455 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java @@ -6,20 +6,27 @@ import java.util.concurrent.Executors; import org.apache.log4j.Logger; import com.baeldung.mdc.log4j.Log4JRunnable; +import com.baeldung.mdc.log4j2.Log4J2Runnable; +import com.baeldung.mdc.slf4j.Slf4jRunnable; public class GenericApp { - - public static void main(String[] args) { - - ExecutorService executor = Executors.newFixedThreadPool(3); - TransactionFactory transactionFactory = new TransactionFactory(); - - for(int i=0; i<10; i++){ - final Transaction tx = transactionFactory.newInstance(); - executor.submit(new Log4JRunnable(tx)); - } - - executor.shutdown(); - - } + + public static void main(String[] args) { + + ExecutorService executor = Executors.newFixedThreadPool(3); + TransactionFactory transactionFactory = new TransactionFactory(); + + for (int i = 0; i < 10; i++) { + final Transaction tx = transactionFactory.newInstance(); + + //Runnable task = new Log4JRunnable(tx); + //Runnable task = new Log4J2Runnable(tx); + Runnable task = new Slf4jRunnable(tx); + + executor.submit(task); + } + + executor.shutdown(); + + } } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java index 26039ba1d4..2ae0b3d3f5 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java @@ -8,9 +8,10 @@ import java.util.UUID; public class TransactionFactory { private static final String[] NAMES = {"John", "Susan", "Marc", "Samantha"}; + private static long nextId = 1; public Transaction newInstance() { - String transactionId = UUID.randomUUID().toString(); + String transactionId = String.valueOf( nextId++ ); String owner = NAMES[ (int) floor(random()*NAMES.length) ]; long amount = (long) (random()*1500 + 500); Transaction tx = new Transaction(transactionId, owner, amount); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java index c7d5c6904a..26633e229e 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java @@ -1,22 +1,21 @@ package com.baeldung.mdc.log4j; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.Logger; import com.baeldung.mdc.BusinessService; -class Log4JBusinessService extends BusinessService { - - private static final Logger logger = LogManager.getLogger(); +public class Log4JBusinessService extends BusinessService { - @Override - protected void beforeTransfer(long amount) { - logger.info("Preparing to transfer {}$."); - } + private Logger logger = Logger.getLogger(Log4JBusinessService.class); + + @Override + protected void beforeTransfer(long amount) { + logger.info("Preparing to transfer " + amount + "$."); + } + + @Override + protected void afterTransfer(long amount, boolean outcome) { + logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); + } - @Override - protected void afterTransfer(long amount, boolean outcome) { - logger.info("Has transfer of {}$ completed successfully ? {}."); - } - } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java index 2aeb75f95a..ce5d97eddf 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java @@ -1,25 +1,29 @@ package com.baeldung.mdc.log4j; import org.apache.log4j.MDC; +import org.apache.logging.log4j.ThreadContext; import com.baeldung.mdc.Transaction; +import com.baeldung.mdc.log4j2.Log4J2BusinessService; public class Log4JRunnable implements Runnable { - private final Transaction tx; - public Log4JRunnable(Transaction tx) { - this.tx = tx; - } + private Transaction tx; + private static Log4JBusinessService log4jBusinessService = new Log4JBusinessService(); - public void run() { + public Log4JRunnable(Transaction tx) { + this.tx = tx; + } - MDC.put("transaction.id", tx.getTransactionId()); - MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt()); + public void run() { - new Log4JBusinessService().transfer(tx.getAmount()); + MDC.put("transaction.id", tx.getTransactionId()); + MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.createdAt", tx.getCreatedAt()); - MDC.clear(); + log4jBusinessService.transfer(tx.getAmount()); - } + MDC.clear(); + + } } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java index 1000b7edc2..cbfbc5b8a5 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java @@ -1,21 +1,22 @@ package com.baeldung.mdc.log4j2; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.baeldung.mdc.BusinessService; -final class Log4J2BusinessService extends BusinessService { - - private Logger logger = Logger.getLogger(Log4J2BusinessService.class); +public class Log4J2BusinessService extends BusinessService { - @Override - protected void beforeTransfer(long amount) { - logger .info("Preparing to transfer " + amount + "$."); - } + private static final Logger logger = LogManager.getLogger(); + + @Override + protected void beforeTransfer(long amount) { + logger.info("Preparing to transfer {}$.", amount); + } + + @Override + protected void afterTransfer(long amount, boolean outcome) { + logger.info("Has transfer of {}$ completed successfully ? {}.", amount, outcome); + } - @Override - protected void afterTransfer(long amount, boolean outcome) { - logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); - } - } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java index 32f2161af8..6a3f39ba5b 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java @@ -4,22 +4,24 @@ import org.apache.logging.log4j.ThreadContext; import com.baeldung.mdc.Transaction; -final class Log4J2Runnable implements Runnable { - private final Transaction tx; +public class Log4J2Runnable implements Runnable { + private final Transaction tx; + private Log4J2BusinessService log4j2BusinessService = new Log4J2BusinessService(); - Log4J2Runnable(Transaction tx) { - this.tx = tx; - } + public Log4J2Runnable(Transaction tx) { + this.tx = tx; + } - public void run() { - - ThreadContext.put("transaction.id", tx.getTransactionId()); - ThreadContext.put("transaction.owner", tx.getOwner()); - ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString()); - - new Log4J2BusinessService().transfer(tx.getAmount()); - - ThreadContext.clearAll(); - - } + public void run() { + + ThreadContext.put("transaction.id", tx.getTransactionId()); + ThreadContext.put("transaction.id", tx.getTransactionId()); + ThreadContext.put("transaction.owner", tx.getOwner()); + ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString()); + + log4j2BusinessService.transfer(tx.getAmount()); + + ThreadContext.clearAll(); + + } } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java index b241ec4b77..d525965ed5 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java @@ -6,17 +6,17 @@ import org.slf4j.LoggerFactory; import com.baeldung.mdc.BusinessService; final class Slf4jBusinessService extends BusinessService { - - private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); - @Override - protected void beforeTransfer(long amount) { - logger.info("Preparing to transfer " + amount + "$."); - } + private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); + + @Override + protected void beforeTransfer(long amount) { + logger.info("Preparing to transfer {}$.", amount); + } + + @Override + protected void afterTransfer(long amount, boolean outcome) { + logger.info("Has transfer of {}$ completed successfully ? {}.", amount, outcome); + } - @Override - protected void afterTransfer(long amount, boolean outcome) { - logger.info("Has transfer of " + amount + "$ completed successfully ? " + outcome + "."); - } - } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java index 938b18c257..2ef170721c 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java @@ -4,22 +4,22 @@ import org.slf4j.MDC; import com.baeldung.mdc.Transaction; -final class Slf4jRunnable implements Runnable { - private final Transaction tx; +public class Slf4jRunnable implements Runnable { + private final Transaction tx; - Slf4jRunnable(Transaction tx) { - this.tx = tx; - } + public Slf4jRunnable(Transaction tx) { + this.tx = tx; + } - public void run() { - - MDC.put("transaction.id", tx.getTransactionId()); - MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt().toString()); - - new Slf4jBusinessService().transfer(tx.getAmount()); - - MDC.clear(); - - } + public void run() { + + MDC.put("transaction.id", tx.getTransactionId()); + MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.createdAt", tx.getCreatedAt().toString()); + + new Slf4jBusinessService().transfer(tx.getAmount()); + + MDC.clear(); + + } } \ No newline at end of file diff --git a/log-mdc-ndc/src/main/resources/log4j.properties b/log-mdc-ndc/src/main/resources/log4j.properties index 03ae9a0c02..39be027f3f 100644 --- a/log-mdc-ndc/src/main/resources/log4j.properties +++ b/log-mdc-ndc/src/main/resources/log4j.properties @@ -1,14 +1,8 @@ log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=/tmp/baeldung.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout - #note the %X{userName} - this is how you fetch data from Mapped Diagnostic Context (MDC) -#log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n -#log4j.appender.file.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m - owner=%X{transaction.owner} creation=%X{transaction.createdAt}%n -log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m%n -log4j.appender.file.layout.ConversionPattern=%-4r [%t] %5p %c %x - %m%n +#log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c{1} %x - %m%n +log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %5p %c{1} %x - %m - tx.id=%X{transaction.id} tx.owner=%X{transaction.owner}%n -log4j.rootLogger = TRACE, consoleAppender, file \ No newline at end of file +log4j.rootLogger = TRACE, consoleAppender \ No newline at end of file diff --git a/log-mdc-ndc/src/main/resources/log4j2.xml b/log-mdc-ndc/src/main/resources/log4j2.xml index f9a2bdcf1a..800cfacafe 100644 --- a/log-mdc-ndc/src/main/resources/log4j2.xml +++ b/log-mdc-ndc/src/main/resources/log4j2.xml @@ -1,32 +1,17 @@ - - # Console appender - - # Pattern of log message for console appender - - + + + + + - # File appender - - + + - - # Override log level for specified package - - - - - - - + + + + \ No newline at end of file diff --git a/log-mdc-ndc/src/main/resources/logback.xml b/log-mdc-ndc/src/main/resources/logback.xml index 7bea9976e7..44d247c87e 100644 --- a/log-mdc-ndc/src/main/resources/logback.xml +++ b/log-mdc-ndc/src/main/resources/logback.xml @@ -1,9 +1,8 @@ - # Console appender - logback %d{yyyy-MM-dd HH:mm:ss} %p %m %X{transaction.owner} %X{transaction.createdAt} %n + %-4r [%t] %5p %c{1} - %m - tx.id=%X{transaction.id} tx.owner=%X{transaction.owner}%n From b9c3710c56544da328655b27ead3b6e6df02bac8 Mon Sep 17 00:00:00 2001 From: Kiran Date: Sun, 6 Nov 2016 21:38:08 -0500 Subject: [PATCH 39/86] Added code for new module --- .../spring-cloud-ribbon-client/pom.xml | 79 +++++++++++++++++++ .../ribbon/client/RibbonConfiguration.java | 28 +++++++ .../ribbon/client/ServerLocationApp.java | 36 +++++++++ .../src/main/resources/application.yml | 13 +++ .../ribbon/client/ServerLocationAppTests.java | 54 +++++++++++++ .../cloud/ribbon/client/TestConfig.java | 17 ++++ 6 files changed, 227 insertions(+) create mode 100644 spring-cloud/spring-cloud-ribbon-client/pom.xml create mode 100644 spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/RibbonConfiguration.java create mode 100644 spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationApp.java create mode 100644 spring-cloud/spring-cloud-ribbon-client/src/main/resources/application.yml create mode 100644 spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationAppTests.java create mode 100644 spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/TestConfig.java diff --git a/spring-cloud/spring-cloud-ribbon-client/pom.xml b/spring-cloud/spring-cloud-ribbon-client/pom.xml new file mode 100644 index 0000000000..c597c5ab8e --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-client/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + com.baeldung + spring-cloud-ribbon + 0.0.1-SNAPSHOT + jar + spring-cloud-ribbon-client + Introduction to Spring Cloud Rest Client with Netflix Ribbon + + + org.springframework.boot + spring-boot-starter-parent + 1.4.1.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-ribbon + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Camden.SR1 + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/RibbonConfiguration.java b/spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/RibbonConfiguration.java new file mode 100644 index 0000000000..59998432ad --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/RibbonConfiguration.java @@ -0,0 +1,28 @@ +package com.baeldung.spring.cloud.ribbon.client; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; + +import com.netflix.client.config.IClientConfig; +import com.netflix.loadbalancer.IPing; +import com.netflix.loadbalancer.IRule; +import com.netflix.loadbalancer.PingUrl; +import com.netflix.loadbalancer.WeightedResponseTimeRule; +import com.netflix.loadbalancer.AvailabilityFilteringRule; + +public class RibbonConfiguration { + + @Autowired + IClientConfig ribbonClientConfig; + + @Bean + public IPing ribbonPing(IClientConfig config) { + return new PingUrl(); + } + + @Bean + public IRule ribbonRule(IClientConfig config) { + return new WeightedResponseTimeRule(); + } + +} diff --git a/spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationApp.java b/spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationApp.java new file mode 100644 index 0000000000..6105e2c489 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-client/src/main/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationApp.java @@ -0,0 +1,36 @@ +package com.baeldung.spring.cloud.ribbon.client; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.ribbon.RibbonClient; +import org.springframework.context.annotation.Bean; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@SpringBootApplication +@RestController +@RibbonClient(name = "ping-a-server", configuration = RibbonConfiguration.class) +public class ServerLocationApp { + + @LoadBalanced + @Bean + RestTemplate getRestTemplate() { + return new RestTemplate(); + } + + @Autowired + RestTemplate restTemplate; + + @RequestMapping("/server-location") + public String serverLocation() { + String servLoc = this.restTemplate.getForObject("http://ping-server/locaus", String.class); + return servLoc; + } + + public static void main(String[] args) { + SpringApplication.run(ServerLocationApp.class, args); + } +} diff --git a/spring-cloud/spring-cloud-ribbon-client/src/main/resources/application.yml b/spring-cloud/spring-cloud-ribbon-client/src/main/resources/application.yml new file mode 100644 index 0000000000..189a923c6c --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-client/src/main/resources/application.yml @@ -0,0 +1,13 @@ +spring: + application: + name: spring-cloud-ribbon + +server: + port: 8888 + +ping-server: + ribbon: + eureka: + enabled: false + listOfServers: localhost:9092,localhost:9999 + ServerListRefreshInterval: 15000 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationAppTests.java b/spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationAppTests.java new file mode 100644 index 0000000000..b3606537a2 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/ServerLocationAppTests.java @@ -0,0 +1,54 @@ +package com.baeldung.spring.cloud.ribbon.client; + +import static org.assertj.core.api.BDDAssertions.then; +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@SuppressWarnings("unused") +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ServerLocationApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class ServerLocationAppTests { + ConfigurableApplicationContext application2; + ConfigurableApplicationContext application3; + + @Before + public void startApps() { + this.application2 = startApp(9092); + this.application3 = startApp(9999); + } + + @After + public void closeApps() { + this.application2.close(); + this.application3.close(); + } + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate testRestTemplate; + + @Test + public void loadBalancingServersTest() throws InterruptedException { + ResponseEntity response = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/server-location", String.class); + assertEquals(response.getBody(), "Australia"); + } + + private ConfigurableApplicationContext startApp(int port) { + return SpringApplication.run(TestConfig.class, "--server.port=" + port, "--spring.jmx.enabled=false"); + } +} diff --git a/spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/TestConfig.java b/spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/TestConfig.java new file mode 100644 index 0000000000..886b28a32e --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-client/src/test/java/com/baeldung/spring/cloud/ribbon/client/TestConfig.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.cloud.ribbon.client; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Configuration +@EnableAutoConfiguration +@RestController +public class TestConfig { + + @RequestMapping(value = "/locaus") + public String locationAUSDetails() { + return "Australia"; + } +} From b7de8a08f453bd676a4f9acefe65add54837291e Mon Sep 17 00:00:00 2001 From: Kiran Date: Sun, 6 Nov 2016 21:39:24 -0500 Subject: [PATCH 40/86] Updated pom.xml added new module "spring-cloud-ribbon-client" --- spring-cloud/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 2349613def..455a5b876b 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -11,6 +11,7 @@ spring-cloud-eureka spring-cloud-hystrix spring-cloud-bootstrap + spring-cloud-ribbon-client pom From d07908f71b2572dfd49c3bafe51440f08992aeb4 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 7 Nov 2016 21:07:06 +0200 Subject: [PATCH 41/86] add source code for Facebook login --- spring-social-login/pom.xml | 169 ++++++++++++++++++ .../java/org/baeldung/config/Application.java | 18 ++ .../org/baeldung/config/SecurityConfig.java | 61 +++++++ .../java/org/baeldung/config/WebConfig.java | 39 ++++ .../persistence/dao/UserRepository.java | 10 ++ .../org/baeldung/persistence/model/User.java | 55 ++++++ .../security/FacebookConnectionSignup.java | 28 +++ .../security/FacebookSignInAdapter.java | 21 +++ .../security/MyUserDetailsService.java | 34 ++++ .../src/main/resources/application.properties | 3 + .../src/main/resources/data.sql | 1 + .../src/main/resources/templates/index.html | 27 +++ .../src/main/resources/templates/login.html | 44 +++++ .../test/ApplicationIntegrationTest.java | 18 ++ 14 files changed, 528 insertions(+) create mode 100644 spring-social-login/pom.xml create mode 100644 spring-social-login/src/main/java/org/baeldung/config/Application.java create mode 100644 spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java create mode 100644 spring-social-login/src/main/java/org/baeldung/config/WebConfig.java create mode 100644 spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java create mode 100644 spring-social-login/src/main/java/org/baeldung/persistence/model/User.java create mode 100644 spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java create mode 100644 spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java create mode 100644 spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java create mode 100644 spring-social-login/src/main/resources/application.properties create mode 100644 spring-social-login/src/main/resources/data.sql create mode 100644 spring-social-login/src/main/resources/templates/index.html create mode 100644 spring-social-login/src/main/resources/templates/login.html create mode 100644 spring-social-login/src/test/java/org/baeldung/test/ApplicationIntegrationTest.java diff --git a/spring-social-login/pom.xml b/spring-social-login/pom.xml new file mode 100644 index 0000000000..6e74b1c3d1 --- /dev/null +++ b/spring-social-login/pom.xml @@ -0,0 +1,169 @@ + + 4.0.0 + spring-social-login + + spring-social-login + war + + + org.springframework.boot + spring-boot-starter-parent + 1.4.0.RELEASE + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + + org.springframework.security + spring-security-web + + + + org.springframework.security + spring-security-config + + + + org.springframework.security + spring-security-taglibs + + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity4 + + + + + org.springframework.social + spring-social-facebook + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.h2database + h2 + + + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework + spring-test + test + + + + junit + junit + test + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + + + spring-social-login + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-war-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + + + 1.8 + 3.3.2 + + + \ No newline at end of file diff --git a/spring-social-login/src/main/java/org/baeldung/config/Application.java b/spring-social-login/src/main/java/org/baeldung/config/Application.java new file mode 100644 index 0000000000..cf6251a51e --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/config/Application.java @@ -0,0 +1,18 @@ +package org.baeldung.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication +@EnableJpaRepositories("org.baeldung.persistence.dao") +@EntityScan("org.baeldung.persistence.model") +public class Application extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file diff --git a/spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java b/spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java new file mode 100644 index 0000000000..8e439653a9 --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java @@ -0,0 +1,61 @@ +package org.baeldung.config; + +import org.baeldung.security.FacebookSignInAdapter; +import org.baeldung.security.FacebookConnectionSignup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.social.connect.ConnectionFactoryLocator; +import org.springframework.social.connect.UsersConnectionRepository; +import org.springframework.social.connect.mem.InMemoryUsersConnectionRepository; +import org.springframework.social.connect.web.ProviderSignInController; + +@Configuration +@EnableWebSecurity +@ComponentScan(basePackages = { "org.baeldung.security" }) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private UserDetailsService userDetailsService; + + @Autowired + private ConnectionFactoryLocator connectionFactoryLocator; + + @Autowired + private UsersConnectionRepository usersConnectionRepository; + + @Autowired + private FacebookConnectionSignup facebookConnectionSignup; + + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService); + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + // @formatter:off + http + .csrf().disable() + .authorizeRequests() + .antMatchers("/login*","/signin/**","/signup/**").permitAll() + .anyRequest().authenticated() + .and() + .formLogin().loginPage("/login").permitAll() + .and() + .logout(); + } // @formatter:on + + @Bean + // @Primary + public ProviderSignInController providerSignInController() { + ((InMemoryUsersConnectionRepository) usersConnectionRepository).setConnectionSignUp(facebookConnectionSignup); + return new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, new FacebookSignInAdapter()); + } +} \ No newline at end of file diff --git a/spring-social-login/src/main/java/org/baeldung/config/WebConfig.java b/spring-social-login/src/main/java/org/baeldung/config/WebConfig.java new file mode 100644 index 0000000000..8cfcd6cb41 --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/config/WebConfig.java @@ -0,0 +1,39 @@ +package org.baeldung.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableWebMvc +public class WebConfig extends WebMvcConfigurerAdapter { + + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + + @Override + public void configureDefaultServletHandling(final DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + registry.addViewController("/").setViewName("forward:/index"); + registry.addViewController("/index"); + registry.addViewController("/login"); + } + + @Override + public void addResourceHandlers(final ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + +} \ No newline at end of file diff --git a/spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java b/spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java new file mode 100644 index 0000000000..679dd6c363 --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java @@ -0,0 +1,10 @@ +package org.baeldung.persistence.dao; + +import org.baeldung.persistence.model.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { + + User findByUsername(final String username); + +} diff --git a/spring-social-login/src/main/java/org/baeldung/persistence/model/User.java b/spring-social-login/src/main/java/org/baeldung/persistence/model/User.java new file mode 100644 index 0000000000..a4cffc27d0 --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/persistence/model/User.java @@ -0,0 +1,55 @@ +package org.baeldung.persistence.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Column(nullable = false, unique = true) + private String username; + + private String password; + + public User() { + super(); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("User [id=").append(id).append(", username=").append(username).append(", password=").append(password).append("]"); + return builder.toString(); + } + +} diff --git a/spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java b/spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java new file mode 100644 index 0000000000..6a9e30d7d8 --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java @@ -0,0 +1,28 @@ +package org.baeldung.security; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; + +import org.baeldung.persistence.dao.UserRepository; +import org.baeldung.persistence.model.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.social.connect.Connection; +import org.springframework.social.connect.ConnectionSignUp; +import org.springframework.stereotype.Service; + +@Service +public class FacebookConnectionSignup implements ConnectionSignUp { + + @Autowired + private UserRepository userRepository; + + @Override + public String execute(Connection connection) { + System.out.println("signup === "); + final User user = new User(); + user.setUsername(connection.getDisplayName()); + user.setPassword(randomAlphabetic(8)); + userRepository.save(user); + return user.getUsername(); + } + +} diff --git a/spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java b/spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java new file mode 100644 index 0000000000..b861609a01 --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java @@ -0,0 +1,21 @@ +package org.baeldung.security; + +import java.util.Arrays; + +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.social.connect.Connection; +import org.springframework.social.connect.web.SignInAdapter; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.NativeWebRequest; + +@Service +public class FacebookSignInAdapter implements SignInAdapter { + @Override + public String signIn(String localUserId, Connection connection, NativeWebRequest request) { + System.out.println(" ====== Sign In adapter"); + SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(connection.getDisplayName(), null, Arrays.asList(new SimpleGrantedAuthority("FACEBOOK_USER")))); + return null; + } +} diff --git a/spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java b/spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java new file mode 100644 index 0000000000..5d0d5d793a --- /dev/null +++ b/spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java @@ -0,0 +1,34 @@ +package org.baeldung.security; + +import java.util.Arrays; + +import org.baeldung.persistence.dao.UserRepository; +import org.baeldung.persistence.model.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service +public class MyUserDetailsService implements UserDetailsService { + + @Autowired + private UserRepository userRepository; + + public MyUserDetailsService() { + super(); + } + + // API + + @Override + public UserDetails loadUserByUsername(final String username) { + final User user = userRepository.findByUsername(username); + if (user == null) { + throw new UsernameNotFoundException(username); + } + return new org.springframework.security.core.userdetails.User(username, user.getPassword(), true, true, true, true, Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"))); + } +} diff --git a/spring-social-login/src/main/resources/application.properties b/spring-social-login/src/main/resources/application.properties new file mode 100644 index 0000000000..2bd99d8239 --- /dev/null +++ b/spring-social-login/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.social.facebook.appId=1715784745414888 +spring.social.facebook.appSecret=abefd6497e9cc01ad03be28509617bf0 +spring.thymeleaf.cache=false \ No newline at end of file diff --git a/spring-social-login/src/main/resources/data.sql b/spring-social-login/src/main/resources/data.sql new file mode 100644 index 0000000000..3b26afef32 --- /dev/null +++ b/spring-social-login/src/main/resources/data.sql @@ -0,0 +1 @@ +insert into User (id, username, password) values (1,'john', '123'); \ No newline at end of file diff --git a/spring-social-login/src/main/resources/templates/index.html b/spring-social-login/src/main/resources/templates/index.html new file mode 100644 index 0000000000..8e1a8da60f --- /dev/null +++ b/spring-social-login/src/main/resources/templates/index.html @@ -0,0 +1,27 @@ + + + + +Spring Social Login + + + + + + +
+

Welcome, Username

+

User authorities

+
+ + \ No newline at end of file diff --git a/spring-social-login/src/main/resources/templates/login.html b/spring-social-login/src/main/resources/templates/login.html new file mode 100644 index 0000000000..41ad39332c --- /dev/null +++ b/spring-social-login/src/main/resources/templates/login.html @@ -0,0 +1,44 @@ + + + + +Spring Social Login + + + +
+
You have been logged out
+
There was an error, please try again
+ +

Login

+
+
+
+ + +
+
+
+ + +
+ +
+ +
+
+
+
+
+
+
+
+ + +
+
+ + +
+ + \ No newline at end of file diff --git a/spring-social-login/src/test/java/org/baeldung/test/ApplicationIntegrationTest.java b/spring-social-login/src/test/java/org/baeldung/test/ApplicationIntegrationTest.java new file mode 100644 index 0000000000..43aaea18b1 --- /dev/null +++ b/spring-social-login/src/test/java/org/baeldung/test/ApplicationIntegrationTest.java @@ -0,0 +1,18 @@ +package org.baeldung.test; + +import org.baeldung.config.Application; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT) +public class ApplicationIntegrationTest { + + @Test + public void whenLoadApplication_thenSuccess() { + + } +} From 48f5fdb8e99bcca2e60abb9138073478f9f2c781 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 7 Nov 2016 21:12:50 +0100 Subject: [PATCH 42/86] Cleanup OkHttpGetLiveTest --- .../baeldung/okhttp/OkHttpGetLiveTest.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java index 632d7577a4..9bf57c41b2 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java @@ -1,23 +1,14 @@ package org.baeldung.okhttp; +import okhttp3.*; +import org.junit.Test; + +import java.io.IOException; + import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.IOException; - -import org.junit.Test; - -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -//@RunWith(SpringJUnit4ClassRunner.class) -//@WebAppConfiguration -//@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/api-servlet.xml") public class OkHttpGetLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; From 9ae723f5ab04cfe9826c6524e10a0d4165c4b409 Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 7 Nov 2016 21:21:28 +0100 Subject: [PATCH 43/86] Removed redundant interface --- .../com/baeldung/mdc/IBusinessService.java | 9 ---- .../java/com/baeldung/mdc/Transaction.java | 50 ++++++++----------- ...inessService.java => TransferService.java} | 4 +- .../mdc/log4j/Log4JBusinessService.java | 4 +- .../com/baeldung/mdc/log4j/Log4JRunnable.java | 3 -- .../mdc/log4j2/Log4J2BusinessService.java | 4 +- .../baeldung/mdc/log4j2/Log4J2Runnable.java | 2 - .../mdc/slf4j/Slf4jBusinessService.java | 4 +- .../com/baeldung/mdc/slf4j/Slf4jRunnable.java | 1 - 9 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java rename log-mdc-ndc/src/main/java/com/baeldung/mdc/{BusinessService.java => TransferService.java} (80%) diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java deleted file mode 100644 index a2f2fbfdb3..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.mdc; - -public interface IBusinessService { - - /** Sample service transferring a given amount of money. - * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ - boolean transfer(long amount); - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java index ac0fe75ac5..1a038512c0 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java @@ -1,35 +1,27 @@ package com.baeldung.mdc; -import java.util.Date; - public class Transaction { - - private String transactionId; - private String owner; - private Date createdAt; - private Long amount; - - public Transaction(String transactionId, String owner, long amount) { - this.transactionId = transactionId; - this.owner = owner; - this.createdAt = new Date(); - this.amount = amount; - } - public String getOwner() { - return owner; - } + private String transactionId; + private String owner; + private Long amount; + + public Transaction(String transactionId, String owner, long amount) { + this.transactionId = transactionId; + this.owner = owner; + this.amount = amount; + } + + public String getOwner() { + return owner; + } + + public String getTransactionId() { + return transactionId; + } + + public Long getAmount() { + return amount; + } - public String getTransactionId() { - return transactionId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public Long getAmount() { - return amount; - } - } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java similarity index 80% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java index a5fa940a42..7ab53043d3 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java @@ -3,8 +3,10 @@ package com.baeldung.mdc; /** * A fake {@link IBusinessService} simulating an actual one. */ -public abstract class BusinessService implements IBusinessService { +public abstract class TransferService { + /** Sample service transferring a given amount of money. + * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ public boolean transfer(long amount) { beforeTransfer(amount); // exchange messages with a remote system to transfer the money diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java index 26633e229e..d8b3a15cc2 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java @@ -2,9 +2,9 @@ package com.baeldung.mdc.log4j; import org.apache.log4j.Logger; -import com.baeldung.mdc.BusinessService; +import com.baeldung.mdc.TransferService; -public class Log4JBusinessService extends BusinessService { +public class Log4JBusinessService extends TransferService { private Logger logger = Logger.getLogger(Log4JBusinessService.class); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java index ce5d97eddf..817eee1e3c 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java @@ -1,10 +1,8 @@ package com.baeldung.mdc.log4j; import org.apache.log4j.MDC; -import org.apache.logging.log4j.ThreadContext; import com.baeldung.mdc.Transaction; -import com.baeldung.mdc.log4j2.Log4J2BusinessService; public class Log4JRunnable implements Runnable { @@ -19,7 +17,6 @@ public class Log4JRunnable implements Runnable { MDC.put("transaction.id", tx.getTransactionId()); MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt()); log4jBusinessService.transfer(tx.getAmount()); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java index cbfbc5b8a5..66a554ff65 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java @@ -3,9 +3,9 @@ package com.baeldung.mdc.log4j2; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.baeldung.mdc.BusinessService; +import com.baeldung.mdc.TransferService; -public class Log4J2BusinessService extends BusinessService { +public class Log4J2BusinessService extends TransferService { private static final Logger logger = LogManager.getLogger(); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java index 6a3f39ba5b..d76f1346e2 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java @@ -14,10 +14,8 @@ public class Log4J2Runnable implements Runnable { public void run() { - ThreadContext.put("transaction.id", tx.getTransactionId()); ThreadContext.put("transaction.id", tx.getTransactionId()); ThreadContext.put("transaction.owner", tx.getOwner()); - ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString()); log4j2BusinessService.transfer(tx.getAmount()); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java index d525965ed5..6cd2df6b46 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java @@ -3,9 +3,9 @@ package com.baeldung.mdc.slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.baeldung.mdc.BusinessService; +import com.baeldung.mdc.TransferService; -final class Slf4jBusinessService extends BusinessService { +final class Slf4jBusinessService extends TransferService { private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java index 2ef170721c..61bf2c0743 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java @@ -15,7 +15,6 @@ public class Slf4jRunnable implements Runnable { MDC.put("transaction.id", tx.getTransactionId()); MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt().toString()); new Slf4jBusinessService().transfer(tx.getAmount()); From b27a8cff06b5298022f5b3a991ec87d78af1594a Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 7 Nov 2016 22:44:09 +0100 Subject: [PATCH 44/86] Renaming following article review --- .../java/com/baeldung/mdc/TransactionFactory.java | 4 ++-- .../baeldung/mdc/{Transaction.java => Transfer.java} | 12 ++++++------ .../mdc/{GenericApp.java => TransferDemo.java} | 4 ++-- .../main/java/com/baeldung/mdc/TransferService.java | 2 +- .../java/com/baeldung/mdc/log4j/Log4JRunnable.java | 10 +++++----- ...usinessService.java => Log4JTransferService.java} | 4 ++-- .../java/com/baeldung/mdc/log4j2/Log4J2Runnable.java | 10 +++++----- ...sinessService.java => Log4J2TransferService.java} | 2 +- ...BusinessService.java => Slf4TransferService.java} | 4 ++-- .../java/com/baeldung/mdc/slf4j/Slf4jRunnable.java | 10 +++++----- 10 files changed, 31 insertions(+), 31 deletions(-) rename log-mdc-ndc/src/main/java/com/baeldung/mdc/{Transaction.java => Transfer.java} (60%) rename log-mdc-ndc/src/main/java/com/baeldung/mdc/{GenericApp.java => TransferDemo.java} (89%) rename log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/{Log4JBusinessService.java => Log4JTransferService.java} (77%) rename log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/{Log4J2BusinessService.java => Log4J2TransferService.java} (89%) rename log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/{Slf4jBusinessService.java => Slf4TransferService.java} (85%) diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java index 2ae0b3d3f5..ec1887eea6 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java @@ -10,11 +10,11 @@ public class TransactionFactory { private static final String[] NAMES = {"John", "Susan", "Marc", "Samantha"}; private static long nextId = 1; - public Transaction newInstance() { + public Transfer newInstance() { String transactionId = String.valueOf( nextId++ ); String owner = NAMES[ (int) floor(random()*NAMES.length) ]; long amount = (long) (random()*1500 + 500); - Transaction tx = new Transaction(transactionId, owner, amount); + Transfer tx = new Transfer(transactionId, owner, amount); return tx; } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transfer.java similarity index 60% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/Transfer.java index 1a038512c0..1a27fe4eec 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transfer.java @@ -1,19 +1,19 @@ package com.baeldung.mdc; -public class Transaction { +public class Transfer { private String transactionId; - private String owner; + private String sender; private Long amount; - public Transaction(String transactionId, String owner, long amount) { + public Transfer(String transactionId, String sender, long amount) { this.transactionId = transactionId; - this.owner = owner; + this.sender = sender; this.amount = amount; } - public String getOwner() { - return owner; + public String getSender() { + return sender; } public String getTransactionId() { diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferDemo.java similarity index 89% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferDemo.java index 9f08e33455..daf256007c 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/GenericApp.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferDemo.java @@ -9,7 +9,7 @@ import com.baeldung.mdc.log4j.Log4JRunnable; import com.baeldung.mdc.log4j2.Log4J2Runnable; import com.baeldung.mdc.slf4j.Slf4jRunnable; -public class GenericApp { +public class TransferDemo { public static void main(String[] args) { @@ -17,7 +17,7 @@ public class GenericApp { TransactionFactory transactionFactory = new TransactionFactory(); for (int i = 0; i < 10; i++) { - final Transaction tx = transactionFactory.newInstance(); + Transfer tx = transactionFactory.newInstance(); //Runnable task = new Log4JRunnable(tx); //Runnable task = new Log4J2Runnable(tx); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java index 7ab53043d3..95e7d38630 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java @@ -1,7 +1,7 @@ package com.baeldung.mdc; /** - * A fake {@link IBusinessService} simulating an actual one. + * A fake transfer service simulating an actual one. */ public abstract class TransferService { diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java index 817eee1e3c..7711795a59 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java @@ -2,21 +2,21 @@ package com.baeldung.mdc.log4j; import org.apache.log4j.MDC; -import com.baeldung.mdc.Transaction; +import com.baeldung.mdc.Transfer; public class Log4JRunnable implements Runnable { - private Transaction tx; - private static Log4JBusinessService log4jBusinessService = new Log4JBusinessService(); + private Transfer tx; + private static Log4JTransferService log4jBusinessService = new Log4JTransferService(); - public Log4JRunnable(Transaction tx) { + public Log4JRunnable(Transfer tx) { this.tx = tx; } public void run() { MDC.put("transaction.id", tx.getTransactionId()); - MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.owner", tx.getSender()); log4jBusinessService.transfer(tx.getAmount()); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java similarity index 77% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java index d8b3a15cc2..a8bfe7957a 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java @@ -4,9 +4,9 @@ import org.apache.log4j.Logger; import com.baeldung.mdc.TransferService; -public class Log4JBusinessService extends TransferService { +public class Log4JTransferService extends TransferService { - private Logger logger = Logger.getLogger(Log4JBusinessService.class); + private Logger logger = Logger.getLogger(Log4JTransferService.class); @Override protected void beforeTransfer(long amount) { diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java index d76f1346e2..0b7f516bd1 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java @@ -2,20 +2,20 @@ package com.baeldung.mdc.log4j2; import org.apache.logging.log4j.ThreadContext; -import com.baeldung.mdc.Transaction; +import com.baeldung.mdc.Transfer; public class Log4J2Runnable implements Runnable { - private final Transaction tx; - private Log4J2BusinessService log4j2BusinessService = new Log4J2BusinessService(); + private final Transfer tx; + private Log4J2TransferService log4j2BusinessService = new Log4J2TransferService(); - public Log4J2Runnable(Transaction tx) { + public Log4J2Runnable(Transfer tx) { this.tx = tx; } public void run() { ThreadContext.put("transaction.id", tx.getTransactionId()); - ThreadContext.put("transaction.owner", tx.getOwner()); + ThreadContext.put("transaction.owner", tx.getSender()); log4j2BusinessService.transfer(tx.getAmount()); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java similarity index 89% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java index 66a554ff65..fb6eeccc9e 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java @@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger; import com.baeldung.mdc.TransferService; -public class Log4J2BusinessService extends TransferService { +public class Log4J2TransferService extends TransferService { private static final Logger logger = LogManager.getLogger(); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java similarity index 85% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java index 6cd2df6b46..f4df150a6a 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java @@ -5,9 +5,9 @@ import org.slf4j.LoggerFactory; import com.baeldung.mdc.TransferService; -final class Slf4jBusinessService extends TransferService { +final class Slf4TransferService extends TransferService { - private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); + private static final Logger logger = LoggerFactory.getLogger(Slf4TransferService.class); @Override protected void beforeTransfer(long amount) { diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java index 61bf2c0743..e30a28a3c7 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java @@ -2,21 +2,21 @@ package com.baeldung.mdc.slf4j; import org.slf4j.MDC; -import com.baeldung.mdc.Transaction; +import com.baeldung.mdc.Transfer; public class Slf4jRunnable implements Runnable { - private final Transaction tx; + private final Transfer tx; - public Slf4jRunnable(Transaction tx) { + public Slf4jRunnable(Transfer tx) { this.tx = tx; } public void run() { MDC.put("transaction.id", tx.getTransactionId()); - MDC.put("transaction.owner", tx.getOwner()); + MDC.put("transaction.owner", tx.getSender()); - new Slf4jBusinessService().transfer(tx.getAmount()); + new Slf4TransferService().transfer(tx.getAmount()); MDC.clear(); From 4e3f9fa626839f6b1f50abc9c147cad0a1e84757 Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 7 Nov 2016 23:06:36 +0100 Subject: [PATCH 45/86] Demos are run with JUnit --- {log-mdc-ndc => log-mdc}/README.md | 0 {log-mdc-ndc => log-mdc}/pom.xml | 8 +++++ .../com/baeldung/mdc/TransactionFactory.java | 0 .../main/java/com/baeldung/mdc/Transfer.java | 0 .../java/com/baeldung/mdc/TransferDemo.java | 0 .../com/baeldung/mdc/TransferService.java | 0 .../com/baeldung/mdc/log4j/Log4JRunnable.java | 0 .../mdc/log4j/Log4JTransferService.java | 0 .../baeldung/mdc/log4j2/Log4J2Runnable.java | 0 .../mdc/log4j2/Log4J2TransferService.java | 0 .../mdc/slf4j/Slf4TransferService.java | 0 .../com/baeldung/mdc/slf4j/Slf4jRunnable.java | 0 .../src/main/resources/log4j.properties | 0 .../src/main/resources/log4j2.xml | 0 .../src/main/resources/logback.xml | 0 .../java/com/baeldung/mdc/log4j/Demo.java | 26 ++++++++++++++++ .../java/com/baeldung/mdc/log4j2/Demo.java | 30 +++++++++++++++++++ .../java/com/baeldung/mdc/slf4j/Demo.java | 30 +++++++++++++++++++ 18 files changed, 94 insertions(+) rename {log-mdc-ndc => log-mdc}/README.md (100%) rename {log-mdc-ndc => log-mdc}/pom.xml (90%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/TransactionFactory.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/Transfer.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/TransferDemo.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/TransferService.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java (100%) rename {log-mdc-ndc => log-mdc}/src/main/resources/log4j.properties (100%) rename {log-mdc-ndc => log-mdc}/src/main/resources/log4j2.xml (100%) rename {log-mdc-ndc => log-mdc}/src/main/resources/logback.xml (100%) create mode 100644 log-mdc/src/test/java/com/baeldung/mdc/log4j/Demo.java create mode 100644 log-mdc/src/test/java/com/baeldung/mdc/log4j2/Demo.java create mode 100644 log-mdc/src/test/java/com/baeldung/mdc/slf4j/Demo.java diff --git a/log-mdc-ndc/README.md b/log-mdc/README.md similarity index 100% rename from log-mdc-ndc/README.md rename to log-mdc/README.md diff --git a/log-mdc-ndc/pom.xml b/log-mdc/pom.xml similarity index 90% rename from log-mdc-ndc/pom.xml rename to log-mdc/pom.xml index 927473ad4e..a6e9414dc5 100644 --- a/log-mdc-ndc/pom.xml +++ b/log-mdc/pom.xml @@ -52,6 +52,14 @@ logback-classic 1.1.7
+ + + junit + junit + 4.12 + test + +
diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java b/log-mdc/src/main/java/com/baeldung/mdc/TransactionFactory.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/TransactionFactory.java rename to log-mdc/src/main/java/com/baeldung/mdc/TransactionFactory.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transfer.java b/log-mdc/src/main/java/com/baeldung/mdc/Transfer.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/Transfer.java rename to log-mdc/src/main/java/com/baeldung/mdc/Transfer.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferDemo.java b/log-mdc/src/main/java/com/baeldung/mdc/TransferDemo.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferDemo.java rename to log-mdc/src/main/java/com/baeldung/mdc/TransferDemo.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java b/log-mdc/src/main/java/com/baeldung/mdc/TransferService.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java rename to log-mdc/src/main/java/com/baeldung/mdc/TransferService.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java b/log-mdc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java rename to log-mdc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java b/log-mdc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java rename to log-mdc/src/main/java/com/baeldung/mdc/log4j/Log4JTransferService.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java b/log-mdc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java rename to log-mdc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java b/log-mdc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java rename to log-mdc/src/main/java/com/baeldung/mdc/log4j2/Log4J2TransferService.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java b/log-mdc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java rename to log-mdc/src/main/java/com/baeldung/mdc/slf4j/Slf4TransferService.java diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java b/log-mdc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java similarity index 100% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java rename to log-mdc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java diff --git a/log-mdc-ndc/src/main/resources/log4j.properties b/log-mdc/src/main/resources/log4j.properties similarity index 100% rename from log-mdc-ndc/src/main/resources/log4j.properties rename to log-mdc/src/main/resources/log4j.properties diff --git a/log-mdc-ndc/src/main/resources/log4j2.xml b/log-mdc/src/main/resources/log4j2.xml similarity index 100% rename from log-mdc-ndc/src/main/resources/log4j2.xml rename to log-mdc/src/main/resources/log4j2.xml diff --git a/log-mdc-ndc/src/main/resources/logback.xml b/log-mdc/src/main/resources/logback.xml similarity index 100% rename from log-mdc-ndc/src/main/resources/logback.xml rename to log-mdc/src/main/resources/logback.xml diff --git a/log-mdc/src/test/java/com/baeldung/mdc/log4j/Demo.java b/log-mdc/src/test/java/com/baeldung/mdc/log4j/Demo.java new file mode 100644 index 0000000000..f9a210606f --- /dev/null +++ b/log-mdc/src/test/java/com/baeldung/mdc/log4j/Demo.java @@ -0,0 +1,26 @@ +package com.baeldung.mdc.log4j; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; + +import com.baeldung.mdc.TransactionFactory; +import com.baeldung.mdc.Transfer; + +public class Demo { + + @Test + public void main() throws InterruptedException { + ExecutorService executor = Executors.newFixedThreadPool(3); + TransactionFactory transactionFactory = new TransactionFactory(); + for (int i = 0; i < 10; i++) { + Transfer tx = transactionFactory.newInstance(); + Runnable task = new Log4JRunnable(tx); + executor.submit(task); + } + executor.shutdown(); + executor.awaitTermination(60, TimeUnit.SECONDS); + } +} diff --git a/log-mdc/src/test/java/com/baeldung/mdc/log4j2/Demo.java b/log-mdc/src/test/java/com/baeldung/mdc/log4j2/Demo.java new file mode 100644 index 0000000000..3f7c1d37d5 --- /dev/null +++ b/log-mdc/src/test/java/com/baeldung/mdc/log4j2/Demo.java @@ -0,0 +1,30 @@ +package com.baeldung.mdc.log4j2; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.junit.Test; + +import com.baeldung.mdc.TransactionFactory; +import com.baeldung.mdc.Transfer; +import com.baeldung.mdc.log4j.Log4JRunnable; +import com.baeldung.mdc.log4j2.Log4J2Runnable; +import com.baeldung.mdc.slf4j.Slf4jRunnable; + +public class Demo { + + @Test + public void main() throws InterruptedException { + ExecutorService executor = Executors.newFixedThreadPool(3); + TransactionFactory transactionFactory = new TransactionFactory(); + for (int i = 0; i < 10; i++) { + Transfer tx = transactionFactory.newInstance(); + Runnable task = new Log4J2Runnable(tx); + executor.submit(task); + } + executor.shutdown(); + executor.awaitTermination(60, TimeUnit.SECONDS); + } +} diff --git a/log-mdc/src/test/java/com/baeldung/mdc/slf4j/Demo.java b/log-mdc/src/test/java/com/baeldung/mdc/slf4j/Demo.java new file mode 100644 index 0000000000..98db698f47 --- /dev/null +++ b/log-mdc/src/test/java/com/baeldung/mdc/slf4j/Demo.java @@ -0,0 +1,30 @@ +package com.baeldung.mdc.slf4j; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.junit.Test; + +import com.baeldung.mdc.TransactionFactory; +import com.baeldung.mdc.Transfer; +import com.baeldung.mdc.log4j.Log4JRunnable; +import com.baeldung.mdc.log4j2.Log4J2Runnable; +import com.baeldung.mdc.slf4j.Slf4jRunnable; + +public class Demo { + + @Test + public void main() throws InterruptedException { + ExecutorService executor = Executors.newFixedThreadPool(3); + TransactionFactory transactionFactory = new TransactionFactory(); + for (int i = 0; i < 10; i++) { + Transfer tx = transactionFactory.newInstance(); + Runnable task = new Slf4jRunnable(tx); + executor.submit(task); + } + executor.shutdown(); + executor.awaitTermination(60, TimeUnit.SECONDS); + } +} From 23db51fbd75d5dacb95db6acf44c3730c0d89861 Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 7 Nov 2016 23:08:51 +0100 Subject: [PATCH 46/86] Minor typos --- log-mdc/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/log-mdc/pom.xml b/log-mdc/pom.xml index a6e9414dc5..7d68049cde 100644 --- a/log-mdc/pom.xml +++ b/log-mdc/pom.xml @@ -1,11 +1,11 @@ 4.0.0 - com.baeldug - logmdcndc + com.baeldung + logmdc 0.0.1-SNAPSHOT - logmdcndc - tutorial on logging with MDC and NDC + logmdc + tutorial on logging with MDC From e26d9ff8e492bdd05e89b9d774c2e7f0a773a0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Wed, 9 Nov 2016 06:57:16 +0100 Subject: [PATCH 47/86] BAEL-41: Some minor format changes. --- .../tests/AsyncFileAppenderUsingJsonLayoutTest.java | 7 ++++--- .../tests/ConsoleAppenderUsingDefaultLayoutTest.java | 11 +++++++---- ...nsoleAppenderUsingPatternLayoutWithColorsTest.java | 10 ++++++---- .../tests/RollingFileAppenderUsingXMLLayoutTest.java | 6 +++--- .../log4j2-rolling-file-appender_xml-layout.xml | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java index db3a4d2458..0472c2219e 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/AsyncFileAppenderUsingJsonLayoutTest.java @@ -14,12 +14,13 @@ import static org.junit.Assert.assertTrue; @RunWith(JUnit4.class) public class AsyncFileAppenderUsingJsonLayoutTest { - @Rule - public LoggerContextRule contextRule = new LoggerContextRule("log4j2-async-file-appender_json-layout.xml"); + public LoggerContextRule contextRule = + new LoggerContextRule("log4j2-async-file-appender_json-layout.xml"); @Test - public void givenLoggerWithAsyncConfig_shouldLogToJsonFile() throws Exception { + public void givenLoggerWithAsyncConfig_shouldLogToJsonFile() + throws Exception { Logger logger = contextRule.getLogger(getClass().getSimpleName()); final int count = 88; for (int i = 0; i < count; i++) { diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java index 9d8b2ae81b..9831030d02 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingDefaultLayoutTest.java @@ -8,11 +8,14 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class ConsoleAppenderUsingDefaultLayoutTest { - @Test - public void givenLoggerWithDefaultConfig_shouldLogToConsole() throws Exception { - Logger logger = LogManager.getLogger(ConsoleAppenderUsingDefaultLayoutTest.class); + public void givenLoggerWithDefaultConfig_shouldLogToConsole() + throws Exception { + Logger logger = LogManager.getLogger(getClass()); Exception e = new RuntimeException("This is only a test!"); - logger.error("This is a simple message at ERROR level. This is the minimum visible level.", e); + logger.info("This is a simple message at INFO level. " + + "It will be hidden."); + logger.error("This is a simple message at ERROR level. " + + "This is the minimum visible level.", e); } } diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java index 1e16ba7d0b..86b005538f 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/ConsoleAppenderUsingPatternLayoutWithColorsTest.java @@ -12,15 +12,17 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class ConsoleAppenderUsingPatternLayoutWithColorsTest { - @Rule - public LoggerContextRule contextRule = new LoggerContextRule("log4j2-console-appender_pattern-layout.xml"); + public LoggerContextRule contextRule = + new LoggerContextRule("log4j2-console-appender_pattern-layout.xml"); @Test - public void givenLoggerWithConsoleConfig_shouldLogToConsoleInColors() throws Exception { + public void givenLoggerWithConsoleConfig_shouldLogToConsoleInColors() + throws Exception { Logger logger = contextRule.getLogger(getClass().getSimpleName()); logger.trace("This is a colored message at TRACE level."); - logger.debug("This is a colored message at DEBUG level. This is the minimum visible level."); + logger.debug("This is a colored message at DEBUG level. " + + "This is the minimum visible level."); logger.info("This is a colored message at INFO level."); logger.warn("This is a colored message at WARN level."); Exception e = new RuntimeException("This is only a test!"); diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java index 2ebdccfc75..3ab69d263c 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/RollingFileAppenderUsingXMLLayoutTest.java @@ -15,9 +15,9 @@ import static org.junit.Assert.assertTrue; @RunWith(JUnit4.class) public class RollingFileAppenderUsingXMLLayoutTest { - @Rule - public LoggerContextRule contextRule = new LoggerContextRule("log4j2-rolling-file-appender_xml-layout.xml"); + public LoggerContextRule contextRule = + new LoggerContextRule("log4j2-rolling-file-appender_xml-layout.xml"); @Test public void givenLoggerWithRollingFileConfig_shouldLogToXMLFile() throws Exception { @@ -29,6 +29,6 @@ public class RollingFileAppenderUsingXMLLayoutTest { String[] logEvents = Files.readAllLines(Paths.get("target/logfile.xml")).stream() .collect(Collectors.joining(System.lineSeparator())) .split("\\n\\n+"); - assertTrue(logEvents.length == count); + assertTrue(logEvents.length == 39); } } diff --git a/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml b/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml index 059007f660..9de1a29186 100644 --- a/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml +++ b/log4j2/src/test/resources/log4j2-rolling-file-appender_xml-layout.xml @@ -6,7 +6,7 @@ filePattern="target/logfile-%d{yyyy-MM-dd}-%i.log.gz"> - + From d1ea5e8394d9296228e1276334b0febda8b060ff Mon Sep 17 00:00:00 2001 From: Ante Pocedulic Date: Wed, 9 Nov 2016 08:00:50 +0100 Subject: [PATCH 48/86] - added new camel example (#812) - added new camel context for junit test --- .../baeldung/camel/file/FileProcessor.java | 20 ++++++ .../com/baeldung/camel/file/FileRouter.java | 15 ++++ .../src/main/resources/camel-context-test.xml | 14 ++++ .../src/main/resources/camel-context.xml | 48 ++++++------- .../file/processor/FileProcessorTest.java | 68 +++++++++++++++++++ 5 files changed, 141 insertions(+), 24 deletions(-) create mode 100644 spring-apache-camel/src/main/java/com/baeldung/camel/file/FileProcessor.java create mode 100644 spring-apache-camel/src/main/java/com/baeldung/camel/file/FileRouter.java create mode 100644 spring-apache-camel/src/main/resources/camel-context-test.xml create mode 100644 spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorTest.java diff --git a/spring-apache-camel/src/main/java/com/baeldung/camel/file/FileProcessor.java b/spring-apache-camel/src/main/java/com/baeldung/camel/file/FileProcessor.java new file mode 100644 index 0000000000..1ea2cad188 --- /dev/null +++ b/spring-apache-camel/src/main/java/com/baeldung/camel/file/FileProcessor.java @@ -0,0 +1,20 @@ +package com.baeldung.camel.file; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; + +public class FileProcessor implements Processor { + + public void process(Exchange exchange) throws Exception { + String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); + + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); + String changedFileName = dateFormat.format(date) + originalFileName; + exchange.getIn().setHeader(Exchange.FILE_NAME, changedFileName); + } + +} diff --git a/spring-apache-camel/src/main/java/com/baeldung/camel/file/FileRouter.java b/spring-apache-camel/src/main/java/com/baeldung/camel/file/FileRouter.java new file mode 100644 index 0000000000..5216c9a595 --- /dev/null +++ b/spring-apache-camel/src/main/java/com/baeldung/camel/file/FileRouter.java @@ -0,0 +1,15 @@ +package com.baeldung.camel.file; + +import org.apache.camel.builder.RouteBuilder; + +public class FileRouter extends RouteBuilder { + + private static final String SOURCE_FOLDER = "src/test/source-folder"; + private static final String DESTINATION_FOLDER = "src/test/destination-folder"; + + @Override + public void configure() throws Exception { + from("file://" + SOURCE_FOLDER + "?delete=true").process(new FileProcessor()).to("file://" + DESTINATION_FOLDER); + } + +} diff --git a/spring-apache-camel/src/main/resources/camel-context-test.xml b/spring-apache-camel/src/main/resources/camel-context-test.xml new file mode 100644 index 0000000000..e6435db9e5 --- /dev/null +++ b/spring-apache-camel/src/main/resources/camel-context-test.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/spring-apache-camel/src/main/resources/camel-context.xml b/spring-apache-camel/src/main/resources/camel-context.xml index 0c10e0ecef..63ef406fdf 100644 --- a/spring-apache-camel/src/main/resources/camel-context.xml +++ b/spring-apache-camel/src/main/resources/camel-context.xml @@ -1,39 +1,39 @@ - + - + - - + + - - + + - - + + - - - ${body.toLowerCase()} - + + + ${body.toLowerCase()} + - - + + - - - .......... File content conversion completed .......... - - + + + .......... File content conversion completed .......... + + - + - + - + \ No newline at end of file diff --git a/spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorTest.java b/spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorTest.java new file mode 100644 index 0000000000..3d63f614e0 --- /dev/null +++ b/spring-apache-camel/src/test/java/org/apache/camel/file/processor/FileProcessorTest.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 FileProcessorTest { + + 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 From c50338720f553c29fc5ceaae248474bb9e991969 Mon Sep 17 00:00:00 2001 From: mujah Date: Wed, 9 Nov 2016 18:28:01 +0800 Subject: [PATCH 49/86] test cases and model fixes --- .../spring/data/solr/model/Product.java | 22 +++-- .../ProductRepositoryIntegrationTest.java | 92 ++++++++++++------- 2 files changed, 73 insertions(+), 41 deletions(-) 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 d08640123a..54962b7e51 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 @@ -1,31 +1,33 @@ package com.baeldung.spring.data.solr.model; -import org.apache.solr.client.solrj.beans.Field; import org.springframework.data.annotation.Id; +import org.springframework.data.solr.core.mapping.Indexed; import org.springframework.data.solr.core.mapping.SolrDocument; @SolrDocument(solrCoreName = "product") public class Product { @Id - @Field("id") + @Indexed(name="id",type = "string") private String id; - @Field("name") + + @Indexed(name="name",type = "string") private String name; - @Field("category") + + @Indexed(name="category",type = "string") private String category; - @Field("description") + + @Indexed(name="description",type = "string") private String description; - - public Product(String id, String name, String category) { - this.id = id; - this.name = name; - this.category = category; + + public Product(){ + } + public String getId() { return id; } 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 b55e65e04a..74d94ef91c 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,94 +21,124 @@ 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("P00001", "Desk", "Furniture"); + 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("P0001", "T-Shirt", "Kitchen"); + 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"); productRepository.save(product); - + final Product retrievedProduct = productRepository.findOne(product.getId()); assertEquals(product.getCategory(), retrievedProduct.getCategory()); } - + @Test public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception { - final Product product = new Product("P0001", "Desk", "Furniture"); + 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("P0001", "Phone", "Electronics"); + 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("P0001", "Smart Phone", "Electronics"); + 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("P0002", "Cover", "Phone"); + + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Cover"); + phoneCover.setCategory("Phone"); phoneCover.setDescription("New Product"); productRepository.save(phoneCover); - - final Product wirelessCharger = new Product("P0003", "Charging Cable", "Cable"); + + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Charging Cable"); + wirelessCharger.setCategory("Cable"); wirelessCharger.setDescription("Wireless Charger for Phone"); 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("P0001", "Smart Phone", "Electronics"); + 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("P0002", "Cover", "Phone"); + + final Product phoneCover = new Product(); + phoneCover.setId("P0002"); + phoneCover.setName("Cover"); + phoneCover.setCategory("Phone"); phoneCover.setDescription("New Product"); productRepository.save(phoneCover); - - final Product wirelessCharger = new Product("P0003", "Charging Cable", "Cable"); + + final Product wirelessCharger = new Product(); + wirelessCharger.setId("P0003"); + wirelessCharger.setName("Charging Cable"); + wirelessCharger.setCategory("Cable"); wirelessCharger.setDescription("Wireless Charger for Phone"); productRepository.save(wirelessCharger); - + Page result = productRepository.findByNamedQuery("one", new PageRequest(0, 10)); assertEquals(3, result.getNumberOfElements()); } - + } From 2ab1eeb036e0d5344eef5751c2602927a2040c93 Mon Sep 17 00:00:00 2001 From: mujah Date: Wed, 9 Nov 2016 18:36:32 +0800 Subject: [PATCH 50/86] refactoring model --- .../spring/data/solr/model/Product.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) 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 54962b7e51..7cd0890718 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,58 +6,50 @@ import org.springframework.data.solr.core.mapping.SolrDocument; @SolrDocument(solrCoreName = "product") public class Product { - + @Id - @Indexed(name="id",type = "string") + @Indexed(name = "id", type = "string") private String id; - - @Indexed(name="name",type = "string") + @Indexed(name = "name", type = "string") private String name; - - @Indexed(name="category",type = "string") + @Indexed(name = "category", type = "string") private String category; - - @Indexed(name="description",type = "string") + @Indexed(name = "description", type = "string") private String description; - public Product(){ - - } - - 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; } - + } From f966f277c026dd53c32aa96e738b82cdb30330aa Mon Sep 17 00:00:00 2001 From: mujah Date: Wed, 9 Nov 2016 22:10:30 +0800 Subject: [PATCH 51/86] removed solr --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 182b2d5147..95182ab63c 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,6 @@ spring-data-mongodb spring-data-redis spring-data-rest - spring-data-solr spring-exceptions spring-freemarker From 6d1fbd5603b8215f06d9f85c2eaff626aa82264c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Wed, 9 Nov 2016 15:21:23 +0100 Subject: [PATCH 52/86] BAEL-41: Fixed small formatting issues. --- .../logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java | 1 - .../java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java index 72d32d76fb..0653394e5a 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/FailoverSyslogConsoleAppenderTest.java @@ -9,7 +9,6 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class FailoverSyslogConsoleAppenderTest { - @Rule public LoggerContextRule contextRule = new LoggerContextRule("log4j2-failover-syslog-console-appender_pattern-layout.xml"); diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java index 2ceda2083b..1b8d33e2bf 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JDBCAppenderTest.java @@ -16,7 +16,6 @@ import static org.junit.Assert.assertTrue; @RunWith(JUnit4.class) public class JDBCAppenderTest { - @Rule public LoggerContextRule contextRule = new LoggerContextRule("log4j2-jdbc-appender.xml"); From 1f0e30b81ca7f87c7f0674ba5bdb83bdff0ba982 Mon Sep 17 00:00:00 2001 From: mujah Date: Wed, 9 Nov 2016 22:26:18 +0800 Subject: [PATCH 53/86] pom changes + merge upstream --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 857922310f..bd626b3ad0 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ spring-data-neo4j spring-data-redis spring-data-rest + spring-data-solr spring-dispatcher-servlet spring-exceptions spring-freemarker From 6708feb70c6f0cb39532b19ae94fec5d81e81868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Wed, 9 Nov 2016 08:52:45 +0100 Subject: [PATCH 54/86] BAEL-86: Added diagram picture and sources. --- .../src/main/resources/README.md | 3 + .../src/main/resources/diagram.graphml | 372 ++++++++++++++++++ .../src/main/resources/diagram.png | Bin 0 -> 60385 bytes 3 files changed, 375 insertions(+) create mode 100644 spring-dispatcher-servlet/src/main/resources/README.md create mode 100644 spring-dispatcher-servlet/src/main/resources/diagram.graphml create mode 100644 spring-dispatcher-servlet/src/main/resources/diagram.png diff --git a/spring-dispatcher-servlet/src/main/resources/README.md b/spring-dispatcher-servlet/src/main/resources/README.md new file mode 100644 index 0000000000..7c97e75a2c --- /dev/null +++ b/spring-dispatcher-servlet/src/main/resources/README.md @@ -0,0 +1,3 @@ +## Info ## + +- The diagram is created with [yed](http://www.yworks.com/products/yed) diff --git a/spring-dispatcher-servlet/src/main/resources/diagram.graphml b/spring-dispatcher-servlet/src/main/resources/diagram.graphml new file mode 100644 index 0000000000..1806ab7719 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/resources/diagram.graphml @@ -0,0 +1,372 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Servlet Engine (e.g. Tomcat) + + + + + + + + + + Folder 1 + + + + + + + + + + + + + + + + Controller + + + + + + + + + + + + + + + + + + + Model + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Model + + + + + + + + + + + + + + + + + + + + DispatcherServlet + + + + + + + + + + + + + + + + + + + View Template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Return Control + + + + + + + + + + + + Render Response + + + + + + + + + + + + Delegate Request + + + + + + + + + + + + Delegate Rendering of Response + + + + + + + + + + + + + + + + + + + + + + + + + Incoming Request + + + + + + + + + + + + Return Response + + + + + + + + + + + + + + Handle Request + + + + + + + + + + + + + + Create Model + + + + + + + + + <?xml version="1.0" encoding="utf-8"?> +<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + width="57px" height="67px" viewBox="0 0 57 67" enable-background="new 0 0 57 67" xml:space="preserve"> +<g> + + <radialGradient id="neck_x5F_white_1_" cx="28.0298" cy="-751.9429" r="11.4464" fx="25.7969" fy="-753.1596" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#B38E5D"/> + <stop offset="1" style="stop-color:#805126"/> + </radialGradient> + <path id="neck_x5F_white_2_" fill="url(#neck_x5F_white_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M19.278,37.799h18.188 + v13.23c-1.313,0.371-17.173,0.436-18.188,0.172V37.799z"/> + + <radialGradient id="SVGID_1_" cx="27.481" cy="-760.3003" r="31.0533" fx="21.4231" fy="-763.6011" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#B38E5D"/> + <stop offset="1" style="stop-color:#805126"/> + </radialGradient> + <path fill="url(#SVGID_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M49.529,51.225c-4.396-4.396-10.951-5.884-12.063-6.109 + V37.8H19.278c0,0,0.038,6.903,0,6.868c0,0-6.874,0.997-12.308,6.432C1.378,56.691,0.5,62.77,0.5,62.77 + c0,1.938,1.575,3.492,3.523,3.492h48.51c1.947,0,3.521-1.558,3.521-3.492C56.055,62.768,54.211,55.906,49.529,51.225z"/> + + <radialGradient id="face_x5F_white_1_" cx="27.7827" cy="-732.2632" r="23.424" fx="23.2131" fy="-734.753" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#B38E5D"/> + <stop offset="1" style="stop-color:#805126"/> + </radialGradient> + <path id="face_x5F_white_2_" fill="url(#face_x5F_white_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M43.676,23.357 + c0.086,10.199-6.738,18.52-15.246,18.586c-8.503,0.068-15.467-8.146-15.553-18.344C12.794,13.4,19.618,5.079,28.123,5.012 + C36.627,4.945,43.59,13.158,43.676,23.357z"/> + + <linearGradient id="face_highlight_1_" gradientUnits="userSpaceOnUse" x1="2941.4297" y1="5674.7988" x2="2965.0596" y2="5768.2505" gradientTransform="matrix(0.275 0 0 0.2733 -783.3976 -1542.678)"> + <stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.42"/> + <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.12"/> + </linearGradient> + <path id="face_highlight_2_" fill="url(#face_highlight_1_)" d="M27.958,6.333c-6.035,0.047-10.747,4.493-12.787,10.386 + c-0.664,1.919-0.294,4.043,0.98,5.629c2.73,3.398,5.729,6.283,9.461,8.088c3.137,1.518,7.535,2.385,11.893,1.247 + c2.274-0.592,3.988-2.459,4.375-4.766c0.183-1.094,0.293-2.289,0.283-3.553C42.083,13.952,36.271,6.268,27.958,6.333z"/> + <path id="path9833_2_" fill="#4B4B4B" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" d="M28.372,0.5 + C17.537,0.5,8.269,7.748,9.153,26.125c0.563,6.563,5.862,12.042,9.366,13.531c-2.929-10.968-0.304-25.021-0.585-25.526 + c-0.281-0.505,3.536,6.728,3.536,6.728l3.183-8.312c5.541,4.28,0.393,11.309,1.049,11.058c4.26-1.631,5.34-9.228,5.34-9.228 + s2.729,3.657,2.701,5.504c-0.054,3.562,2.194-6.067,2.194-6.067l1.027,2.031c6.727,9.822,3.684,16.208,1.654,22.781 + c15.665-0.703,12.289-10.48,9.658-18.407C43.59,6.092,39.206,0.5,28.372,0.5z"/> + + <radialGradient id="collar_x5F_body_2_" cx="15.1587" cy="-763.7056" r="32.4004" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#B0E8FF"/> + <stop offset="1" style="stop-color:#74AEEE"/> + </radialGradient> + <path id="collar_x5F_body_1_" fill="url(#collar_x5F_body_2_)" stroke="#5491CF" d="M0.5,62.768c0,1.938,1.575,3.494,3.523,3.494 + h48.51c1.947,0,3.521-1.559,3.521-3.494c0,0-1.844-6.861-6.525-11.543c-4.815-4.813-11.244-6.146-11.244-6.146 + c-1.771,1.655-5.61,2.802-10.063,2.802c-4.453,0-8.292-1.146-10.063-2.802c0,0-5.755,0.586-11.189,6.021 + C1.378,56.689,0.5,62.768,0.5,62.768z"/> + + <radialGradient id="collar_x5F_r_2_" cx="31.5" cy="-753.832" r="9.2834" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#80CCFF"/> + <stop offset="1" style="stop-color:#74AEEE"/> + </radialGradient> + <path id="collar_x5F_r_1_" fill="url(#collar_x5F_r_2_)" stroke="#5491CF" d="M38.159,41.381c0,0-0.574,2.369-3.013,4.441 + c-2.108,1.795-5.783,2.072-5.783,2.072l3.974,6.217c0,0,2.957-1.637,5.009-3.848c1.922-2.072,1.37-5.479,1.37-5.479L38.159,41.381z + "/> + + <radialGradient id="collar_x5F_l_2_" cx="19.1377" cy="-753.873" r="9.2837" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#80CCFF"/> + <stop offset="1" style="stop-color:#74AEEE"/> + </radialGradient> + <path id="collar_x5F_l_1_" fill="url(#collar_x5F_l_2_)" stroke="#5491CF" d="M18.63,41.422c0,0,0.576,2.369,3.012,4.441 + c2.109,1.793,5.785,2.072,5.785,2.072l-3.974,6.217c0,0-2.957-1.637-5.007-3.85c-1.922-2.072-1.37-5.48-1.37-5.48L18.63,41.422z"/> + + <radialGradient id="Knob2_2_" cx="27.8872" cy="9.9414" r="0.9669" gradientTransform="matrix(1 0 0 -1 0.04 66.1543)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#80CCFF"/> + <stop offset="1" style="stop-color:#74AEEE"/> + </radialGradient> + <circle id="Knob2_1_" fill="url(#Knob2_2_)" stroke="#5491CF" cx="28.258" cy="56.254" r="0.584"/> + + <radialGradient id="Knob1_2_" cx="27.9253" cy="3.6973" r="0.9669" gradientTransform="matrix(1 0 0 -1 0.04 66.1543)" gradientUnits="userSpaceOnUse"> + <stop offset="0" style="stop-color:#80CCFF"/> + <stop offset="1" style="stop-color:#74AEEE"/> + </radialGradient> + <circle id="Knob1_1_" fill="url(#Knob1_2_)" stroke="#5491CF" cx="28.296" cy="62.499" r="0.584"/> +</g> +</svg> + + + + diff --git a/spring-dispatcher-servlet/src/main/resources/diagram.png b/spring-dispatcher-servlet/src/main/resources/diagram.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c545d680d344da47592a4180b9061fd1615a59 GIT binary patch literal 60385 zcmc$`cRbZ^{65|=j+G-TBb;PruSm$T_XtU{$|fs&6-U|Gglrj+5rvG%sAPo*nb}*} z>-#*7_viD+@A3FO9^Zey{nO&S?$>=k$Mw9f>lUJ^u0TRaOL*eM2@)kmS?v=ia7s^{ zIAw`A1^U2;=u_eS!o@Qp`|)^eVuQ~t5W_4E1#cLyMGaL>HPd`zE>h5pS{>^ z*nUBz!v0FD9vx*%aB)@!`#CKg3OPAG<^aL~vrhKVtR%|e2ZUJ{XfksY10JZ4Z^sL- zSl-g5(AC7HtWSUZIB&4>TftYO)xACg?>hhWG$a~vLS~If~l?QBBeDD*bYRO8<4;BiT^&{PN6Y^N3S~q+j zzR*bslPKh(5N~O4%=22NxFy)CUWO4D?o(eUpuLmF?l4kdB!1X7KXv3h)4Z-OV|X6_ zlYi-&yI^Yp7rlrdd&2SCu-H!!%VJ^deCb2%bcboiu zN(2jL@7^;cdeG=1W(|)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0 zI@H5yS$osnAK`R!m*hlH(%vr95u%QHDZ8K1qs`j9VLFq8A{_~e7<$3QWiCq$SIb;l zo39I3p_GrlpF@15!S6en(hLh1Ewlr8hP-$zCOo|i z5@Vi874GoEn=^PNP0aUM*lAr=lj-^$E01_Squ(9&8-eRD__|B>zq0>$Lo9VxXc(V6 z)19CcBJSdr0qGI4w_08?;^Bef!cOOi2eZ5hdtcwKo)H?Bd@RoTSX_AaHGI=6ZPGvC zdz)!GN#OTwvEh1J_@}4t3t183;p0#1=1;9%sp$IUbM<*Mzri@l%&}fiVQ)qc{XbXB rpLhJftnoi<^M6}n|Mg24{cY)*FNeNjAEtjsCj6qjs@yBQvH$-8|2|Wc literal 0 HcmV?d00001 From 997b3cabbe8b51f63fb47303faf96d45c52ee6a0 Mon Sep 17 00:00:00 2001 From: James Kerak Date: Thu, 10 Nov 2016 09:02:46 -0500 Subject: [PATCH 55/86] changing anonymous subclass to lambda --- .../org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java index d1cc67b99a..2c88408017 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java @@ -56,13 +56,10 @@ public class OkHttpFileUploadingLiveTest { .build(); - ProgressRequestWrapper.ProgressListener listener = new ProgressRequestWrapper.ProgressListener() { + ProgressRequestWrapper.ProgressListener listener = (bytesWritten, contentLength) -> { - public void onRequestProgress(long bytesWritten, long contentLength) { - - float percentage = 100f * bytesWritten / contentLength; - assertFalse(Float.compare(percentage, 100) > 0); - } + float percentage = 100f * bytesWritten / contentLength; + assertFalse(Float.compare(percentage, 100) > 0); }; ProgressRequestWrapper countingBody = new ProgressRequestWrapper(requestBody, listener); From 9703ea7f1a295bda11d5387d60c5205f2d9c33d6 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 10 Nov 2016 16:11:53 +0100 Subject: [PATCH 56/86] Add BAEL-396 (Netflix Ribbon intro) to README.md --- spring-cloud/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/README.md b/spring-cloud/README.md index 3e8cd21b82..60acdaeed5 100644 --- a/spring-cloud/README.md +++ b/spring-cloud/README.md @@ -14,5 +14,6 @@ - [Intro to Spring Cloud Netflix - Hystrix](http://www.baeldung.com/spring-cloud-netflix-hystrix) - [Dockerizing a Spring Boot Application](http://www.baeldung.com/dockerizing-spring-boot-application) +- [Introduction to Spring Cloud Rest Client with Netflix Ribbon](http://www.baeldung.com/spring-cloud-rest-client-with-netflix-ribbon) From 3d5227adbbc95b3b880df6c32092971b688daafd Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 10 Nov 2016 16:13:42 +0100 Subject: [PATCH 57/86] Added BAEL-387 --- core-java/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java/README.md b/core-java/README.md index 48f0677461..49317bf369 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -35,4 +35,5 @@ - [Java 8 Streams Advanced](http://www.baeldung.com/java-8-streams) - [Introduction to Thread Pools in Java](http://www.baeldung.com/thread-pool-java-and-guava) - [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction) -- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join) \ No newline at end of file +- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join) +- [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java) From 63a47897f34130a107cb07719363e5542055b1f6 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 10 Nov 2016 16:16:12 +0100 Subject: [PATCH 58/86] Added Java 9 New Features --- core-java-9/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-9/README.md b/core-java-9/README.md index b5d4dbef95..78f235046f 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -2,4 +2,4 @@ ## Core Java 9 Examples -http://inprogress.baeldung.com/java-9-new-features/ \ No newline at end of file +(Java 9 New Features)[http://www.baeldung.com/new-java-9] From b384c48bd384aeecbd4610b967d7f0e8c61084df Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 10 Nov 2016 16:16:48 +0100 Subject: [PATCH 59/86] Fix link --- core-java-9/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-9/README.md b/core-java-9/README.md index 78f235046f..fbe5f908aa 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -2,4 +2,4 @@ ## Core Java 9 Examples -(Java 9 New Features)[http://www.baeldung.com/new-java-9] +[Java 9 New Features](http://www.baeldung.com/new-java-9) From ec132346c7322de25e3a93882070b49d0a46e575 Mon Sep 17 00:00:00 2001 From: Nancy Bosecker Date: Thu, 10 Nov 2016 18:50:16 -0800 Subject: [PATCH 60/86] fixed imports for sslcontext for apache 4.4 (#815) The new test passes, and the maven build succeeded. --- .../java/org/baeldung/httpclient/HttpsClientSslLiveTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java index fb272b0a33..e9a16f18ad 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java @@ -19,8 +19,6 @@ import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContextBuilder; -import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.conn.ssl.TrustStrategy; @@ -29,6 +27,8 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.ssl.SSLContexts; import org.junit.Test; /** From fcd6ff2891917e3b2cf4c49ae9a5e84ba4a798f2 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Fri, 11 Nov 2016 09:03:53 +0530 Subject: [PATCH 61/86] Making changes in Maven Profile for Test Case Failure --- selenium-junit-testng/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml index cc96ea8529..754bf679b5 100644 --- a/selenium-junit-testng/pom.xml +++ b/selenium-junit-testng/pom.xml @@ -25,6 +25,7 @@ **/*UnitTest.java + false @@ -42,6 +43,7 @@ **/*LiveTest.java + false From 3daf23ae222b796fc9a2f3d1526d2bd831869188 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 11 Nov 2016 15:02:37 +0100 Subject: [PATCH 62/86] Refactor OkHttp examples --- .../org/baeldung/okhttp/OkHttpGetLiveTest.java | 3 +-- .../org/baeldung/okhttp/OkHttpMiscLiveTest.java | 15 +++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java index 9bf57c41b2..3f773bf35e 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java @@ -60,9 +60,8 @@ public class OkHttpGetLiveTest { Call call = client.newCall(request); call.enqueue(new Callback() { - public void onResponse(Call call, Response response) throws IOException { - assertThat(response.code(), equalTo(200)); + System.out.println("OK"); } public void onFailure(Call call, IOException e) { diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java index dcdb4e328c..9c38c8da51 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java @@ -1,21 +1,16 @@ package org.baeldung.okhttp; +import okhttp3.*; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import okhttp3.Cache; -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - public class OkHttpMiscLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; From 584ae4167f43d10e2552676728e6b3111dd45447 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 11 Nov 2016 18:59:49 +0100 Subject: [PATCH 63/86] Refactor HttpsClientSSLLiveTest --- .../httpclient/HttpsClientSslLiveTest.java | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java index e9a16f18ad..278cdb3556 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java @@ -1,27 +1,11 @@ package org.baeldung.httpclient; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLException; - import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLSocketFactory; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.conn.ssl.*; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; @@ -31,6 +15,14 @@ import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContexts; import org.junit.Test; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLException; +import java.io.IOException; +import java.security.GeneralSecurityException; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + /** * This test requires a localhost server over HTTPS
* It should only be manually run, not part of the automated build @@ -101,17 +93,9 @@ public class HttpsClientSslLiveTest { } @Test - public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws IOException { - - final TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true; - - SSLContext sslContext = null; - try { - sslContext = new SSLContextBuilder().loadTrustMaterial(null, acceptingTrustStrategy).build(); - - } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { - e.printStackTrace(); - } + public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws Exception { + SSLContext sslContext = new SSLContextBuilder() + .loadTrustMaterial(null, (certificate, authType) -> true).build(); final CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); final HttpGet httpGet = new HttpGet(HOST_WITH_SSL); From c30bd6caa75287552bfb424d07ac717c90c9ca13 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Sat, 12 Nov 2016 13:42:01 +0530 Subject: [PATCH 64/86] BAEL-29 Refactored Code to comeup with Unit Test --- .../java/conversion/StringConversion.java | 60 ---------- .../java/conversion/StringConversionTest.java | 104 ++++++++++++++++++ 2 files changed, 104 insertions(+), 60 deletions(-) delete mode 100644 core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java create mode 100644 core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java diff --git a/core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java b/core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java deleted file mode 100644 index 0a0f79566e..0000000000 --- a/core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.java.conversion; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.LocalDateTime; -import java.util.Date; - -import com.baeldung.datetime.UseLocalDateTime; - -public class StringConversion { - - public static int getInt(String str) { - return Integer.parseInt(str); - } - - public static int getInteger(String str) { - return Integer.valueOf(str); - } - - public static long getLongPrimitive(String str) { - return Long.parseLong(str); - } - - public static Long getLong(String str) { - return Long.valueOf(str); - } - - public static double getDouble(String str) { - return Double.parseDouble(str); - } - - public static double getDoublePrimitive(String str) { - return Double.valueOf(str); - } - - public static byte[] getByteArray(String str) { - return str.getBytes(); - } - - public static char[] getCharArray(String str) { - return str.toCharArray(); - } - - public static boolean getBooleanPrimitive(String str) { - return Boolean.parseBoolean(str); - } - - public static boolean getBoolean(String str) { - return Boolean.valueOf(str); - } - - public static Date getJava6Date(String str, String format) throws ParseException { - SimpleDateFormat formatter = new SimpleDateFormat(format); - return formatter.parse(str); - } - - public static LocalDateTime getJava8Date(String str) throws ParseException { - return new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); - } -} diff --git a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java new file mode 100644 index 0000000000..731f9a2a6e --- /dev/null +++ b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java @@ -0,0 +1,104 @@ +package com.baeldung.java.conversion; + +import static org.junit.Assert.assertEquals; + +import java.io.UnsupportedEncodingException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.Month; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import org.junit.Test; + +import com.baeldung.datetime.UseLocalDateTime; + +public class StringConversionTest { + + @Test + public void givenString_whenConvertedToint_thenCorrect() { + String str = "1"; + assertEquals(Integer.parseInt(str), 1); + } + + @Test + public void givenString_whenConvertedToInteger_thenCorrect() { + String str = "12"; + Integer number = Integer.valueOf(str); + assertEquals(number.intValue(), 12); + } + + @Test + public void givenString_whenConvertedTolong_thenCorrect() { + String str = "12345"; + assertEquals(Long.parseLong(str), 12345); + } + + @Test + public void givenString_whenConvertedToLong_thenCorrect() { + String str = "14567"; + Long number = Long.valueOf(str); + assertEquals(number.longValue(), 14567); + } + + @Test + public void givenString_whenConvertedTodouble_thenCorrect() { + String str = "1.4"; + assertEquals(Double.parseDouble(str), 1.4, 0.0); + } + + @Test + public void givenString_whenConvertedToDouble_thenCorrect() { + String str = "145.67"; + Double number = Double.valueOf(str); + assertEquals(number.doubleValue(), 145.67, 0.0); + } + + @Test + public void givenString_whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException { + byte[] byteArray1 = new byte[] { 'a', 'b', 'c' }; + String str = new String(byteArray1, "UTF-8"); + assertEquals(Arrays.equals(str.getBytes(), byteArray1), true); + } + + @Test + public void givenString_whenConvertedToboolean_thenCorrect() { + String str = "true"; + assertEquals(Boolean.parseBoolean(str), true); + } + + @Test + public void givenString_whenConvertedToBoolean_thenCorrect() { + String str = "true"; + assertEquals(Boolean.valueOf(str), true); + } + + @Test + public void givenString_whenConvertedToCharArray_thenCorrect() { + String str = "hello"; + char[] charArray = { 'h', 'e', 'l', 'l', 'o' }; + assertEquals(Arrays.equals(charArray, str.toCharArray()), true); + } + + @Test + public void givenString_whenConvertedToJava6Date_thenCorrect() throws ParseException { + String str = "15/10/2013"; + SimpleDateFormat formatter = new SimpleDateFormat("dd/M/yyyy"); + Date date1 = formatter.parse(str); + Calendar calendar = new GregorianCalendar(2013, 9, 15); + Date date2 = calendar.getTime(); + assertEquals(date1.compareTo(date2), 0); + } + + @Test + public void givenString_whenConvertedToJava8Date_thenCorrect() throws ParseException { + String str = "2007-12-03T10:15:30"; + LocalDateTime localDateTime = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); + assertEquals(localDateTime.getDayOfMonth(), 3); + assertEquals(localDateTime.getMonth(), Month.DECEMBER); + assertEquals(localDateTime.getYear(), 2007); + } +} From 19eb8bd90d286e5d3337cf520c71d3feebe07cd0 Mon Sep 17 00:00:00 2001 From: "nguyenminhtuanfit@gmail.com" Date: Sat, 12 Nov 2016 15:53:40 +0700 Subject: [PATCH 65/86] An introduction to JAXB --- jaxb/pom.xml | 170 ++++++++++++++++++ .../src/main/java/com/baeldung/jaxb/Book.java | 58 ++++++ .../java/com/baeldung/jaxb/DateAdapter.java | 28 +++ .../src/main/java/com/baeldung/jaxb/Main.java | 39 ++++ jaxb/src/main/resources/global.xjb | 13 ++ jaxb/src/main/resources/logback.xml | 18 ++ jaxb/src/main/resources/user.xsd | 23 +++ 7 files changed, 349 insertions(+) create mode 100644 jaxb/pom.xml create mode 100644 jaxb/src/main/java/com/baeldung/jaxb/Book.java create mode 100644 jaxb/src/main/java/com/baeldung/jaxb/DateAdapter.java create mode 100644 jaxb/src/main/java/com/baeldung/jaxb/Main.java create mode 100644 jaxb/src/main/resources/global.xjb create mode 100644 jaxb/src/main/resources/logback.xml create mode 100644 jaxb/src/main/resources/user.xsd diff --git a/jaxb/pom.xml b/jaxb/pom.xml new file mode 100644 index 0000000000..cce40c55d4 --- /dev/null +++ b/jaxb/pom.xml @@ -0,0 +1,170 @@ + + 4.0.0 + com.baeldung + jaxb + 0.0.1-SNAPSHOT + jaxb + + + + org.glassfish.jaxb + jaxb-runtime + ${jaxb.version} + + + + org.glassfish.jaxb + jaxb-core + ${jaxb.version} + + + + + com.sun.istack + istack-commons-runtime + 3.0.2 + + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + + + + + jaxb + + + src/main/resources + true + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + [${jaxb2-maven-plugin.version},) + + schemagen + xjc + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + ${jaxb2-maven-plugin.version} + + + xjc + + xjc + + + + + + src/main/resources/global.xjb + + + src/main/resources/user.xsd + + ${basedir}/src/main/java + false + + + + + + + + + + + 2.2.11 + + + 1.7.21 + 1.1.7 + + + 3.5.1 + 2.3 + + + \ No newline at end of file diff --git a/jaxb/src/main/java/com/baeldung/jaxb/Book.java b/jaxb/src/main/java/com/baeldung/jaxb/Book.java new file mode 100644 index 0000000000..8455d3e6df --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/Book.java @@ -0,0 +1,58 @@ +package com.baeldung.jaxb; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.XmlType; + +@XmlRootElement(name = "book") +@XmlType(propOrder = { "id", "name", "date" }) +public class Book { + private Long id; + private String name; + private String author; + private Date date; + + @XmlAttribute + public void setId(Long id) { + this.id = id; + } + + @XmlElement(name = "title") + public void setName(String name) { + this.name = name; + } + + @XmlTransient + public void setAuthor(String author) { + this.author = author; + } + + public String getName() { + return name; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Long getId() { + return id; + } + + public String getAuthor() { + return author; + } + + @Override + public String toString() { + return "Book [id=" + id + ", name=" + name + ", author=" + author + ", date=" + date + "]"; + } +} diff --git a/jaxb/src/main/java/com/baeldung/jaxb/DateAdapter.java b/jaxb/src/main/java/com/baeldung/jaxb/DateAdapter.java new file mode 100644 index 0000000000..6631525619 --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/DateAdapter.java @@ -0,0 +1,28 @@ +package com.baeldung.jaxb; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class DateAdapter extends XmlAdapter { + + private static final ThreadLocal dateFormat = new ThreadLocal() { + + @Override + protected DateFormat initialValue() { + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + } + }; + + @Override + public Date unmarshal(String v) throws Exception { + return dateFormat.get().parse(v); + } + + @Override + public String marshal(Date v) throws Exception { + return dateFormat.get().format(v); + } +} diff --git a/jaxb/src/main/java/com/baeldung/jaxb/Main.java b/jaxb/src/main/java/com/baeldung/jaxb/Main.java new file mode 100644 index 0000000000..aaf062dd4e --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/Main.java @@ -0,0 +1,39 @@ +package com.baeldung.jaxb; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Date; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +public class Main { + public static void marshal() throws JAXBException, IOException { + Book book = new Book(); + book.setId(1L); + book.setName("Book1"); + book.setAuthor("Author1"); + book.setDate(new Date()); + + JAXBContext context = JAXBContext.newInstance(Book.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(book, new File("./book.xml")); + } + + public static Book unMashal() throws JAXBException, IOException { + JAXBContext context = JAXBContext.newInstance(Book.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + Book book = (Book) unmarshaller.unmarshal(new FileReader("./book.xml")); + return book; + } + + public static void main(String[] args) throws JAXBException, IOException { + marshal(); + Book book = unMashal(); + System.out.println(book.toString()); + } +} diff --git a/jaxb/src/main/resources/global.xjb b/jaxb/src/main/resources/global.xjb new file mode 100644 index 0000000000..de9dcf1577 --- /dev/null +++ b/jaxb/src/main/resources/global.xjb @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/jaxb/src/main/resources/logback.xml b/jaxb/src/main/resources/logback.xml new file mode 100644 index 0000000000..8b566286b8 --- /dev/null +++ b/jaxb/src/main/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg %n + + + + + + + + + + + + \ No newline at end of file diff --git a/jaxb/src/main/resources/user.xsd b/jaxb/src/main/resources/user.xsd new file mode 100644 index 0000000000..18d2b95d10 --- /dev/null +++ b/jaxb/src/main/resources/user.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 633162a04bc5317dbe949085eae62e337e677320 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Sat, 12 Nov 2016 15:03:07 +0530 Subject: [PATCH 66/86] Refactoring Code - short and simple --- .../java/conversion/StringConversionTest.java | 59 ++++++++----------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java index 731f9a2a6e..60daf21091 100644 --- a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java +++ b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java @@ -19,84 +19,77 @@ import com.baeldung.datetime.UseLocalDateTime; public class StringConversionTest { @Test - public void givenString_whenConvertedToint_thenCorrect() { - String str = "1"; - assertEquals(Integer.parseInt(str), 1); + public void whenConvertedToint_thenCorrect() { + assertEquals(Integer.parseInt("1"), 1); } @Test - public void givenString_whenConvertedToInteger_thenCorrect() { - String str = "12"; - Integer number = Integer.valueOf(str); - assertEquals(number.intValue(), 12); + public void whenConvertedToInteger_thenCorrect() { + assertEquals(Integer.valueOf("12").equals(12), true); } @Test - public void givenString_whenConvertedTolong_thenCorrect() { - String str = "12345"; - assertEquals(Long.parseLong(str), 12345); + public void whenConvertedTolong_thenCorrect() { + assertEquals(Long.parseLong("12345"), 12345); } @Test - public void givenString_whenConvertedToLong_thenCorrect() { - String str = "14567"; - Long number = Long.valueOf(str); - assertEquals(number.longValue(), 14567); + public void whenConvertedToLong_thenCorrect() { + assertEquals(Long.valueOf("14567").equals(14567L), true); } @Test - public void givenString_whenConvertedTodouble_thenCorrect() { - String str = "1.4"; - assertEquals(Double.parseDouble(str), 1.4, 0.0); + public void whenConvertedTodouble_thenCorrect() { + assertEquals(Double.parseDouble("1.4"), 1.4, 0.0); } @Test - public void givenString_whenConvertedToDouble_thenCorrect() { - String str = "145.67"; - Double number = Double.valueOf(str); - assertEquals(number.doubleValue(), 145.67, 0.0); + public void whenConvertedToDouble_thenCorrect() { + assertEquals(Double.valueOf("145.67").equals(145.67d), true); } @Test - public void givenString_whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException { + public void whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException { byte[] byteArray1 = new byte[] { 'a', 'b', 'c' }; - String str = new String(byteArray1, "UTF-8"); - assertEquals(Arrays.equals(str.getBytes(), byteArray1), true); + String string = new String(byteArray1, "UTF-8"); + + assertEquals(Arrays.equals(string.getBytes(), byteArray1), true); } @Test - public void givenString_whenConvertedToboolean_thenCorrect() { - String str = "true"; - assertEquals(Boolean.parseBoolean(str), true); + public void whenConvertedToboolean_thenCorrect() { + assertEquals(Boolean.parseBoolean("true"), true); } @Test - public void givenString_whenConvertedToBoolean_thenCorrect() { - String str = "true"; - assertEquals(Boolean.valueOf(str), true); + public void whenConvertedToBoolean_thenCorrect() { + assertEquals(Boolean.valueOf("true"), true); } @Test - public void givenString_whenConvertedToCharArray_thenCorrect() { + public void whenConvertedToCharArray_thenCorrect() { String str = "hello"; char[] charArray = { 'h', 'e', 'l', 'l', 'o' }; + assertEquals(Arrays.equals(charArray, str.toCharArray()), true); } @Test - public void givenString_whenConvertedToJava6Date_thenCorrect() throws ParseException { + public void whenConvertedToJava6Date_thenCorrect() throws ParseException { String str = "15/10/2013"; SimpleDateFormat formatter = new SimpleDateFormat("dd/M/yyyy"); Date date1 = formatter.parse(str); Calendar calendar = new GregorianCalendar(2013, 9, 15); Date date2 = calendar.getTime(); + assertEquals(date1.compareTo(date2), 0); } @Test - public void givenString_whenConvertedToJava8Date_thenCorrect() throws ParseException { + public void whenConvertedToJava8Date_thenCorrect() throws ParseException { String str = "2007-12-03T10:15:30"; LocalDateTime localDateTime = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); + assertEquals(localDateTime.getDayOfMonth(), 3); assertEquals(localDateTime.getMonth(), Month.DECEMBER); assertEquals(localDateTime.getYear(), 2007); From b58c2341da2c216cedacab8003797e29f544ea8d Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Sat, 12 Nov 2016 16:01:53 +0530 Subject: [PATCH 67/86] Refactoring Code - Naming corrections --- .../com/baeldung/java/conversion/StringConversionTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java index 60daf21091..d4786f54ac 100644 --- a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java +++ b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java @@ -19,7 +19,7 @@ import com.baeldung.datetime.UseLocalDateTime; public class StringConversionTest { @Test - public void whenConvertedToint_thenCorrect() { + public void whenConvertedToInt_thenCorrect() { assertEquals(Integer.parseInt("1"), 1); } @@ -75,7 +75,7 @@ public class StringConversionTest { } @Test - public void whenConvertedToJava6Date_thenCorrect() throws ParseException { + public void whenConvertedToDate_thenCorrect() throws ParseException { String str = "15/10/2013"; SimpleDateFormat formatter = new SimpleDateFormat("dd/M/yyyy"); Date date1 = formatter.parse(str); @@ -86,7 +86,7 @@ public class StringConversionTest { } @Test - public void whenConvertedToJava8Date_thenCorrect() throws ParseException { + public void whenConvertedToLocalDateTime_thenCorrect() throws ParseException { String str = "2007-12-03T10:15:30"; LocalDateTime localDateTime = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); From 87ed454d64740687ffe96c3b20899a877ee57e73 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Sun, 13 Nov 2016 13:10:28 +0530 Subject: [PATCH 68/86] Added entry for BAEL-29 - Java String Conversions --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 49317bf369..92f124d14b 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -37,3 +37,4 @@ - [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction) - [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join) - [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java) +- [How to Convert String to different data types in Java](http://www.baeldung.com/java-string-conversions) From aeb8f7595c03f534af4ccaa49ffbc6e7cafd34a5 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 13 Nov 2016 19:09:47 +0200 Subject: [PATCH 69/86] adding new module to the parent --- core-java/0.12457740242410742 | 0 pom.xml | 1 + 2 files changed, 1 insertion(+) delete mode 100644 core-java/0.12457740242410742 diff --git a/core-java/0.12457740242410742 b/core-java/0.12457740242410742 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pom.xml b/pom.xml index bd626b3ad0..9dfb0fdaaf 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ junit5 log4j + log-mdc lombok mapstruct From de16f2601193132badb1a4ea2738ff29e125b964 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Fri, 11 Nov 2016 09:03:53 +0530 Subject: [PATCH 70/86] Making changes in Maven Profile for Test Case Failure --- selenium-junit-testng/pom.xml | 2 ++ .../src/main/java/com/baeldung/selenium/SeleniumExample.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml index cc96ea8529..754bf679b5 100644 --- a/selenium-junit-testng/pom.xml +++ b/selenium-junit-testng/pom.xml @@ -25,6 +25,7 @@ **/*UnitTest.java + false @@ -42,6 +43,7 @@ **/*LiveTest.java + false 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 58d47c0162..dd309cec79 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 @@ -56,6 +56,6 @@ public class SeleniumExample { } public boolean isAuthorInformationAvailable() { - return webDriver.findElement(By.xpath("//*[contains(text(), 'Eugen – an engineer')]")).isDisplayed(); + return webDriver.findElement(By.xpath("//*[contains(text(), 'an engineer with a passion for teaching and building stuff on the web')]")).isDisplayed(); } } From 2d34971fcc35dbad2bdbe2bdda586c709a19fa81 Mon Sep 17 00:00:00 2001 From: maibin Date: Mon, 14 Nov 2016 09:45:01 +0100 Subject: [PATCH 71/86] Junit5 (latest two commits) (#825) * PDF to X * PDF to X * Remove created doc * Code fixes and cleanup for PDF module * Fix web.xml in spring-mvc-web-vs-initializer project * Rollback web.xml * Fixes to PDF article * Merge with main eugen branch * Junit 5 * Fix name of test and modifier --- .../com/baeldung/hexToAscii/HexToAscii.java | 46 +++++ .../equalshashcode/entities/ComplexClass.java | 63 ++++++ .../entities/PrimitiveClass.java | 54 +++++ .../equalshashcode/entities/Rectangle.java | 58 ++++++ .../equalshashcode/entities/Shape.java | 7 + .../equalshashcode/entities/Square.java | 58 ++++++ .../executable/ExecutableMavenJar.java | 11 + .../interfaces/NetworkInterfaceTest.java | 122 +++++++++++ .../java/com/baeldung/java/nio2/PathTest.java | 195 ++++++++++++++++++ .../front/controller/filters/AuditFilter.java | 25 +++ .../filters/VisitorCounterFilter.java | 23 +++ enterprise-patterns/pom.xml | 35 ++++ junit5/{REDAME.md => README.md} | 0 junit5/pom.xml | 120 ++++------- .../test/java/com/baeldung/AssertionTest.java | 29 +++ .../java/com/baeldung/AssumptionTest.java | 8 +- .../test/java/com/baeldung/ExceptionTest.java | 30 ++- .../src/test/java/com/baeldung/FirstTest.java | 6 +- .../com/baeldung/JUnit5NewFeaturesTest.java | 50 +++++ .../src/test/java/com/baeldung/LiveTest.java | 38 ++++ .../test/java/com/baeldung/NestedTest.java | 8 +- .../test/java/com/baeldung/StringUtils.java | 11 + .../test/java/com/baeldung/TaggedTest.java | 6 +- .../java/com/baeldung/suites/AllTests.java | 8 + 24 files changed, 914 insertions(+), 97 deletions(-) create mode 100644 core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java create mode 100644 core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java create mode 100644 core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java create mode 100644 core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java create mode 100644 core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java create mode 100644 core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java create mode 100644 core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java create mode 100644 core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java create mode 100644 core-java/src/test/java/com/baeldung/java/nio2/PathTest.java create mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/AuditFilter.java create mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/VisitorCounterFilter.java create mode 100644 enterprise-patterns/pom.xml rename junit5/{REDAME.md => README.md} (100%) create mode 100644 junit5/src/test/java/com/baeldung/AssertionTest.java create mode 100644 junit5/src/test/java/com/baeldung/JUnit5NewFeaturesTest.java create mode 100644 junit5/src/test/java/com/baeldung/LiveTest.java create mode 100644 junit5/src/test/java/com/baeldung/StringUtils.java create mode 100644 junit5/src/test/java/com/baeldung/suites/AllTests.java diff --git a/core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java b/core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java new file mode 100644 index 0000000000..2a3c4b109e --- /dev/null +++ b/core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java @@ -0,0 +1,46 @@ +package com.baeldung.hexToAscii; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class HexToAscii { + + @Test + public static void whenHexToAscii() { + String asciiString = "http://www.baeldung.com/jackson-serialize-dates"; + String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573"; + + assertEquals(asciiString, hexToAscii(hexEquivalent)); + } + + @Test + public static void whenAsciiToHex() { + String asciiString = "http://www.baeldung.com/jackson-serialize-dates"; + String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573"; + + assertEquals(hexEquivalent, asciiToHex(asciiString)); + } + + // + + private static String asciiToHex(String asciiStr) { + char[] chars = asciiStr.toCharArray(); + StringBuilder hex = new StringBuilder(); + for (char ch : chars) { + hex.append(Integer.toHexString((int) ch)); + } + + return hex.toString(); + } + + private static String hexToAscii(String hexStr) { + StringBuilder output = new StringBuilder(""); + for (int i = 0; i < hexStr.length(); i += 2) { + String str = hexStr.substring(i, i + 2); + output.append((char) Integer.parseInt(str, 16)); + } + return output.toString(); + } + +} diff --git a/core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java new file mode 100644 index 0000000000..6329f41252 --- /dev/null +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java @@ -0,0 +1,63 @@ +package org.baeldung.equalshashcode.entities; + +import java.util.List; +import java.util.Set; + +public class ComplexClass { + + private List genericList; + private Set integerSet; + + public ComplexClass(List genericArrayList, Set integerHashSet) { + super(); + this.genericList = genericArrayList; + this.integerSet = integerHashSet; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((genericList == null) ? 0 : genericList.hashCode()); + result = prime * result + ((integerSet == null) ? 0 : integerSet.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof ComplexClass)) + return false; + ComplexClass other = (ComplexClass) obj; + if (genericList == null) { + if (other.genericList != null) + return false; + } else if (!genericList.equals(other.genericList)) + return false; + if (integerSet == null) { + if (other.integerSet != null) + return false; + } else if (!integerSet.equals(other.integerSet)) + return false; + return true; + } + + protected List getGenericList() { + return genericList; + } + + protected void setGenericArrayList(List genericList) { + this.genericList = genericList; + } + + protected Set getIntegerSet() { + return integerSet; + } + + protected void setIntegerSet(Set integerSet) { + this.integerSet = integerSet; + } +} diff --git a/core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java new file mode 100644 index 0000000000..ebe005688c --- /dev/null +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java @@ -0,0 +1,54 @@ +package org.baeldung.equalshashcode.entities; + +public class PrimitiveClass { + + private boolean primitiveBoolean; + private int primitiveInt; + + public PrimitiveClass(boolean primitiveBoolean, int primitiveInt) { + super(); + this.primitiveBoolean = primitiveBoolean; + this.primitiveInt = primitiveInt; + } + + protected boolean isPrimitiveBoolean() { + return primitiveBoolean; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (primitiveBoolean ? 1231 : 1237); + result = prime * result + primitiveInt; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PrimitiveClass other = (PrimitiveClass) obj; + if (primitiveBoolean != other.primitiveBoolean) + return false; + if (primitiveInt != other.primitiveInt) + return false; + return true; + } + + protected void setPrimitiveBoolean(boolean primitiveBoolean) { + this.primitiveBoolean = primitiveBoolean; + } + + protected int getPrimitiveInt() { + return primitiveInt; + } + + protected void setPrimitiveInt(int primitiveInt) { + this.primitiveInt = primitiveInt; + } +} diff --git a/core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java new file mode 100644 index 0000000000..1e1423f0b3 --- /dev/null +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java @@ -0,0 +1,58 @@ +package org.baeldung.equalshashcode.entities; + +public class Rectangle extends Shape { + private double width; + private double length; + + public Rectangle(double width, double length) { + this.width = width; + this.length = length; + } + + @Override + public double area() { + return width * length; + } + + @Override + public double perimeter() { + return 2 * (width + length); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(length); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(width); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Rectangle other = (Rectangle) obj; + if (Double.doubleToLongBits(length) != Double.doubleToLongBits(other.length)) + return false; + if (Double.doubleToLongBits(width) != Double.doubleToLongBits(other.width)) + return false; + return true; + } + + protected double getWidth() { + return width; + } + + protected double getLength() { + return length; + } + +} \ No newline at end of file diff --git a/core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java new file mode 100644 index 0000000000..3bfc81da8f --- /dev/null +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java @@ -0,0 +1,7 @@ +package org.baeldung.equalshashcode.entities; + +public abstract class Shape { + public abstract double area(); + + public abstract double perimeter(); +} diff --git a/core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java new file mode 100644 index 0000000000..f11e34f0ba --- /dev/null +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java @@ -0,0 +1,58 @@ +package org.baeldung.equalshashcode.entities; + +import java.awt.Color; + +public class Square extends Rectangle { + + Color color; + + public Square(double width, Color color) { + super(width, width); + this.color = color; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((color == null) ? 0 : color.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof Square)) { + return false; + } + Square other = (Square) obj; + if (color == null) { + if (other.color != null) { + return false; + } + } else if (!color.equals(other.color)) { + return false; + } + return true; + } + + protected Color getColor() { + return color; + } + + protected void setColor(Color color) { + this.color = color; + } + +} diff --git a/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java b/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java new file mode 100644 index 0000000000..09344902b7 --- /dev/null +++ b/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java @@ -0,0 +1,11 @@ +package org.baeldung.executable; + +import javax.swing.JOptionPane; + +public class ExecutableMavenJar { + + public static void main(String[] args) { + JOptionPane.showMessageDialog(null, "It worked!", "Executable Jar with Maven", 1); + } + +} diff --git a/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java b/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java new file mode 100644 index 0000000000..4a8ef57b8f --- /dev/null +++ b/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java @@ -0,0 +1,122 @@ +package com.baeldung.java.networking.interfaces; + +import static org.junit.Assert.*; + +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.List; + +import org.junit.Test; + +public class NetworkInterfaceTest { + @Test + public void givenName_whenReturnsNetworkInterface_thenCorrect() throws SocketException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + assertNotNull(nif); + } + + @Test + public void givenInExistentName_whenReturnsNull_thenCorrect() throws SocketException { + NetworkInterface nif = NetworkInterface.getByName("inexistent_name"); + assertNull(nif); + } + + @Test + public void givenIP_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { + byte[] ip = new byte[] { 127, 0, 0, 1 }; + NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getByAddress(ip)); + assertNotNull(nif); + } + + @Test + public void givenHostName_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")); + assertNotNull(nif); + } + + @Test + public void givenLocalHost_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()); + assertNotNull(nif); + } + + @Test + public void givenLoopBack_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getLoopbackAddress()); + assertNotNull(nif); + } + + @Test + public void givenIndex_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByIndex(0); + assertNotNull(nif); + } + + @Test + public void givenInterface_whenReturnsInetAddresses_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + Enumeration addressEnum = nif.getInetAddresses(); + InetAddress address = addressEnum.nextElement(); + assertEquals("127.0.0.1", address.getHostAddress()); + } + + @Test + public void givenInterface_whenReturnsInterfaceAddresses_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + + List addressEnum = nif.getInterfaceAddresses(); + InterfaceAddress address = addressEnum.get(0); + InetAddress localAddress = address.getAddress(); + InetAddress broadCastAddress = address.getBroadcast(); + assertEquals("127.0.0.1", localAddress.getHostAddress()); + assertEquals("127.255.255.255", broadCastAddress.getHostAddress()); + } + + @Test + public void givenInterface_whenChecksIfLoopback_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + assertTrue(nif.isLoopback()); + } + + @Test + public void givenInterface_whenChecksIfUp_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + assertTrue(nif.isUp()); + } + + @Test + public void givenInterface_whenChecksIfPointToPoint_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + assertFalse(nif.isPointToPoint()); + } + + @Test + public void givenInterface_whenChecksIfVirtual_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + assertFalse(nif.isVirtual()); + } + + @Test + public void givenInterface_whenChecksMulticastSupport_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + assertTrue(nif.supportsMulticast()); + } + + @Test + public void givenInterface_whenGetsMacAddress_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("lo"); + byte[] bytes = nif.getHardwareAddress(); + assertNotNull(bytes); + } + + @Test + public void givenInterface_whenGetsMTU_thenCorrect() throws SocketException, UnknownHostException { + NetworkInterface nif = NetworkInterface.getByName("net0"); + int mtu = nif.getMTU(); + assertEquals(1500, mtu); + } +} diff --git a/core-java/src/test/java/com/baeldung/java/nio2/PathTest.java b/core-java/src/test/java/com/baeldung/java/nio2/PathTest.java new file mode 100644 index 0000000000..004aeb3deb --- /dev/null +++ b/core-java/src/test/java/com/baeldung/java/nio2/PathTest.java @@ -0,0 +1,195 @@ +package com.baeldung.java.nio2; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Date; + +import org.junit.Test; + +public class PathTest { + + private static final String HOME = System.getProperty("user.home"); + + // creating a path + @Test + public void givenPathString_whenCreatesPathObject_thenCorrect() { + Path p = Paths.get("/articles/baeldung"); + assertEquals("\\articles\\baeldung", p.toString()); + + } + + @Test + public void givenPathParts_whenCreatesPathObject_thenCorrect() { + Path p = Paths.get("/articles", "baeldung"); + assertEquals("\\articles\\baeldung", p.toString()); + + } + + // retrieving path info + @Test + public void givenPath_whenRetrievesFileName_thenCorrect() { + Path p = Paths.get("/articles/baeldung/logs"); + assertEquals("logs", p.getFileName().toString()); + } + + @Test + public void givenPath_whenRetrievesNameByIndex_thenCorrect() { + Path p = Paths.get("/articles/baeldung/logs"); + assertEquals("articles", p.getName(0).toString()); + assertEquals("baeldung", p.getName(1).toString()); + assertEquals("logs", p.getName(2).toString()); + } + + @Test + public void givenPath_whenCountsParts_thenCorrect() { + Path p = Paths.get("/articles/baeldung/logs"); + assertEquals(3, p.getNameCount()); + } + + @Test + public void givenPath_whenCanRetrieveSubsequenceByIndex_thenCorrect() { + Path p = Paths.get("/articles/baeldung/logs"); + assertEquals("articles", p.subpath(0, 1).toString()); + assertEquals("articles\\baeldung", p.subpath(0, 2).toString()); + assertEquals("articles\\baeldung\\logs", p.subpath(0, 3).toString()); + assertEquals("baeldung", p.subpath(1, 2).toString()); + assertEquals("baeldung\\logs", p.subpath(1, 3).toString()); + assertEquals("logs", p.subpath(2, 3).toString()); + } + + @Test + public void givenPath_whenRetrievesParent_thenCorrect() { + Path p1 = Paths.get("/articles/baeldung/logs"); + Path p2 = Paths.get("/articles/baeldung"); + Path p3 = Paths.get("/articles"); + Path p4 = Paths.get("/"); + + assertEquals("\\articles\\baeldung", p1.getParent().toString()); + assertEquals("\\articles", p2.getParent().toString()); + assertEquals("\\", p3.getParent().toString()); + assertEquals(null, p4.getParent()); + } + + @Test + public void givenPath_whenRetrievesRoot_thenCorrect() { + Path p1 = Paths.get("/articles/baeldung/logs"); + Path p2 = Paths.get("c:/articles/baeldung/logs"); + + assertEquals("\\", p1.getRoot().toString()); + assertEquals("c:\\", p2.getRoot().toString()); + } + + // removing redundancies from path + @Test + public void givenPath_whenRemovesRedundancies_thenCorrect1() { + Path p = Paths.get("/home/./baeldung/articles"); + p = p.normalize(); + assertEquals("\\home\\baeldung\\articles", p.toString()); + } + + @Test + public void givenPath_whenRemovesRedundancies_thenCorrect2() { + Path p = Paths.get("/home/baeldung/../articles"); + p = p.normalize(); + assertEquals("\\home\\articles", p.toString()); + } + + // converting a path + @Test + public void givenPath_whenConvertsToBrowseablePath_thenCorrect() { + Path p = Paths.get("/home/baeldung/articles.html"); + URI uri = p.toUri(); + assertEquals("file:///E:/home/baeldung/articles.html", uri.toString()); + } + + @Test + public void givenPath_whenConvertsToAbsolutePath_thenCorrect() { + Path p = Paths.get("/home/baeldung/articles.html"); + assertEquals("E:\\home\\baeldung\\articles.html", p.toAbsolutePath().toString()); + } + + @Test + public void givenAbsolutePath_whenRetainsAsAbsolute_thenCorrect() { + Path p = Paths.get("E:\\home\\baeldung\\articles.html"); + assertEquals("E:\\home\\baeldung\\articles.html", p.toAbsolutePath().toString()); + } + + @Test + public void givenExistingPath_whenGetsRealPathToFile_thenCorrect() throws IOException { + Path p = Paths.get(HOME); + assertEquals(HOME, p.toRealPath().toString()); + } + + @Test(expected = NoSuchFileException.class) + public void givenInExistentPath_whenFailsToConvert_thenCorrect() throws IOException { + Path p = Paths.get("E:\\home\\baeldung\\articles.html"); + + p.toRealPath(); + } + + // joining paths + @Test + public void givenTwoPaths_whenJoinsAndResolves_thenCorrect() throws IOException { + Path p = Paths.get("/baeldung/articles"); + assertEquals("\\baeldung\\articles\\java", p.resolve("java").toString()); + } + + @Test + public void givenAbsolutePath_whenResolutionRetainsIt_thenCorrect() throws IOException { + Path p = Paths.get("/baeldung/articles"); + assertEquals("C:\\baeldung\\articles\\java", p.resolve("C:\\baeldung\\articles\\java").toString()); + } + + @Test + public void givenPathWithRoot_whenResolutionRetainsIt_thenCorrect2() throws IOException { + Path p = Paths.get("/baeldung/articles"); + assertEquals("\\java", p.resolve("/java").toString()); + } + + // creating a path between 2 paths + @Test + public void givenSiblingPaths_whenCreatesPathToOther_thenCorrect() throws IOException { + Path p1 = Paths.get("articles"); + Path p2 = Paths.get("authors"); + assertEquals("..\\authors", p1.relativize(p2).toString()); + assertEquals("..\\articles", p2.relativize(p1).toString()); + } + + @Test + public void givenNonSiblingPaths_whenCreatesPathToOther_thenCorrect() throws IOException { + Path p1 = Paths.get("/baeldung"); + Path p2 = Paths.get("/baeldung/authors/articles"); + assertEquals("authors\\articles", p1.relativize(p2).toString()); + assertEquals("..\\..", p2.relativize(p1).toString()); + } + + // comparing 2 paths + @Test + public void givenTwoPaths_whenTestsEquality_thenCorrect() throws IOException { + Path p1 = Paths.get("/baeldung/articles"); + Path p2 = Paths.get("/baeldung/articles"); + Path p3 = Paths.get("/baeldung/authors"); + + assertTrue(p1.equals(p2)); + assertFalse(p1.equals(p3)); + } + + @Test + public void givenPath_whenInspectsStart_thenCorrect() { + Path p1 = Paths.get("/baeldung/articles"); + assertTrue(p1.startsWith("/baeldung")); + } + + @Test + public void givenPath_whenInspectsEnd_thenCorrect() { + Path p1 = Paths.get("/baeldung/articles"); + assertTrue(p1.endsWith("articles")); + } +} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/AuditFilter.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/AuditFilter.java new file mode 100644 index 0000000000..d24c0a94b3 --- /dev/null +++ b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/AuditFilter.java @@ -0,0 +1,25 @@ +package com.baeldung.enterprise.patterns.front.controller.filters; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +public class AuditFilter extends BaseFilter { + @Override + public void doFilter( + ServletRequest request, + ServletResponse response, + FilterChain chain + ) throws IOException, ServletException { + HttpServletRequest httpServletRequest = (HttpServletRequest) request; + HttpSession session = httpServletRequest.getSession(false); + if (session != null && session.getAttribute("username") != null) { + request.setAttribute("username", session.getAttribute("username")); + } + chain.doFilter(request, response); + } +} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/VisitorCounterFilter.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/VisitorCounterFilter.java new file mode 100644 index 0000000000..0ae7cd73fd --- /dev/null +++ b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/enterprise/patterns/front/controller/filters/VisitorCounterFilter.java @@ -0,0 +1,23 @@ +package com.baeldung.enterprise.patterns.front.controller.filters; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.annotation.WebFilter; +import java.io.IOException; + +@WebFilter(servletNames = "front-controller") +public class VisitorCounterFilter extends BaseFilter { + private int counter; + + @Override + public void doFilter( + ServletRequest request, + ServletResponse response, + FilterChain chain + ) throws IOException, ServletException { + request.setAttribute("counter", ++counter); + chain.doFilter(request, response); + } +} diff --git a/enterprise-patterns/pom.xml b/enterprise-patterns/pom.xml new file mode 100644 index 0000000000..036a61c44a --- /dev/null +++ b/enterprise-patterns/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + com.baeldung.enterprise.patterns + enterprise-patterns-parent + pom + + spring-dispatcher-servlet + + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + + diff --git a/junit5/REDAME.md b/junit5/README.md similarity index 100% rename from junit5/REDAME.md rename to junit5/README.md diff --git a/junit5/pom.xml b/junit5/pom.xml index 5a2ea61668..84d64e7b42 100644 --- a/junit5/pom.xml +++ b/junit5/pom.xml @@ -1,83 +1,53 @@ - - 4.0.0 + + 4.0.0 - com.baeldung - junit5 - 1.0-SNAPSHOT + com.baeldung + junit5 + 1.0-SNAPSHOT - junit5 - Intro to JUnit 5 + junit5 + Intro to JUnit 5 - - UTF-8 - 1.8 - - 5.0.0-SNAPSHOT - + + UTF-8 + 1.8 + 5.0.0-M2 + 1.0.0-M2 + - - - snapshots-repo - https://oss.sonatype.org/content/repositories/snapshots - - false - - - - always - true - - - + + + + maven-compiler-plugin + 3.1 + + ${java.version} + ${java.version} + + + + maven-surefire-plugin + 2.19 + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + - - - snapshots-repo - https://oss.sonatype.org/content/repositories/snapshots - - false - - - - always - true - - - + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + - - - - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - - - - maven-surefire-plugin - 2.19 - - - org.junit - surefire-junit5 - ${junit.gen5.version} - - - - - - - - - org.junit - junit5-api - ${junit.gen5.version} - test - - + \ No newline at end of file diff --git a/junit5/src/test/java/com/baeldung/AssertionTest.java b/junit5/src/test/java/com/baeldung/AssertionTest.java new file mode 100644 index 0000000000..70297b9073 --- /dev/null +++ b/junit5/src/test/java/com/baeldung/AssertionTest.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.expectThrows; + +import org.junit.jupiter.api.Test; + +public class AssertionTest { + + @Test + public void testConvertToDoubleThrowException() { + String age = "eighteen"; + expectThrows(NumberFormatException.class, () -> { + convertToInt(age); + }); + + assertThrows(NumberFormatException.class, () -> { + convertToInt(age); + }); + } + + private static Integer convertToInt(String str) { + if (str == null) { + return null; + } + return Integer.valueOf(str); + } + +} diff --git a/junit5/src/test/java/com/baeldung/AssumptionTest.java b/junit5/src/test/java/com/baeldung/AssumptionTest.java index e4c2b56124..f6f288e8a7 100644 --- a/junit5/src/test/java/com/baeldung/AssumptionTest.java +++ b/junit5/src/test/java/com/baeldung/AssumptionTest.java @@ -1,9 +1,11 @@ package com.baeldung; -import org.junit.gen5.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumingThat; -import static org.junit.gen5.api.Assertions.assertEquals; -import static org.junit.gen5.api.Assumptions.*; +import org.junit.jupiter.api.Test; public class AssumptionTest { diff --git a/junit5/src/test/java/com/baeldung/ExceptionTest.java b/junit5/src/test/java/com/baeldung/ExceptionTest.java index 5c30ad5b44..31a6dff657 100644 --- a/junit5/src/test/java/com/baeldung/ExceptionTest.java +++ b/junit5/src/test/java/com/baeldung/ExceptionTest.java @@ -1,18 +1,26 @@ package com.baeldung; -import org.junit.gen5.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.expectThrows; -import static org.junit.gen5.api.Assertions.assertEquals; -import static org.junit.gen5.api.Assertions.expectThrows; +import org.junit.jupiter.api.Test; public class ExceptionTest { - @Test - void shouldThrowException() { - Throwable exception = expectThrows(UnsupportedOperationException.class, - () -> { - throw new UnsupportedOperationException("Not supported"); - }); - assertEquals(exception.getMessage(), "Not supported"); - } + @Test + void shouldThrowException() { + Throwable exception = expectThrows(UnsupportedOperationException.class, () -> { + throw new UnsupportedOperationException("Not supported"); + }); + assertEquals(exception.getMessage(), "Not supported"); + } + + @Test + void assertThrowsException() { + String str = null; + assertThrows(IllegalArgumentException.class, () -> { + Integer.valueOf(str); + }); + } } diff --git a/junit5/src/test/java/com/baeldung/FirstTest.java b/junit5/src/test/java/com/baeldung/FirstTest.java index 3306dc01f9..817d8b36de 100644 --- a/junit5/src/test/java/com/baeldung/FirstTest.java +++ b/junit5/src/test/java/com/baeldung/FirstTest.java @@ -1,12 +1,12 @@ package com.baeldung; -import org.junit.gen5.api.Disabled; -import org.junit.gen5.api.Test; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.List; -import static org.junit.gen5.api.Assertions.*; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; class FirstTest { diff --git a/junit5/src/test/java/com/baeldung/JUnit5NewFeaturesTest.java b/junit5/src/test/java/com/baeldung/JUnit5NewFeaturesTest.java new file mode 100644 index 0000000000..6c790a7c8e --- /dev/null +++ b/junit5/src/test/java/com/baeldung/JUnit5NewFeaturesTest.java @@ -0,0 +1,50 @@ +package com.baeldung; + +import java.util.logging.Logger; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +//@RunWith(JUnitPlatform.class) +public class JUnit5NewFeaturesTest { + + private static final Logger log = Logger.getLogger(JUnit5NewFeaturesTest.class.getName()); + + @BeforeAll + static void setup() { + log.info("@BeforeAll - executes once before all test methods in this class"); + } + + @BeforeEach + void init() { + log.info("@BeforeEach - executes before each test method in this class"); + } + + @DisplayName("Single test successful") + @Test + void testSingleSuccessTest() { + log.info("Success"); + + } + + @Test + @Disabled("Not implemented yet.") + void testShowSomething() { + } + + @AfterEach + void tearDown() { + log.info("@AfterEach - executed after each test method."); + } + + @AfterAll + static void done() { + log.info("@AfterAll - executed after all test methods."); + } + +} diff --git a/junit5/src/test/java/com/baeldung/LiveTest.java b/junit5/src/test/java/com/baeldung/LiveTest.java new file mode 100644 index 0000000000..e0e267da0b --- /dev/null +++ b/junit5/src/test/java/com/baeldung/LiveTest.java @@ -0,0 +1,38 @@ +package com.baeldung; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + +public class LiveTest { + + private List in = new ArrayList<>(Arrays.asList("Hello", "Yes", "No")); + private List out = new ArrayList<>(Arrays.asList("Cześć", "Tak", "Nie")); + + @TestFactory + public Stream translateDynamicTestsFromStream() { + + return in.stream().map(word -> DynamicTest.dynamicTest("Test translate " + word, () -> { + int id = in.indexOf(word); + assertEquals(out.get(id), translate(word)); + })); + } + + private String translate(String word) { + if ("Hello".equalsIgnoreCase(word)) { + return "Cześć"; + } else if ("Yes".equalsIgnoreCase(word)) { + return "Tak"; + } else if ("No".equalsIgnoreCase(word)) { + return "Nie"; + } + return "Error"; + } + +} diff --git a/junit5/src/test/java/com/baeldung/NestedTest.java b/junit5/src/test/java/com/baeldung/NestedTest.java index 3fbe4f8644..b1c873e258 100644 --- a/junit5/src/test/java/com/baeldung/NestedTest.java +++ b/junit5/src/test/java/com/baeldung/NestedTest.java @@ -1,10 +1,14 @@ package com.baeldung; -import org.junit.gen5.api.*; - import java.util.EmptyStackException; import java.util.Stack; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + public class NestedTest { Stack stack; boolean isRun = false; diff --git a/junit5/src/test/java/com/baeldung/StringUtils.java b/junit5/src/test/java/com/baeldung/StringUtils.java new file mode 100644 index 0000000000..c1852113bc --- /dev/null +++ b/junit5/src/test/java/com/baeldung/StringUtils.java @@ -0,0 +1,11 @@ +package com.baeldung; + +public final class StringUtils { + + public static Double convertToDouble(String str) { + if (str == null) { + return null; + } + return Double.valueOf(str); + } +} diff --git a/junit5/src/test/java/com/baeldung/TaggedTest.java b/junit5/src/test/java/com/baeldung/TaggedTest.java index dbc82f4022..fa3a500240 100644 --- a/junit5/src/test/java/com/baeldung/TaggedTest.java +++ b/junit5/src/test/java/com/baeldung/TaggedTest.java @@ -1,9 +1,9 @@ package com.baeldung; -import org.junit.gen5.api.Tag; -import org.junit.gen5.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.gen5.api.Assertions.assertEquals; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; @Tag("Test case") public class TaggedTest { diff --git a/junit5/src/test/java/com/baeldung/suites/AllTests.java b/junit5/src/test/java/com/baeldung/suites/AllTests.java new file mode 100644 index 0000000000..24af1e733b --- /dev/null +++ b/junit5/src/test/java/com/baeldung/suites/AllTests.java @@ -0,0 +1,8 @@ +package com.baeldung.suites; + +//@RunWith(JUnitPlatform.class) +//@SelectPackages("com.baeldung") +//@SelectClasses({AssertionTest.class, AssumptionTest.class, ExceptionTest.class}) +public class AllTests { + +} From 2ffc247f9a3b2a06a1253406d60e2868131ed009 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Mon, 14 Nov 2016 18:32:42 +0530 Subject: [PATCH 72/86] BAEL-29 Review Comment - Remove Inlining Variables --- .../java/conversion/StringConversionTest.java | 103 ++++++++++++------ 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java index d4786f54ac..613b7b9522 100644 --- a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java +++ b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java @@ -2,7 +2,6 @@ package com.baeldung.java.conversion; import static org.junit.Assert.assertEquals; -import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; @@ -19,79 +18,111 @@ import com.baeldung.datetime.UseLocalDateTime; public class StringConversionTest { @Test - public void whenConvertedToInt_thenCorrect() { - assertEquals(Integer.parseInt("1"), 1); + public void whenConvedToInt_thenCorrect() { + String beforeConvStr = "1"; + int afterConvInt = 1; + + assertEquals(Integer.parseInt(beforeConvStr), afterConvInt); } @Test - public void whenConvertedToInteger_thenCorrect() { - assertEquals(Integer.valueOf("12").equals(12), true); + public void whenConvedToInteger_thenCorrect() { + String beforeConvStr = "12"; + Integer afterConvInteger = 12; + + assertEquals(Integer.valueOf(beforeConvStr).equals(afterConvInteger), true); } @Test - public void whenConvertedTolong_thenCorrect() { - assertEquals(Long.parseLong("12345"), 12345); + public void whenConvedTolong_thenCorrect() { + String beforeConvStr = "12345"; + long afterConvLongPrimitive = 12345; + + assertEquals(Long.parseLong(beforeConvStr), afterConvLongPrimitive); } @Test - public void whenConvertedToLong_thenCorrect() { - assertEquals(Long.valueOf("14567").equals(14567L), true); + public void whenConvedToLong_thenCorrect() { + String beforeConvStr = "14567"; + Long afterConvLong = 14567l; + + assertEquals(Long.valueOf(beforeConvStr).equals(afterConvLong), true); } @Test - public void whenConvertedTodouble_thenCorrect() { - assertEquals(Double.parseDouble("1.4"), 1.4, 0.0); + public void whenConvedTodouble_thenCorrect() { + String beforeConvStr = "1.4"; + double afterConvDoublePrimitive = 1.4; + + assertEquals(Double.parseDouble(beforeConvStr), afterConvDoublePrimitive, 0.0); } @Test - public void whenConvertedToDouble_thenCorrect() { - assertEquals(Double.valueOf("145.67").equals(145.67d), true); + public void whenConvedToDouble_thenCorrect() { + String beforeConvStr = "145.67"; + double afterConvDouble = 145.67d; + + assertEquals(Double.valueOf(beforeConvStr).equals(afterConvDouble), true); } @Test - public void whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException { - byte[] byteArray1 = new byte[] { 'a', 'b', 'c' }; - String string = new String(byteArray1, "UTF-8"); + public void whenConvedToByteArr_thenCorrect() { + String beforeConvStr = "abc"; + byte[] afterConvByteArr = new byte[] { 'a', 'b', 'c' }; - assertEquals(Arrays.equals(string.getBytes(), byteArray1), true); + assertEquals(Arrays.equals(beforeConvStr.getBytes(), afterConvByteArr), true); } @Test - public void whenConvertedToboolean_thenCorrect() { - assertEquals(Boolean.parseBoolean("true"), true); + public void whenConvedToboolean_thenCorrect() { + String beforeConvStr = "true"; + boolean afterConvBooleanPrimitive = true; + + assertEquals(Boolean.parseBoolean(beforeConvStr), afterConvBooleanPrimitive); } @Test - public void whenConvertedToBoolean_thenCorrect() { - assertEquals(Boolean.valueOf("true"), true); + public void whenConvedToBoolean_thenCorrect() { + String beforeConvStr = "true"; + Boolean afterConvBoolean = true; + + assertEquals(Boolean.valueOf(beforeConvStr), afterConvBoolean); } @Test - public void whenConvertedToCharArray_thenCorrect() { - String str = "hello"; - char[] charArray = { 'h', 'e', 'l', 'l', 'o' }; + public void whenConvedToCharArr_thenCorrect() { + String beforeConvStr = "hello"; + char[] afterConvCharArr = { 'h', 'e', 'l', 'l', 'o' }; - assertEquals(Arrays.equals(charArray, str.toCharArray()), true); + assertEquals(Arrays.equals(beforeConvStr.toCharArray(), afterConvCharArr), true); } @Test - public void whenConvertedToDate_thenCorrect() throws ParseException { - String str = "15/10/2013"; + public void whenConvedToDate_thenCorrect() throws ParseException { + String beforeConvStr = "15/10/2013"; + int afterConvCalendarDay = 15; + int afterConvCalendarMonth = 9; + int afterConvCalendarYear = 2013; SimpleDateFormat formatter = new SimpleDateFormat("dd/M/yyyy"); - Date date1 = formatter.parse(str); - Calendar calendar = new GregorianCalendar(2013, 9, 15); - Date date2 = calendar.getTime(); + Date afterConvDate = formatter.parse(beforeConvStr); + Calendar calendar = new GregorianCalendar(); + calendar.setTime(afterConvDate); - assertEquals(date1.compareTo(date2), 0); + assertEquals(calendar.get(Calendar.DAY_OF_MONTH), afterConvCalendarDay); + assertEquals(calendar.get(Calendar.MONTH), afterConvCalendarMonth); + assertEquals(calendar.get(Calendar.YEAR), afterConvCalendarYear); } @Test - public void whenConvertedToLocalDateTime_thenCorrect() throws ParseException { + public void whenConvedToLocalDateTime_thenCorrect() { String str = "2007-12-03T10:15:30"; - LocalDateTime localDateTime = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); + int afterConvCalendarDay = 03; + Month afterConvCalendarMonth = Month.DECEMBER; + int afterConvCalendarYear = 2007; + LocalDateTime afterConvDate = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); - assertEquals(localDateTime.getDayOfMonth(), 3); - assertEquals(localDateTime.getMonth(), Month.DECEMBER); - assertEquals(localDateTime.getYear(), 2007); + assertEquals(afterConvDate.getDayOfMonth(), afterConvCalendarDay); + assertEquals(afterConvDate.getMonth(), afterConvCalendarMonth); + assertEquals(afterConvDate.getYear(), afterConvCalendarYear); } } From 710a932f268f9fd06d702f4262b2310a480e6481 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Mon, 14 Nov 2016 18:53:14 +0530 Subject: [PATCH 73/86] Refactoring Code --- .../java/conversion/StringConversionTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java index 613b7b9522..9a4ac053af 100644 --- a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java +++ b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java @@ -18,7 +18,7 @@ import com.baeldung.datetime.UseLocalDateTime; public class StringConversionTest { @Test - public void whenConvedToInt_thenCorrect() { + public void whenConvertedToInt_thenCorrect() { String beforeConvStr = "1"; int afterConvInt = 1; @@ -26,7 +26,7 @@ public class StringConversionTest { } @Test - public void whenConvedToInteger_thenCorrect() { + public void whenConvertedToInteger_thenCorrect() { String beforeConvStr = "12"; Integer afterConvInteger = 12; @@ -34,7 +34,7 @@ public class StringConversionTest { } @Test - public void whenConvedTolong_thenCorrect() { + public void whenConvertedTolong_thenCorrect() { String beforeConvStr = "12345"; long afterConvLongPrimitive = 12345; @@ -42,7 +42,7 @@ public class StringConversionTest { } @Test - public void whenConvedToLong_thenCorrect() { + public void whenConvertedToLong_thenCorrect() { String beforeConvStr = "14567"; Long afterConvLong = 14567l; @@ -50,7 +50,7 @@ public class StringConversionTest { } @Test - public void whenConvedTodouble_thenCorrect() { + public void whenConvertedTodouble_thenCorrect() { String beforeConvStr = "1.4"; double afterConvDoublePrimitive = 1.4; @@ -58,7 +58,7 @@ public class StringConversionTest { } @Test - public void whenConvedToDouble_thenCorrect() { + public void whenConvertedToDouble_thenCorrect() { String beforeConvStr = "145.67"; double afterConvDouble = 145.67d; @@ -66,7 +66,7 @@ public class StringConversionTest { } @Test - public void whenConvedToByteArr_thenCorrect() { + public void whenConvertedToByteArr_thenCorrect() { String beforeConvStr = "abc"; byte[] afterConvByteArr = new byte[] { 'a', 'b', 'c' }; @@ -74,7 +74,7 @@ public class StringConversionTest { } @Test - public void whenConvedToboolean_thenCorrect() { + public void whenConvertedToboolean_thenCorrect() { String beforeConvStr = "true"; boolean afterConvBooleanPrimitive = true; @@ -82,7 +82,7 @@ public class StringConversionTest { } @Test - public void whenConvedToBoolean_thenCorrect() { + public void whenConvertedToBoolean_thenCorrect() { String beforeConvStr = "true"; Boolean afterConvBoolean = true; @@ -90,7 +90,7 @@ public class StringConversionTest { } @Test - public void whenConvedToCharArr_thenCorrect() { + public void whenConvertedToCharArr_thenCorrect() { String beforeConvStr = "hello"; char[] afterConvCharArr = { 'h', 'e', 'l', 'l', 'o' }; @@ -98,7 +98,7 @@ public class StringConversionTest { } @Test - public void whenConvedToDate_thenCorrect() throws ParseException { + public void whenConvertedToDate_thenCorrect() throws ParseException { String beforeConvStr = "15/10/2013"; int afterConvCalendarDay = 15; int afterConvCalendarMonth = 9; @@ -114,7 +114,7 @@ public class StringConversionTest { } @Test - public void whenConvedToLocalDateTime_thenCorrect() { + public void whenConvertedToLocalDateTime_thenCorrect() { String str = "2007-12-03T10:15:30"; int afterConvCalendarDay = 03; Month afterConvCalendarMonth = Month.DECEMBER; From 2385fe04b182fbc36235cd58ab693b6327c41bc5 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Mon, 14 Nov 2016 19:06:29 +0530 Subject: [PATCH 74/86] Refactoring Code --- .../com/baeldung/java/conversion/StringConversionTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java index 9a4ac053af..09cacd0a29 100644 --- a/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java +++ b/core-java/src/test/java/com/baeldung/java/conversion/StringConversionTest.java @@ -119,7 +119,8 @@ public class StringConversionTest { int afterConvCalendarDay = 03; Month afterConvCalendarMonth = Month.DECEMBER; int afterConvCalendarYear = 2007; - LocalDateTime afterConvDate = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); + LocalDateTime afterConvDate + = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); assertEquals(afterConvDate.getDayOfMonth(), afterConvCalendarDay); assertEquals(afterConvDate.getMonth(), afterConvCalendarMonth); From 0110a3f75e84541134118e36ac765115598be720 Mon Sep 17 00:00:00 2001 From: "nguyenminhtuanfit@gmail.com" Date: Mon, 14 Nov 2016 21:14:09 +0700 Subject: [PATCH 75/86] change pointcut name --- aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj b/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj index 3bdddd22a8..2ddf03192b 100644 --- a/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj +++ b/aspectj/src/main/java/com/baeldung/aspectj/AccountAspect.aj @@ -24,7 +24,7 @@ public aspect AccountAspect { } } - after(int amount, Account balance) : callAtWithDraw(amount, balance) { + after(int amount, Account balance) : callWithDraw(amount, balance) { logger.info("Balance after withdrawal : {}", balance.balance); } } From 315e1aa9cd6102dab222522f8d818a6d87668062 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 14 Nov 2016 16:26:41 +0100 Subject: [PATCH 76/86] Remove duplicate file --- .../com/baeldung/hexToAscii/HexToAscii.java | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java diff --git a/core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java b/core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java deleted file mode 100644 index 2a3c4b109e..0000000000 --- a/core-java/src/main/java/com/baeldung/hexToAscii/HexToAscii.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.hexToAscii; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class HexToAscii { - - @Test - public static void whenHexToAscii() { - String asciiString = "http://www.baeldung.com/jackson-serialize-dates"; - String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573"; - - assertEquals(asciiString, hexToAscii(hexEquivalent)); - } - - @Test - public static void whenAsciiToHex() { - String asciiString = "http://www.baeldung.com/jackson-serialize-dates"; - String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573"; - - assertEquals(hexEquivalent, asciiToHex(asciiString)); - } - - // - - private static String asciiToHex(String asciiStr) { - char[] chars = asciiStr.toCharArray(); - StringBuilder hex = new StringBuilder(); - for (char ch : chars) { - hex.append(Integer.toHexString((int) ch)); - } - - return hex.toString(); - } - - private static String hexToAscii(String hexStr) { - StringBuilder output = new StringBuilder(""); - for (int i = 0; i < hexStr.length(); i += 2) { - String str = hexStr.substring(i, i + 2); - output.append((char) Integer.parseInt(str, 16)); - } - return output.toString(); - } - -} From 8e2ad9323311958a4e8161c011b6187980bdb104 Mon Sep 17 00:00:00 2001 From: Sameera Date: Mon, 14 Nov 2016 22:31:50 +0530 Subject: [PATCH 77/86] Adding SHA-256 hashing impl and test classes --- core-java/pom.xml | 5 ++ .../com/baeldung/hashing/SHA256Hashing.java | 51 +++++++++++++++++++ .../baeldung/hashing/SHA256HashingTest.java | 37 ++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/hashing/SHA256Hashing.java create mode 100644 core-java/src/test/java/com/baeldung/hashing/SHA256HashingTest.java diff --git a/core-java/pom.xml b/core-java/pom.xml index 8b93e238eb..17d9c2ce64 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -46,6 +46,11 @@ 3.3 + + org.bouncycastle + bcprov-jdk15on + 1.55 + diff --git a/core-java/src/main/java/com/baeldung/hashing/SHA256Hashing.java b/core-java/src/main/java/com/baeldung/hashing/SHA256Hashing.java new file mode 100644 index 0000000000..9c8fc86e7a --- /dev/null +++ b/core-java/src/main/java/com/baeldung/hashing/SHA256Hashing.java @@ -0,0 +1,51 @@ +package com.baeldung.hashing; + + +import com.google.common.hash.Hashing; +import org.apache.commons.codec.digest.DigestUtils; +import org.bouncycastle.util.encoders.Hex; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SHA256Hashing { + + public static String HashWithJavaMessageDigest(final String originalString) + throws NoSuchAlgorithmException { + final MessageDigest digest = MessageDigest.getInstance("SHA-256"); + final byte[] encodedhash = digest.digest( + originalString.getBytes(StandardCharsets.UTF_8)); + return bytesToHex(encodedhash); + } + + public static String HashWithGuava(final String originalString) { + final String sha256hex = Hashing.sha256().hashString( + originalString, StandardCharsets.UTF_8).toString(); + return sha256hex; + } + + public static String HashWithApacheCommons(final String originalString) { + final String sha256hex = DigestUtils.sha256Hex(originalString); + return sha256hex; + } + + public static String HashWithBouncyCastle(final String originalString) + throws NoSuchAlgorithmException { + final MessageDigest digest = MessageDigest.getInstance("SHA-256"); + final byte[] hash = digest.digest( + originalString.getBytes(StandardCharsets.UTF_8)); + final String sha256hex = new String(Hex.encode(hash)); + return sha256hex; + } + + private static String bytesToHex(byte[] hash) { + StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if(hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } +} diff --git a/core-java/src/test/java/com/baeldung/hashing/SHA256HashingTest.java b/core-java/src/test/java/com/baeldung/hashing/SHA256HashingTest.java new file mode 100644 index 0000000000..dc496d589b --- /dev/null +++ b/core-java/src/test/java/com/baeldung/hashing/SHA256HashingTest.java @@ -0,0 +1,37 @@ +package com.baeldung.hashing; + +import org.junit.Test; + +import static org.junit.Assert.*; + + +public class SHA256HashingTest { + + private static String originalValue = "abc123"; + private static String hashedValue = + "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090"; + + @Test + public void testHashWithJavaMessageDigest() throws Exception { + final String currentHashedValue = SHA256Hashing.HashWithJavaMessageDigest(originalValue); + assertEquals(currentHashedValue, hashedValue); + } + + @Test + public void testHashWithGuava() throws Exception { + final String currentHashedValue = SHA256Hashing.HashWithApacheCommons(originalValue); + assertEquals(currentHashedValue, hashedValue); + } + + @Test + public void testHashWithApacheCommans() throws Exception { + final String currentHashedValue = SHA256Hashing.HashWithGuava(originalValue); + assertEquals(currentHashedValue, hashedValue); + } + + @Test + public void testHashWithBouncyCastle() throws Exception { + final String currentHashedValue = SHA256Hashing.HashWithBouncyCastle(originalValue); + assertEquals(currentHashedValue, hashedValue); + } +} \ No newline at end of file From a323947704278a150ddd357969b8b95c61b7fcde Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Mon, 14 Nov 2016 23:43:37 +0100 Subject: [PATCH 78/86] BAEL-86 - rename main class --- ...cationInitializer.java => DispatcherServletApplication.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/{WebApplicationInitializer.java => DispatcherServletApplication.java} (92%) diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/WebApplicationInitializer.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/DispatcherServletApplication.java similarity index 92% rename from spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/WebApplicationInitializer.java rename to spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/DispatcherServletApplication.java index 016e4a8b4c..181fb3f405 100644 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/WebApplicationInitializer.java +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/DispatcherServletApplication.java @@ -9,7 +9,7 @@ import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; -public class WebApplicationInitializer implements org.springframework.web.WebApplicationInitializer { +public class DispatcherServletApplication implements org.springframework.web.WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = From 3914a5d41751a2ffac8f88c74bfd53f9ca0a3519 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Tue, 15 Nov 2016 06:36:28 +0100 Subject: [PATCH 79/86] BAEL-89 - splitting controller and main application class --- .../src/main/resources/application.properties | 6 ++++- .../JettyWebApplication.java | 13 +---------- .../{tomcatex => jettyex}/SecurityConfig.java | 2 +- .../{tomcatex => jettyex}/SessionConfig.java | 2 +- .../session/jettyex/TestController.java | 12 ++++++++++ .../session/tomcatex/TestController.java | 23 +++++++++++++++++++ .../tomcatex/TomcatWebApplication.java | 15 ------------ 7 files changed, 43 insertions(+), 30 deletions(-) rename spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/{tomcatex => jettyex}/JettyWebApplication.java (57%) rename spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/{tomcatex => jettyex}/SecurityConfig.java (94%) rename spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/{tomcatex => jettyex}/SessionConfig.java (93%) create mode 100644 spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/TestController.java create mode 100644 spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TestController.java diff --git a/spring-cloud/spring-cloud-bootstrap/config/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/config/src/main/resources/application.properties index 6c47d001f4..212586f0ea 100644 --- a/spring-cloud/spring-cloud-bootstrap/config/src/main/resources/application.properties +++ b/spring-cloud/spring-cloud-bootstrap/config/src/main/resources/application.properties @@ -5,4 +5,8 @@ spring.cloud.config.server.git.uri=file:///${user.home}/application-config eureka.client.region = default eureka.client.registryFetchIntervalSeconds = 5 -eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ \ No newline at end of file +eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ + +security.user.name=configUser +security.user.password=configPassword +security.user.role=SYSTEM \ No newline at end of file diff --git a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/JettyWebApplication.java b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java similarity index 57% rename from spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/JettyWebApplication.java rename to spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java index 7bbc776eaa..41503c3d9e 100644 --- a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/JettyWebApplication.java +++ b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java @@ -1,8 +1,7 @@ -package com.baeldung.spring.session.tomcatex; +package com.baeldung.spring.session.jettyex; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @@ -11,14 +10,4 @@ public class JettyWebApplication { public static void main(String[] args) { SpringApplication.run(JettyWebApplication.class, args); } - - @RequestMapping - public String helloJetty() { - return "hello Jetty"; - } - - @RequestMapping("/test") - public String lksjdf() { - return ""; - } } diff --git a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/SecurityConfig.java b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/SecurityConfig.java similarity index 94% rename from spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/SecurityConfig.java rename to spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/SecurityConfig.java index 6ed7df9218..28cdb3cc08 100644 --- a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/SecurityConfig.java +++ b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/SecurityConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.session.tomcatex; +package com.baeldung.spring.session.jettyex; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/SessionConfig.java b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/SessionConfig.java similarity index 93% rename from spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/SessionConfig.java rename to spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/SessionConfig.java index f261f66f9d..735ae7fb43 100644 --- a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/SessionConfig.java +++ b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/SessionConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.session.tomcatex; +package com.baeldung.spring.session.jettyex; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/TestController.java b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/TestController.java new file mode 100644 index 0000000000..f5c82f2260 --- /dev/null +++ b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/TestController.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.session.jettyex; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + @RequestMapping + public String helloJetty() { + return "hello Jetty"; + } +} \ No newline at end of file diff --git a/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TestController.java b/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TestController.java new file mode 100644 index 0000000000..877f29e1d3 --- /dev/null +++ b/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TestController.java @@ -0,0 +1,23 @@ +package com.baeldung.spring.session.tomcatex; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + @RequestMapping + public String helloDefault() { + return "hello default"; + } + + @RequestMapping("/tomcat") + public String helloTomcat() { + return "hello tomcat"; + } + + @RequestMapping("/tomcat/admin") + public String helloTomcatAdmin() { + return "hello tomcat admin"; + } +} diff --git a/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java b/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java index 58c6b807ec..683a4a1f15 100644 --- a/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java +++ b/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java @@ -11,19 +11,4 @@ public class TomcatWebApplication { public static void main(String[] args) { SpringApplication.run(TomcatWebApplication.class, args); } - - @RequestMapping - public String helloDefault() { - return "hello default"; - } - - @RequestMapping("/tomcat") - public String helloTomcat() { - return "hello tomcat"; - } - - @RequestMapping("/tomcat/admin") - public String helloTomcatAdmin() { - return "hello tomcat admin"; - } } From 3c254fad0bef21108675dbd2fa4f45c59a3049e8 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Tue, 15 Nov 2016 07:04:56 +0100 Subject: [PATCH 80/86] BAEL-80 - file copy java config --- .../com/baeldung/samples/FileCopyConfig.java | 72 +++++++++++++++++++ .../src/main/resources/log4j.xml | 28 ++++++++ .../com/baeldung/samples/FileCopyTest.java | 14 ++-- 3 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java create mode 100644 spring-integration/src/main/resources/log4j.xml diff --git a/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java b/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java new file mode 100644 index 0000000000..e7cf43e902 --- /dev/null +++ b/spring-integration/src/main/java/com/baeldung/samples/FileCopyConfig.java @@ -0,0 +1,72 @@ +package com.baeldung.samples; + +import java.io.File; +import java.util.Scanner; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.integration.annotation.InboundChannelAdapter; +import org.springframework.integration.annotation.Poller; +import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.core.MessageSource; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.integration.file.FileWritingMessageHandler; +import org.springframework.integration.file.filters.SimplePatternFileListFilter; +import org.springframework.integration.file.support.FileExistsMode; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHandler; + +@Configuration +@EnableIntegration +public class FileCopyConfig { + + public final String INPUT_DIR = "source"; + public final String OUTPUT_DIR = "target"; + public final String FILE_PATTERN = ".jpg"; + + @Bean + public MessageChannel fileChannel() { + return new DirectChannel(); + } + + @Bean + @InboundChannelAdapter(value = "fileChannel", poller = @Poller(fixedDelay = "10000")) + public MessageSource fileReadingMessageSource() { + FileReadingMessageSource sourceReader = new FileReadingMessageSource(); + sourceReader.setDirectory(new File(INPUT_DIR)); + sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN)); + return sourceReader; + } + + @Bean + @ServiceActivator(inputChannel = "fileChannel") + public MessageHandler fileWritingMessageHandler() { + FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(OUTPUT_DIR)); + handler.setFileExistsMode(FileExistsMode.REPLACE); + return handler; + } + + public static void main(final String... args) { + final AbstractApplicationContext context = new AnnotationConfigApplicationContext(FileCopyConfig.class.getCanonicalName()); + context.registerShutdownHook(); + final Scanner scanner = new Scanner(System.in); + System.out.print("Please enter a string and press : "); + while (true) { + final String input = scanner.nextLine(); + if ("q".equals(input.trim())) { + context.close(); + scanner.close(); + break; + } + } + System.exit(0); + } + +} + + + diff --git a/spring-integration/src/main/resources/log4j.xml b/spring-integration/src/main/resources/log4j.xml new file mode 100644 index 0000000000..cfa93a8037 --- /dev/null +++ b/spring-integration/src/main/resources/log4j.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration/src/test/java/com/baeldung/samples/FileCopyTest.java b/spring-integration/src/test/java/com/baeldung/samples/FileCopyTest.java index 96e5a98f41..567d181972 100644 --- a/spring-integration/src/test/java/com/baeldung/samples/FileCopyTest.java +++ b/spring-integration/src/test/java/com/baeldung/samples/FileCopyTest.java @@ -17,11 +17,10 @@ package com.baeldung.samples; import org.apache.log4j.Logger; import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import java.util.Scanner; - /** * Starts the Spring Context and will initialize the Spring Integration routes. @@ -35,15 +34,10 @@ public final class FileCopyTest { private static final Logger LOGGER = Logger.getLogger(FileCopyTest.class); @Test - public void test() throws InterruptedException { - - - final AbstractApplicationContext context = - new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/spring-integration-file-copy-context.xml"); - + public void whenFileCopyConfiguration_thanFileCopiedSuccessfully() throws InterruptedException { + final AbstractApplicationContext context = new AnnotationConfigApplicationContext(FileCopyConfig.class.getCanonicalName()); + context.registerShutdownHook(); Thread.sleep(5000); - - } @Test From 62d58599c5dc9fc4b4ed309d3340362bd4801f17 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Tue, 15 Nov 2016 21:23:04 +0100 Subject: [PATCH 81/86] BAEL-89 - removing @RestController from application classes --- .../com/baeldung/spring/session/jettyex/JettyWebApplication.java | 1 - .../baeldung/spring/session/tomcatex/TomcatWebApplication.java | 1 - 2 files changed, 2 deletions(-) diff --git a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java index 41503c3d9e..f692d0ff23 100644 --- a/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java +++ b/spring-session/jetty-session-demo/src/main/java/com/baeldung/spring/session/jettyex/JettyWebApplication.java @@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication -@RestController public class JettyWebApplication { public static void main(String[] args) { SpringApplication.run(JettyWebApplication.class, args); diff --git a/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java b/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java index 683a4a1f15..b7e26027d8 100644 --- a/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java +++ b/spring-session/tomcat-session-demo/src/main/java/com/baeldung/spring/session/tomcatex/TomcatWebApplication.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication -@RestController public class TomcatWebApplication { public static void main(String[] args) { SpringApplication.run(TomcatWebApplication.class, args); From efc24501236ab94540c7a70a6a9d964923136314 Mon Sep 17 00:00:00 2001 From: Pritam Banerjee Date: Sat, 15 Oct 2016 23:40:20 +0200 Subject: [PATCH 82/86] BAEL 317: Setting up EJB EJB Client and EJB Remote --- ejb/ejb-client/pom.xml | 28 +++++++ .../com/baeldung/ejb/client/EJBClient.java | 71 ++++++++++++++++ .../resources/jboss-ejb-client.properties | 8 ++ .../baeldung/ejb/setup/test/EJBSetupTest.java | 16 ++++ ejb/ejb-remote/pom.xml | 25 ++++++ .../com/baeldung/ejb/tutorial/HelloWorld.java | 8 ++ .../baeldung/ejb/tutorial/HelloWorldBean.java | 18 ++++ .../src/main/resources/META-INF/ejb-jar.xml | 7 ++ ejb/pom.xml | 83 +++++++++++++++++++ 9 files changed, 264 insertions(+) create mode 100644 ejb/ejb-client/pom.xml create mode 100644 ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java create mode 100644 ejb/ejb-client/src/main/resources/jboss-ejb-client.properties create mode 100644 ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java create mode 100644 ejb/ejb-remote/pom.xml create mode 100644 ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java create mode 100644 ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java create mode 100644 ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml create mode 100644 ejb/pom.xml diff --git a/ejb/ejb-client/pom.xml b/ejb/ejb-client/pom.xml new file mode 100644 index 0000000000..d1d245ba6d --- /dev/null +++ b/ejb/ejb-client/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + com.baeldung.ejb + ejb + 1.0-SNAPSHOT + + ejb-client + EJB3 Client Maven + EJB3 Client Maven + + + + org.wildfly + wildfly-ejb-client-bom + pom + import + + + com.baeldung.ejb + ejb-remote + ejb + + + + \ No newline at end of file diff --git a/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java b/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java new file mode 100644 index 0000000000..5426bbdc81 --- /dev/null +++ b/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java @@ -0,0 +1,71 @@ +package com.baeldung.ejb.client; + +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import com.baeldung.ejb.tutorial.HelloWorld; + +public class EJBClient { + + public EJBClient() { + } + + private Context context = null; + + public String getEJBRemoteMessage() { + EJBClient main = new EJBClient(); + try { + // 1. Obtaining Context + main.createInitialContext(); + // 2. Generate JNDI Lookup name and caste + HelloWorld helloWorld = main.lookup(); + return helloWorld.getHelloWorld(); + } catch (NamingException e) { + e.printStackTrace(); + return ""; + } finally { + try { + main.closeContext(); + } catch (NamingException e) { + e.printStackTrace(); + } + } + } + + public HelloWorld lookup() throws NamingException { + + // The app name is the EAR name of the deployed EJB without .ear suffix. + // Since we haven't deployed the application as a .ear, the app name for + // us will be an empty string + final String appName = ""; + final String moduleName = "remote"; + final String distinctName = ""; + final String beanName = "HelloWorld"; + final String viewClassName = HelloWorld.class.getName(); + final String toLookup = "ejb:" + appName + "/" + moduleName + + "/" + distinctName + "/" + beanName + "!" + viewClassName; + return (HelloWorld) context.lookup(toLookup); + } + + public void createInitialContext() throws NamingException { + Properties prop = new Properties(); + prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); + prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); + prop.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080"); + prop.put(Context.SECURITY_PRINCIPAL, "pritamtest"); + prop.put(Context.SECURITY_CREDENTIALS, "iamtheki9g"); + prop.put("jboss.naming.client.ejb.context", false); + + context = new InitialContext(prop); + } + + public void closeContext() throws NamingException { + if (context != null) { + context.close(); + } + } + +} diff --git a/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties b/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties new file mode 100644 index 0000000000..e17d8ba17e --- /dev/null +++ b/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties @@ -0,0 +1,8 @@ +remote.connections=default +remote.connection.default.host=127.0.0.1 +remote.connection.default.port=8080 +remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false +remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false +remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=${host.auth:JBOSS-LOCAL-USER} +remote.connection.default.username=pritamtest +remote.connection.default.password=iamtheki9g \ No newline at end of file diff --git a/ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java b/ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java new file mode 100644 index 0000000000..1a8165cee6 --- /dev/null +++ b/ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java @@ -0,0 +1,16 @@ +package com.baeldung.ejb.setup.test; + +import static org.junit.Assert.*; +import org.junit.Test; +import com.baeldung.ejb.client.EJBClient; +import com.baeldung.ejb.tutorial.HelloWorldBean; + +public class EJBSetupTest { + + @Test + public void testEJBClient() { + EJBClient ejbClient = new EJBClient(); + HelloWorldBean bean = new HelloWorldBean(); + assertEquals(bean.getHelloWorld(), ejbClient.getEJBRemoteMessage()); + } +} diff --git a/ejb/ejb-remote/pom.xml b/ejb/ejb-remote/pom.xml new file mode 100644 index 0000000000..14c02edd0e --- /dev/null +++ b/ejb/ejb-remote/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.baeldung.ejb + ejb + 1.0-SNAPSHOT + + ejb-remote + ejb + + ejb-remote + + + org.jboss.spec.javax.ejb + jboss-ejb-api_3.2_spec + provided + + + + + ejb-remote + + \ No newline at end of file diff --git a/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java new file mode 100644 index 0000000000..79684de1a8 --- /dev/null +++ b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java @@ -0,0 +1,8 @@ +package com.baeldung.ejb.tutorial; + +import javax.ejb.Remote; + +@Remote +public interface HelloWorld { + String getHelloWorld(); +} diff --git a/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java new file mode 100644 index 0000000000..6c5ee34afe --- /dev/null +++ b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java @@ -0,0 +1,18 @@ +package com.baeldung.ejb.tutorial; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateless; + +@Stateless(name = "HelloWorld") +public class HelloWorldBean implements HelloWorld { + + @Resource + private SessionContext context; + + @Override + public String getHelloWorld() { + return "Welcome to EJB Tutorial!"; + } + +} diff --git a/ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml b/ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml new file mode 100644 index 0000000000..d6c2200198 --- /dev/null +++ b/ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml @@ -0,0 +1,7 @@ + + + remote + + diff --git a/ejb/pom.xml b/ejb/pom.xml new file mode 100644 index 0000000000..49ddc694e9 --- /dev/null +++ b/ejb/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + com.baeldung.ejb + ejb + 1.0-SNAPSHOT + pom + ejb + EJB Tutorial + + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + + + com.baeldung.ejb + ejb-remote + 1.0-SNAPSHOT + ejb + + + + org.jboss.spec + jboss-javaee-7.0 + 1.0.1.Final + pom + import + + + + org.wildfly + wildfly-ejb-client-bom + 10.1.0.Final + pom + import + + + + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + maven-ejb-plugin + 2.4 + + 3.2 + + + + + + + + ejb-remote + ejb-client + + \ No newline at end of file From 35ee1b89bbce2df2517d066d9e166da011a1a9df Mon Sep 17 00:00:00 2001 From: Pritam Banerjee Date: Mon, 7 Nov 2016 11:06:51 +0100 Subject: [PATCH 83/86] BAEL-317 - Updated Wildfly configurations and changed the files --- ejb/ejb-remote/pom.xml | 18 ++++++++++++++++-- ejb/pom.xml | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ejb/ejb-remote/pom.xml b/ejb/ejb-remote/pom.xml index 14c02edd0e..3661fa5b2c 100644 --- a/ejb/ejb-remote/pom.xml +++ b/ejb/ejb-remote/pom.xml @@ -10,7 +10,7 @@ ejb-remote ejb - ejb-remote + org.jboss.spec.javax.ejb @@ -20,6 +20,20 @@ - ejb-remote + + + org.wildfly.plugins + wildfly-maven-plugin + 1.1.0.Alpha5 + + 127.0.0.1 + 9990 + pritamtest + iamtheki9g + ${build.finalName}.jar + + + + \ No newline at end of file diff --git a/ejb/pom.xml b/ejb/pom.xml index 49ddc694e9..5c54cdcf72 100644 --- a/ejb/pom.xml +++ b/ejb/pom.xml @@ -60,8 +60,8 @@ maven-compiler-plugin 3.1 - 1.7 - 1.7 + 1.8 + 1.8 From 0262d2728f4b2cfcee4b74f6ed44fa09f6f06970 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Wed, 16 Nov 2016 07:21:01 +0100 Subject: [PATCH 84/86] BAEL-317 - Added junit and surefire, updated the authentication info so that it fits the article --- ejb/ejb-client/pom.xml | 72 +++++++++++++------ .../com/baeldung/ejb/client/EJBClient.java | 4 +- .../resources/jboss-ejb-client.properties | 4 +- ejb/ejb-remote/pom.xml | 4 +- .../baeldung/ejb/tutorial/HelloWorldBean.java | 5 -- 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/ejb/ejb-client/pom.xml b/ejb/ejb-client/pom.xml index d1d245ba6d..772e4056d3 100644 --- a/ejb/ejb-client/pom.xml +++ b/ejb/ejb-client/pom.xml @@ -1,28 +1,54 @@ - 4.0.0 - - com.baeldung.ejb - ejb - 1.0-SNAPSHOT - - ejb-client - EJB3 Client Maven - EJB3 Client Maven + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + + com.baeldung.ejb + ejb + 1.0-SNAPSHOT + + ejb-client + EJB3 Client Maven + EJB3 Client Maven + + 4.12 + 2.19.1 + + + + + org.wildfly + wildfly-ejb-client-bom + pom + import + + + com.baeldung.ejb + ejb-remote + ejb + + + + junit + junit + ${junit.version} + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*EJBSetupTest.java + + + + + - - - org.wildfly - wildfly-ejb-client-bom - pom - import - - - com.baeldung.ejb - ejb-remote - ejb - - \ No newline at end of file diff --git a/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java b/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java index 5426bbdc81..08286d580e 100644 --- a/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java +++ b/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java @@ -55,8 +55,8 @@ public class EJBClient { prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); prop.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080"); - prop.put(Context.SECURITY_PRINCIPAL, "pritamtest"); - prop.put(Context.SECURITY_CREDENTIALS, "iamtheki9g"); + prop.put(Context.SECURITY_PRINCIPAL, "testUser"); + prop.put(Context.SECURITY_CREDENTIALS, "admin1234!"); prop.put("jboss.naming.client.ejb.context", false); context = new InitialContext(prop); diff --git a/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties b/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties index e17d8ba17e..077cd7583f 100644 --- a/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties +++ b/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties @@ -4,5 +4,5 @@ remote.connection.default.port=8080 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=${host.auth:JBOSS-LOCAL-USER} -remote.connection.default.username=pritamtest -remote.connection.default.password=iamtheki9g \ No newline at end of file +remote.connection.default.username=testUser +remote.connection.default.password=admin1234! \ No newline at end of file diff --git a/ejb/ejb-remote/pom.xml b/ejb/ejb-remote/pom.xml index 3661fa5b2c..65bfc6dbec 100644 --- a/ejb/ejb-remote/pom.xml +++ b/ejb/ejb-remote/pom.xml @@ -28,8 +28,8 @@ 127.0.0.1 9990 - pritamtest - iamtheki9g + testUser + admin1234! ${build.finalName}.jar diff --git a/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java index 6c5ee34afe..4b88747e6a 100644 --- a/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java +++ b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java @@ -1,15 +1,10 @@ package com.baeldung.ejb.tutorial; -import javax.annotation.Resource; -import javax.ejb.SessionContext; import javax.ejb.Stateless; @Stateless(name = "HelloWorld") public class HelloWorldBean implements HelloWorld { - @Resource - private SessionContext context; - @Override public String getHelloWorld() { return "Welcome to EJB Tutorial!"; From 69427b6cad4754f435f92a17b3a197d953a8aa47 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Wed, 16 Nov 2016 07:28:35 +0100 Subject: [PATCH 85/86] BAEL-317 Adding JUnit and surefire plugin, updating auth info to fit the article --- ejb/ejb-client/pom.xml | 0 .../src/main/java/com/baeldung/ejb/client/EJBClient.java | 0 ejb/ejb-client/src/main/resources/jboss-ejb-client.properties | 0 .../src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java | 0 ejb/ejb-remote/pom.xml | 0 .../src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java | 0 .../src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java | 0 ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml | 0 ejb/pom.xml | 0 9 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ejb/ejb-client/pom.xml mode change 100644 => 100755 ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java mode change 100644 => 100755 ejb/ejb-client/src/main/resources/jboss-ejb-client.properties mode change 100644 => 100755 ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java mode change 100644 => 100755 ejb/ejb-remote/pom.xml mode change 100644 => 100755 ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java mode change 100644 => 100755 ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java mode change 100644 => 100755 ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml mode change 100644 => 100755 ejb/pom.xml diff --git a/ejb/ejb-client/pom.xml b/ejb/ejb-client/pom.xml old mode 100644 new mode 100755 diff --git a/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java b/ejb/ejb-client/src/main/java/com/baeldung/ejb/client/EJBClient.java old mode 100644 new mode 100755 diff --git a/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties b/ejb/ejb-client/src/main/resources/jboss-ejb-client.properties old mode 100644 new mode 100755 diff --git a/ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java b/ejb/ejb-client/src/test/java/com/baeldung/ejb/setup/test/EJBSetupTest.java old mode 100644 new mode 100755 diff --git a/ejb/ejb-remote/pom.xml b/ejb/ejb-remote/pom.xml old mode 100644 new mode 100755 diff --git a/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorld.java old mode 100644 new mode 100755 diff --git a/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java b/ejb/ejb-remote/src/main/java/com/baeldung/ejb/tutorial/HelloWorldBean.java old mode 100644 new mode 100755 diff --git a/ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml b/ejb/ejb-remote/src/main/resources/META-INF/ejb-jar.xml old mode 100644 new mode 100755 diff --git a/ejb/pom.xml b/ejb/pom.xml old mode 100644 new mode 100755 From 4681d3d1728512bc22650b1fc107efcbed45ceef Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Wed, 16 Nov 2016 07:44:56 +0100 Subject: [PATCH 86/86] BAEL-80 - Adding wildcard to filename --- .../src/main/java/com/baeldung/samples/FileCopyConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 : ");