SlideShare a Scribd company logo
1 of 27
 
 
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],< bean  id = &quot;mailSender&quot; class = &quot;org.springframework.mail.javamail.JavaMailSenderImpl&quot; > < property  name = &quot;host&quot;  value = &quot;host.url.com.br&quot;  /> < property  name = &quot;password&quot;  value = &quot;senha&quot;  /> < property  name = &quot;username&quot;  value = &quot;username@host.com.br&quot;  /> </ bean >   < bean  id = &quot;simpleMailMessage&quot; class = &quot;org.springframework.mail.SimpleMailMessage&quot; > < constructor-arg  index = &quot;0&quot;  ref = &quot;templateMessage&quot;  /> < property  name = &quot;to&quot;  value = &quot;to@server.com&quot;  /> < property  name = &quot;text&quot;  value = &quot; 123 Testando... &quot;  /> </ bean >
package  com.targettrust.spring.email; import  org.springframework.context.ApplicationContext; import  org.springframework.context.support.ClassPathXmlApplicationContext; import  org.springframework.mail.MailException; import  org.springframework.mail.MailSender; import  org.springframework.mail.SimpleMailMessage; public   class  TesteEnviaEmail { public   static   void  main(String[] args) { ApplicationContext ac =  new   ClassPathXmlApplicationContext( &quot;/com/targettrust/spring/email/Spring-beans.xml&quot; );  SimpleMailMessage msg = (SimpleMailMessage)ac.getBean( &quot;simpleMailMessage&quot; ); MailSender ms = (MailSender)ac.getBean( &quot;mailSender&quot; ); try { ms.send(msg); } catch (MailException ex) {  ex.printStackTrace();  } } }
package  com.targettrust.spring.email; import  java.io.File; import  javax.mail.internet.MimeMessage; import  org.springframework.context.ApplicationContext; import  org.springframework.context.support.ClassPathXmlApplicationContext; import  org.springframework.core.io.FileSystemResource; import  org.springframework.mail.javamail.JavaMailSender; import  org.springframework.mail.javamail.MimeMessageHelper; public   class  TesteMimeMessageHelperAtt { public   static   void  main( String [] args) { ApplicationContext ac =  new  ClassPathXmlApplicationContext( &quot;/com/targettrust/spring/email/Spring-beans.xml&quot; ); JavaMailSender ms = (JavaMailSender)ac.getBean( &quot;mailSender&quot; ); try { MimeMessage message = ms.createMimeMessage(); MimeMessageHelper helper =  new  MimeMessageHelper(message, true ); helper.setFrom( &quot;from@server.com.br&quot; ); helper.setTo( &quot;to@server.com&quot; ); helper.setText( &quot;Email MimeMessageHelper&quot; ); FileSystemResource file =  new  FileSystemResource( new   File( &quot;.&quot; ).getCanonicalPath() +  &quot;/build.xml&quot; ); helper.addAttachment( &quot;build.xml&quot; , file); ms.send(message); } catch (Exception e){   e.printStackTrace(); } } }
package  com.targettrust.spring.email; import  java.io.File; import  javax.mail.internet.MimeMessage; import  org.springframework.context.ApplicationContext; import  org.springframework.context.support.ClassPathXmlApplicationContext; import  org.springframework.core.io.FileSystemResource; import  org.springframework.mail.javamail.JavaMailSender; import  org.springframework.mail.javamail.MimeMessageHelper; public   class  TesteMimeMessageHelperAttImg { public   static   void  main(String[] args) { ApplicationContext ac =  new  ClassPathXmlApplicationContext( &quot;/com/targettrust/spring/email/Spring-beans.xml&quot; ); JavaMailSender ms = (JavaMailSender)ac.getBean( &quot;mailSender&quot; ); try { MimeMessage message = ms.createMimeMessage(); MimeMessageHelper helper =  new  MimeMessageHelper(message, true ); helper.setFrom( &quot;form@server.com.br&quot; ); helper.setTo( &quot;dest@server.com&quot; ); helper.setText( &quot;<html><body><img src='cid:img1'><br>Email MimeMessageHelper com suporte a imagems em linha!</body></html>&quot; , true ); FileSystemResource file =  new  FileSystemResource( new   File( &quot;.&quot; ).getCanonicalPath() +  &quot;/imagem.jpg&quot; ); helper.addInline( &quot;img1&quot; , file); ms.send(message); } catch (Exception e){ e.printStackTrace(); } } }
[object Object],[object Object],[object Object],[object Object],[object Object]
package  com.targettrust.spring.jdktask; import  java.util.Date; import  java.util.TimerTask; public   class  HoraCertaService  extends  TimerTask{ @Override @SuppressWarnings ( &quot;deprecation&quot; ) public   void  run() { System. out .println( new  Date().getHours()  +  &quot;:&quot;  +    new  Date().getMinutes() +  &quot;:&quot;  +   new  Date().getSeconds()   ); } }
<? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot; ?> < beans  xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean  id = &quot;horaCertaService&quot; class = &quot;com.targettrust.spring.jdktask.HoraCertaService&quot;  /> < bean  id = &quot;scheduledTask&quot; class = &quot;org.springframework.scheduling.timer.ScheduledTimerTask&quot; lazy-init = &quot;false&quot; > <!-- Espera 0 ms antes de iniciar --> < property  name = &quot;delay&quot;  value = &quot;0&quot;  /> <!-- roda de 1 em 1 segundo --> < property  name = &quot;period&quot;  value = &quot;1000&quot;  /> <!-- Ira executar a TimerTask horaCertaService --> < property  name = &quot;timerTask&quot;  ref = &quot;horaCertaService&quot;  /> </ bean > </ beans >
< bean  id = &quot;timerFactory“        class = &quot;org.springframework.scheduling.timer.TimerFactoryBean” > < property  name = &quot;scheduledTimerTasks&quot; >   < list >   < ref  bean = &quot;scheduledTask&quot;  />   </ list > </ property > </ bean >
<? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot; ?> < beans  xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean  id = &quot;horaCertaServiceNaoAcoplada&quot; class = &quot;com.targettrust.spring.jdktask.HoraCertaServiceNaoAcoplada“ /> < bean  id = &quot;scheduledTask“  lazy-init = &quot;false&quot; class = &quot;org.springframework.scheduling.timer.ScheduledTimerTask” > <!-- Espera 0 ms antes de iniciar --> < property  name = &quot;delay&quot;  value = &quot;0&quot;  /> <!-- roda de 1 em 1 segundo --> < property  name = &quot;period&quot;  value = &quot;1000&quot;  /> <!-- Ira executar a TimerTask horaCertaService --> < property  name = &quot;timerTask&quot;  ref = &quot;executor&quot;  /> </ bean > < bean  id = &quot;executor&quot;  class = &quot;org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean“ > < property  name = &quot;targetObject&quot;  ref = &quot;horaCertaServiceNaoAcoplada&quot;  /> < property  name = &quot;targetMethod&quot;  value = &quot;showTime&quot;  />   </ bean > < bean  id = &quot;timerFactory&quot;  class = &quot;org.springframework.scheduling.timer.TimerFactoryBean“ > < property  name = &quot;scheduledTimerTasks&quot; > < list >   < ref  bean = &quot;scheduledTask&quot;  /> </ list > </ property > </ bean > </ beans >
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
 
package  com.targettrust.spring.aop; public   interface  Service { public   void  fazAlgo(); }   package  com.targettrust.spring.aop; import  org.apache.commons.logging.Log; import  org.apache.commons.logging.LogFactory; public   class  ServiceA  implements  Service{ private   static   final  Log  log  = LogFactory. getLog (ServiceA. class ); @Override public   void  fazAlgo() { log .info( &quot;Fiz algo do tipo A&quot; ); } }   package  com.targettrust.spring.aop; import  org.apache.commons.logging.Log; import  org.apache.commons.logging.LogFactory; public   class  ServiceB  implements  Service{ private   static   final  Log  log  = LogFactory. getLog (ServiceB. class ); @Override public   void  fazAlgo() { log .info( &quot;Fiz algo do tipo B&quot; ); } }
package  com.targettrust.spring.aop; import  org.apache.commons.logging.Log; import  org.apache.commons.logging.LogFactory; public   class  ServiceC  implements  Service{ private   static   final  Log  log  = LogFactory. getLog (ServiceC. class ); @Override public   void  fazAlgo() { log .info( &quot;Fiz algo do tipo C&quot; ); } }
<? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot; ?> < beans  xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:aop = &quot;http://www.springframework.org/schema/aop&quot; xmlns:tx = &quot;http://www.springframework.org/schema/tx&quot; xsi:schemaLocation = &quot; http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd&quot; > < aop:aspectj-autoproxy /> < bean  id = &quot;aspecto“  lazy-init = &quot;false&quot; class = &quot;com.targettrust.spring.aop.Aspecto“ /> < bean  id = &quot;sa“  class = &quot;com.targettrust.spring.aop.ServiceA“  /> < bean  id = &quot;sb“  class = &quot;com.targettrust.spring.aop.ServiceB“  /> < bean  id = &quot;sc“  class = &quot;com.targettrust.spring.aop.ServiceC“  /> < bean  id = &quot;services“  class = &quot;java.util.ArrayList“  > < constructor-arg  index = &quot;0&quot; > < list > < ref  bean = &quot;sa&quot;  /> < ref  bean = &quot;sb&quot;  /> < ref  bean = &quot;sc&quot;  /> </ list > </ constructor-arg > </ bean > </ beans >
package  com.targettrust.spring.aop; import  org.apache.commons.logging.Log; import  org.apache.commons.logging.LogFactory; import  org.aspectj.lang.ProceedingJoinPoint; import  org.aspectj.lang.annotation.After; import  org.aspectj.lang.annotation.Around; import  org.aspectj.lang.annotation.Aspect; import  org.aspectj.lang.annotation.Before; @Aspect public   class  Aspecto { private   static   final  Log  log  = LogFactory. getLog (Aspecto. class ); @Before ( &quot;execution(* com.targettrust.spring.aop.Service.*(..))&quot; ) public   void  execucaoDeFazAlgoAntes() { log .info( &quot;To sabendo antes da execu ç ão de Service&quot; ); } @After ( &quot;execution(* com.targettrust.spring.aop.Service.*(..))&quot; ) public   void  execucaoDeFazAlgoDepois() { log .info( &quot;To sabendo depois da execu ç ão de Serice&quot; ); } @Around ( &quot;execution(* com.targettrust.spring.aop.ServiceB.faz*(..)))&quot; )  public  Object doBasicProfiling(ProceedingJoinPoint pjp)  throws  Throwable {   Object retVal = pjp.proceed();   log .info( &quot;To sabendo around SericeB&quot; );   return  retVal; } }
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
package  com.targettrust.spring.testing; import  java.util.Date; import  junit.framework.Assert; import  org.springframework.test.AbstractDependencyInjectionSpringContextTests; public   class  TestDataService  extends  AbstractDependencyInjectionSpringContextTests { private  DataService  dataService ; public   void  setDataService(DataService dataService) { this . dataService  = dataService; } @Override protected  String[] getConfigLocations() {   return   new  String[]{ &quot;classpath:com/targettrust/spring/testing/Spring-beans.xml&quot; }; } @SuppressWarnings ( &quot;deprecation&quot; ) public   void  testDataDoDataService(){ Date d =  dataService .getSysDate(); Date l =  new  Date(); Assert. assertEquals (d.getDay(),l.getDay()); Assert. assertEquals (d.getMonth(),l.getMonth()); Assert. assertEquals (d.getYear(),l.getYear()); } }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
package  com.targettrust.spring.remoting; import  java.util.Date; public   interface  HoraService { public  Date getDate(); }   package  com.targettrust.spring.remoting; import  java.util.Calendar; import  java.util.Date; public   class  HoraServiceImpl  implements  HoraService{ public  Date getDate() { return  Calendar. getInstance ().getTime(); } }   <? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot; ?> < beans  xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean  id = &quot;horaService&quot;  class = &quot;com.targettrust.spring.remoting.HoraServiceImpl”  />     < bean  class = &quot;org.springframework.remoting.rmi.RmiServiceExporter” > < property  name = &quot;serviceName&quot;  value = &quot;Target-HoraService&quot; /> < property  name = &quot;service&quot;  ref = &quot;horaService&quot; /> < property  name = &quot;serviceInterface“  value = &quot;com.targettrust.spring.remoting.HoraService&quot; /> < property  name = &quot;registryPort&quot;    value = &quot;1199&quot; /> </ bean > </ beans >
<? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot; ?> < beans  xmlns = “ http://www.springframework.org/schema/beans ” xmlns:xsi = “ http://www.w3.org/2001/XMLSchema-instance ” xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean  id = &quot;horaService” class = &quot;org.springframework.remoting.rmi.RmiProxyFactoryBean&quot; > < property  name = &quot;serviceUrl&quot;    value = &quot;rmi://localhost:1199/Target-HoraService&quot; /> < property  name = &quot;serviceInterface&quot;  value = &quot;com.targettrust.spring.remoting.HoraService&quot; /> </ bean > </ beans >
[object Object],[object Object],[object Object]

More Related Content

What's hot

The MetaCPAN VM for Dummies Part One (Installation)
The MetaCPAN VM for Dummies Part One (Installation)The MetaCPAN VM for Dummies Part One (Installation)
The MetaCPAN VM for Dummies Part One (Installation)Olaf Alders
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python MeetupAreski Belaid
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with JasmineTim Tyrrell
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.jsMatthew Beale
 
Flask patterns
Flask patternsFlask patterns
Flask patternsit-people
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queueAlex Eftimie
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit TestingPrince Norin
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineJavier de Pedro López
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Edureka!
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Andres Almiray
 

What's hot (20)

The MetaCPAN VM for Dummies Part One (Installation)
The MetaCPAN VM for Dummies Part One (Installation)The MetaCPAN VM for Dummies Part One (Installation)
The MetaCPAN VM for Dummies Part One (Installation)
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
 
Perlbal Tutorial
Perlbal TutorialPerlbal Tutorial
Perlbal Tutorial
 
My java file
My java fileMy java file
My java file
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
Practical Celery
Practical CeleryPractical Celery
Practical Celery
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queue
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
 
Servlet11
Servlet11Servlet11
Servlet11
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 

Viewers also liked

Agile tem que morrer? Já morreu? Hacker way? BS ou mais do mesmo?
Agile tem que morrer? Já morreu?  Hacker way? BS ou mais do mesmo?Agile tem que morrer? Já morreu?  Hacker way? BS ou mais do mesmo?
Agile tem que morrer? Já morreu? Hacker way? BS ou mais do mesmo?Diego Pacheco
 
Agile culture & Mindsets
Agile culture & MindsetsAgile culture & Mindsets
Agile culture & MindsetsDiego Pacheco
 
EXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui Arch
EXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui ArchEXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui Arch
EXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui ArchDiego Pacheco
 
Contracts and models
Contracts and modelsContracts and models
Contracts and modelsDiego Pacheco
 
Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...
Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...
Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...Diego Pacheco
 
Cloud-Native DevOps Engineering
Cloud-Native DevOps EngineeringCloud-Native DevOps Engineering
Cloud-Native DevOps EngineeringDiego Pacheco
 
Microservices reativos usando a stack do Netflix na AWS
Microservices reativos usando a stack do Netflix na AWSMicroservices reativos usando a stack do Netflix na AWS
Microservices reativos usando a stack do Netflix na AWSDiego Pacheco
 

Viewers also liked (19)

Apache flink
Apache flinkApache flink
Apache flink
 
Lean the principles
Lean the principlesLean the principles
Lean the principles
 
Agile tem que morrer? Já morreu? Hacker way? BS ou mais do mesmo?
Agile tem que morrer? Já morreu?  Hacker way? BS ou mais do mesmo?Agile tem que morrer? Já morreu?  Hacker way? BS ou mais do mesmo?
Agile tem que morrer? Já morreu? Hacker way? BS ou mais do mesmo?
 
ML and R
ML and RML and R
ML and R
 
Apache mesos
Apache mesosApache mesos
Apache mesos
 
Agile culture & Mindsets
Agile culture & MindsetsAgile culture & Mindsets
Agile culture & Mindsets
 
EXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui Arch
EXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui ArchEXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui Arch
EXTRA: Workshop SOA, Microservices e Devops - Discoverability + Ui Arch
 
Avout
AvoutAvout
Avout
 
Docker
DockerDocker
Docker
 
Contracts and models
Contracts and modelsContracts and models
Contracts and models
 
Knox
KnoxKnox
Knox
 
Vert.x
Vert.xVert.x
Vert.x
 
Spring Capitulo 01
Spring Capitulo 01Spring Capitulo 01
Spring Capitulo 01
 
Twitter Bootstrap
Twitter BootstrapTwitter Bootstrap
Twitter Bootstrap
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
 
Cassandra
CassandraCassandra
Cassandra
 
Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...
Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...
Cloud Native, Microservices and SRE/Chaos Engineering: The new Rules of The G...
 
Cloud-Native DevOps Engineering
Cloud-Native DevOps EngineeringCloud-Native DevOps Engineering
Cloud-Native DevOps Engineering
 
Microservices reativos usando a stack do Netflix na AWS
Microservices reativos usando a stack do Netflix na AWSMicroservices reativos usando a stack do Netflix na AWS
Microservices reativos usando a stack do Netflix na AWS
 

Similar to Spring Capitulo 05

ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
Struts2
Struts2Struts2
Struts2yuvalb
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
AJAX Workshop Notes
AJAX Workshop NotesAJAX Workshop Notes
AJAX Workshop NotesPamela Fox
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate BustersHamletDRC
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog SampleSkills Matter
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008inovex GmbH
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorialjbarciauskas
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Steve Souders
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0Matt Raible
 
JMS Introduction
JMS IntroductionJMS Introduction
JMS IntroductionAlex Su
 

Similar to Spring Capitulo 05 (20)

ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Os Leonard
Os LeonardOs Leonard
Os Leonard
 
Jsp
JspJsp
Jsp
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Jsp And Jdbc
Jsp And JdbcJsp And Jdbc
Jsp And Jdbc
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Struts2
Struts2Struts2
Struts2
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
AJAX Workshop Notes
AJAX Workshop NotesAJAX Workshop Notes
AJAX Workshop Notes
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
 
Riding Apache Camel
Riding Apache CamelRiding Apache Camel
Riding Apache Camel
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorial
 
สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
JMS Introduction
JMS IntroductionJMS Introduction
JMS Introduction
 

More from Diego Pacheco

Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Diego Pacheco
 
Continuous Discovery Habits Book Review.pdf
Continuous Discovery Habits  Book Review.pdfContinuous Discovery Habits  Book Review.pdf
Continuous Discovery Habits Book Review.pdfDiego Pacheco
 
Thoughts about Shape Up
Thoughts about Shape UpThoughts about Shape Up
Thoughts about Shape UpDiego Pacheco
 
Encryption Deep Dive
Encryption Deep DiveEncryption Deep Dive
Encryption Deep DiveDiego Pacheco
 
Management: Doing the non-obvious! III
Management: Doing the non-obvious! IIIManagement: Doing the non-obvious! III
Management: Doing the non-obvious! IIIDiego Pacheco
 
Design is not Subjective
Design is not SubjectiveDesign is not Subjective
Design is not SubjectiveDiego Pacheco
 
Architecture & Engineering : Doing the non-obvious!
Architecture & Engineering :  Doing the non-obvious!Architecture & Engineering :  Doing the non-obvious!
Architecture & Engineering : Doing the non-obvious!Diego Pacheco
 
Management doing the non-obvious II
Management doing the non-obvious II Management doing the non-obvious II
Management doing the non-obvious II Diego Pacheco
 
Testing in production
Testing in productionTesting in production
Testing in productionDiego Pacheco
 
Nine lies about work
Nine lies about workNine lies about work
Nine lies about workDiego Pacheco
 
Management: doing the nonobvious!
Management: doing the nonobvious!Management: doing the nonobvious!
Management: doing the nonobvious!Diego Pacheco
 
Dealing with dependencies
Dealing  with dependenciesDealing  with dependencies
Dealing with dependenciesDiego Pacheco
 
Dealing with dependencies in tests
Dealing  with dependencies in testsDealing  with dependencies in tests
Dealing with dependencies in testsDiego Pacheco
 

More from Diego Pacheco (20)

Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!
 
Continuous Discovery Habits Book Review.pdf
Continuous Discovery Habits  Book Review.pdfContinuous Discovery Habits  Book Review.pdf
Continuous Discovery Habits Book Review.pdf
 
Thoughts about Shape Up
Thoughts about Shape UpThoughts about Shape Up
Thoughts about Shape Up
 
Holacracy
HolacracyHolacracy
Holacracy
 
AWS IAM
AWS IAMAWS IAM
AWS IAM
 
CDKs
CDKsCDKs
CDKs
 
Encryption Deep Dive
Encryption Deep DiveEncryption Deep Dive
Encryption Deep Dive
 
Sec 101
Sec 101Sec 101
Sec 101
 
Reflections on SCM
Reflections on SCMReflections on SCM
Reflections on SCM
 
Management: Doing the non-obvious! III
Management: Doing the non-obvious! IIIManagement: Doing the non-obvious! III
Management: Doing the non-obvious! III
 
Design is not Subjective
Design is not SubjectiveDesign is not Subjective
Design is not Subjective
 
Architecture & Engineering : Doing the non-obvious!
Architecture & Engineering :  Doing the non-obvious!Architecture & Engineering :  Doing the non-obvious!
Architecture & Engineering : Doing the non-obvious!
 
Management doing the non-obvious II
Management doing the non-obvious II Management doing the non-obvious II
Management doing the non-obvious II
 
Testing in production
Testing in productionTesting in production
Testing in production
 
Nine lies about work
Nine lies about workNine lies about work
Nine lies about work
 
Management: doing the nonobvious!
Management: doing the nonobvious!Management: doing the nonobvious!
Management: doing the nonobvious!
 
AI and the Future
AI and the FutureAI and the Future
AI and the Future
 
Dealing with dependencies
Dealing  with dependenciesDealing  with dependencies
Dealing with dependencies
 
Dealing with dependencies in tests
Dealing  with dependencies in testsDealing  with dependencies in tests
Dealing with dependencies in tests
 
Kanban 2020
Kanban 2020Kanban 2020
Kanban 2020
 

Spring Capitulo 05

  • 1.  
  • 2.  
  • 3.
  • 4.
  • 5.
  • 6. package com.targettrust.spring.email; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.mail.MailException; import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; public class TesteEnviaEmail { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext( &quot;/com/targettrust/spring/email/Spring-beans.xml&quot; ); SimpleMailMessage msg = (SimpleMailMessage)ac.getBean( &quot;simpleMailMessage&quot; ); MailSender ms = (MailSender)ac.getBean( &quot;mailSender&quot; ); try { ms.send(msg); } catch (MailException ex) { ex.printStackTrace(); } } }
  • 7. package com.targettrust.spring.email; import java.io.File; import javax.mail.internet.MimeMessage; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; public class TesteMimeMessageHelperAtt { public static void main( String [] args) { ApplicationContext ac = new ClassPathXmlApplicationContext( &quot;/com/targettrust/spring/email/Spring-beans.xml&quot; ); JavaMailSender ms = (JavaMailSender)ac.getBean( &quot;mailSender&quot; ); try { MimeMessage message = ms.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true ); helper.setFrom( &quot;from@server.com.br&quot; ); helper.setTo( &quot;to@server.com&quot; ); helper.setText( &quot;Email MimeMessageHelper&quot; ); FileSystemResource file = new FileSystemResource( new File( &quot;.&quot; ).getCanonicalPath() + &quot;/build.xml&quot; ); helper.addAttachment( &quot;build.xml&quot; , file); ms.send(message); } catch (Exception e){ e.printStackTrace(); } } }
  • 8. package com.targettrust.spring.email; import java.io.File; import javax.mail.internet.MimeMessage; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; public class TesteMimeMessageHelperAttImg { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext( &quot;/com/targettrust/spring/email/Spring-beans.xml&quot; ); JavaMailSender ms = (JavaMailSender)ac.getBean( &quot;mailSender&quot; ); try { MimeMessage message = ms.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true ); helper.setFrom( &quot;form@server.com.br&quot; ); helper.setTo( &quot;dest@server.com&quot; ); helper.setText( &quot;<html><body><img src='cid:img1'><br>Email MimeMessageHelper com suporte a imagems em linha!</body></html>&quot; , true ); FileSystemResource file = new FileSystemResource( new File( &quot;.&quot; ).getCanonicalPath() + &quot;/imagem.jpg&quot; ); helper.addInline( &quot;img1&quot; , file); ms.send(message); } catch (Exception e){ e.printStackTrace(); } } }
  • 9.
  • 10. package com.targettrust.spring.jdktask; import java.util.Date; import java.util.TimerTask; public class HoraCertaService extends TimerTask{ @Override @SuppressWarnings ( &quot;deprecation&quot; ) public void run() { System. out .println( new Date().getHours() + &quot;:&quot; + new Date().getMinutes() + &quot;:&quot; + new Date().getSeconds() ); } }
  • 11. <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean id = &quot;horaCertaService&quot; class = &quot;com.targettrust.spring.jdktask.HoraCertaService&quot; /> < bean id = &quot;scheduledTask&quot; class = &quot;org.springframework.scheduling.timer.ScheduledTimerTask&quot; lazy-init = &quot;false&quot; > <!-- Espera 0 ms antes de iniciar --> < property name = &quot;delay&quot; value = &quot;0&quot; /> <!-- roda de 1 em 1 segundo --> < property name = &quot;period&quot; value = &quot;1000&quot; /> <!-- Ira executar a TimerTask horaCertaService --> < property name = &quot;timerTask&quot; ref = &quot;horaCertaService&quot; /> </ bean > </ beans >
  • 12. < bean id = &quot;timerFactory“ class = &quot;org.springframework.scheduling.timer.TimerFactoryBean” > < property name = &quot;scheduledTimerTasks&quot; > < list > < ref bean = &quot;scheduledTask&quot; /> </ list > </ property > </ bean >
  • 13. <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean id = &quot;horaCertaServiceNaoAcoplada&quot; class = &quot;com.targettrust.spring.jdktask.HoraCertaServiceNaoAcoplada“ /> < bean id = &quot;scheduledTask“ lazy-init = &quot;false&quot; class = &quot;org.springframework.scheduling.timer.ScheduledTimerTask” > <!-- Espera 0 ms antes de iniciar --> < property name = &quot;delay&quot; value = &quot;0&quot; /> <!-- roda de 1 em 1 segundo --> < property name = &quot;period&quot; value = &quot;1000&quot; /> <!-- Ira executar a TimerTask horaCertaService --> < property name = &quot;timerTask&quot; ref = &quot;executor&quot; /> </ bean > < bean id = &quot;executor&quot; class = &quot;org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean“ > < property name = &quot;targetObject&quot; ref = &quot;horaCertaServiceNaoAcoplada&quot; /> < property name = &quot;targetMethod&quot; value = &quot;showTime&quot; /> </ bean > < bean id = &quot;timerFactory&quot; class = &quot;org.springframework.scheduling.timer.TimerFactoryBean“ > < property name = &quot;scheduledTimerTasks&quot; > < list > < ref bean = &quot;scheduledTask&quot; /> </ list > </ property > </ bean > </ beans >
  • 14.
  • 15.  
  • 16.  
  • 17. package com.targettrust.spring.aop; public interface Service { public void fazAlgo(); } package com.targettrust.spring.aop; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ServiceA implements Service{ private static final Log log = LogFactory. getLog (ServiceA. class ); @Override public void fazAlgo() { log .info( &quot;Fiz algo do tipo A&quot; ); } } package com.targettrust.spring.aop; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ServiceB implements Service{ private static final Log log = LogFactory. getLog (ServiceB. class ); @Override public void fazAlgo() { log .info( &quot;Fiz algo do tipo B&quot; ); } }
  • 18. package com.targettrust.spring.aop; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ServiceC implements Service{ private static final Log log = LogFactory. getLog (ServiceC. class ); @Override public void fazAlgo() { log .info( &quot;Fiz algo do tipo C&quot; ); } }
  • 19. <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:aop = &quot;http://www.springframework.org/schema/aop&quot; xmlns:tx = &quot;http://www.springframework.org/schema/tx&quot; xsi:schemaLocation = &quot; http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd&quot; > < aop:aspectj-autoproxy /> < bean id = &quot;aspecto“ lazy-init = &quot;false&quot; class = &quot;com.targettrust.spring.aop.Aspecto“ /> < bean id = &quot;sa“ class = &quot;com.targettrust.spring.aop.ServiceA“ /> < bean id = &quot;sb“ class = &quot;com.targettrust.spring.aop.ServiceB“ /> < bean id = &quot;sc“ class = &quot;com.targettrust.spring.aop.ServiceC“ /> < bean id = &quot;services“ class = &quot;java.util.ArrayList“ > < constructor-arg index = &quot;0&quot; > < list > < ref bean = &quot;sa&quot; /> < ref bean = &quot;sb&quot; /> < ref bean = &quot;sc&quot; /> </ list > </ constructor-arg > </ bean > </ beans >
  • 20. package com.targettrust.spring.aop; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class Aspecto { private static final Log log = LogFactory. getLog (Aspecto. class ); @Before ( &quot;execution(* com.targettrust.spring.aop.Service.*(..))&quot; ) public void execucaoDeFazAlgoAntes() { log .info( &quot;To sabendo antes da execu ç ão de Service&quot; ); } @After ( &quot;execution(* com.targettrust.spring.aop.Service.*(..))&quot; ) public void execucaoDeFazAlgoDepois() { log .info( &quot;To sabendo depois da execu ç ão de Serice&quot; ); } @Around ( &quot;execution(* com.targettrust.spring.aop.ServiceB.faz*(..)))&quot; ) public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { Object retVal = pjp.proceed(); log .info( &quot;To sabendo around SericeB&quot; ); return retVal; } }
  • 21.
  • 22.
  • 23. package com.targettrust.spring.testing; import java.util.Date; import junit.framework.Assert; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; public class TestDataService extends AbstractDependencyInjectionSpringContextTests { private DataService dataService ; public void setDataService(DataService dataService) { this . dataService = dataService; } @Override protected String[] getConfigLocations() { return new String[]{ &quot;classpath:com/targettrust/spring/testing/Spring-beans.xml&quot; }; } @SuppressWarnings ( &quot;deprecation&quot; ) public void testDataDoDataService(){ Date d = dataService .getSysDate(); Date l = new Date(); Assert. assertEquals (d.getDay(),l.getDay()); Assert. assertEquals (d.getMonth(),l.getMonth()); Assert. assertEquals (d.getYear(),l.getYear()); } }
  • 24.
  • 25. package com.targettrust.spring.remoting; import java.util.Date; public interface HoraService { public Date getDate(); } package com.targettrust.spring.remoting; import java.util.Calendar; import java.util.Date; public class HoraServiceImpl implements HoraService{ public Date getDate() { return Calendar. getInstance ().getTime(); } } <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean id = &quot;horaService&quot; class = &quot;com.targettrust.spring.remoting.HoraServiceImpl” /> < bean class = &quot;org.springframework.remoting.rmi.RmiServiceExporter” > < property name = &quot;serviceName&quot; value = &quot;Target-HoraService&quot; /> < property name = &quot;service&quot; ref = &quot;horaService&quot; /> < property name = &quot;serviceInterface“ value = &quot;com.targettrust.spring.remoting.HoraService&quot; /> < property name = &quot;registryPort&quot; value = &quot;1199&quot; /> </ bean > </ beans >
  • 26. <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = “ http://www.springframework.org/schema/beans ” xmlns:xsi = “ http://www.w3.org/2001/XMLSchema-instance ” xsi:schemaLocation = &quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot; > < bean id = &quot;horaService” class = &quot;org.springframework.remoting.rmi.RmiProxyFactoryBean&quot; > < property name = &quot;serviceUrl&quot; value = &quot;rmi://localhost:1199/Target-HoraService&quot; /> < property name = &quot;serviceInterface&quot; value = &quot;com.targettrust.spring.remoting.HoraService&quot; /> </ bean > </ beans >
  • 27.