SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
Spring framework
                     Motto: Musíte rozbít vejce když chcete udělat omeletu




                Spring framework training materials by Roman Pichlík is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Sunday 13 May 2012                                                                                                                                       1
Java EE
                     Kurz jak používat Java EE a nezbláznit se z toho




Sunday 13 May 2012                                                      2
Co Spring nabízí
                     • EJB
                     • JMS
                     • JNDI
                     • JCA
                     • Remoting
                     • Napojení na služby

Sunday 13 May 2012                              3
EJB

                     • Zjednoduššené vytváření EJB
                      • SLSB, SLFB, MDB
                        • AbstractStatelessSessionBean
                        • AbstractStatefulSessionBean
                        • AbstractJmsMessageDrivenBean


Sunday 13 May 2012                                       4
Jak na vlastní beanu




Sunday 13 May 2012                          5
Vlastní business rozhraní


  public interface ReservationService {

  	
  	    public boolean reserveBook(Long bookId, Date from, Date to, User user);	
  	
  }




Sunday 13 May 2012                                                                6
Implementace

  @Service(value="reservationService")
  public class ReservationServiceImpl implements ReservationService {
  	
  	 @Autowired
  	 private BookService bookService;

  	    public boolean reserveBook(Long bookId, Date from, Date to, User user) {
  	    	 Book book = bookService.getBook(bookId);
  	    	 if(book == null) {
  	    	 	 throw new RuntimeException("Sorry, the book doesn't exist");
  	    	 }
  	    	 return true;
  	    }
  }




Sunday 13 May 2012                                                                7

Spring bean, mozno testovat
EJB facade




Sunday 13 May 2012                8
Vlastní fasáda
   Předek, zaručující Spring                            EJB má stejné rozhraní
           podport                                        jako Spring beana
  public class ReservationServiceEJBFacade extends
                               AbstractStatelessSessionBean implements ReservationService {
  	
  	 private static final long serialVersionUID = 1L;

  	    private ReservationService reservationService;                       Získání spring
  	    @Override                                                                beany
  	    protected void onEjbCreate() throws CreateException {
  	    	 reservationService = getBeanFactory().getBean("reservationService");	
  	    }

  	    public boolean reserveBook(Long bookId, Date from, Date to, User user) {	 	
  	    	 return reservationService.reserveBook(bookId, from, to, user);
  	    }	
  }




Sunday 13 May 2012                                                                            9

-stejny business interface nam umuznuje delegovat volani
Home a Local Interface
  import javax.ejb.CreateException;
  import javax.ejb.EJBLocalHome;

  public interface ReservationServiceHome extends EJBLocalHome {

  	    public ReservationServiceLocal create() throws CreateException;
  }




  import javax.ejb.EJBLocalObject;

  import cz.sweb.pichlik.ReservationService;

  public interface ReservationServiceLocal extends EJBLocalObject, ReservationService   {
  }




Sunday 13 May 2012                                                                          10
Jak se Spring startuje
  <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/
  XMLSchema-instance"
  	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-
  jar_2_1.xsd"
  	 version="2.1" id="ejb-jar_ID">
  	 <description>Book service EJB facade</description>
  	 <display-name>ejbs</display-name>                Určuje kontext, který se bude
  	 <enterprise-beans>                                         bootovat
  	 	 <session>
  	 	 	 <description>Book service EJB facade</description>
  	 	 	 <ejb-name>ReservationServiceEJBFacade</ejb-name>
  	 	 	 <local-home>cz.sweb.pichlik.ejb.ReservationServiceHome</local-home>
  	 	 	 <local>cz.sweb.pichlik.ejb.ReservationServiceLocal</local>
  	 	 	 <ejb-class>cz.sweb.pichlik.ejb.ReservationServiceEJBFacade</ejb-class>
  	 	 	 <session-type>Stateless</session-type>
  	 	 	 <transaction-type>Container</transaction-type>	    	 	
  	 	 	 <env-entry>
  	 	 	 	 <env-entry-name>ejb/BeanFactoryPath</env-entry-name>
  	 	 	 	 <env-entry-type>java.lang.String</env-entry-type>
  	 	 	 	 <env-entry-value>classpath*:META-INF/businessContext.xml</env-entry-value>
  	 	 	 </env-entry>
  	 	 </session>
Sunday 13 May 2012                                                                         11

- kazda instance beany si vytvari vlastni kontext.
JNDI




Sunday 13 May 2012          12
Lookup generic, local&remote
  <jee:jndi-lookup id="simple"
               jndi-name="jdbc/MyDataSource"
               cache="true"
               resource-ref="true"
               lookup-on-startup="false"
               expected-type=""
               proxy-interface="com.myapp.Foo"/>

  <jee:local-slsb id="complexLocalEjb"
      jndi-name="ejb/RentalServiceBean"
      business-interface="com.foo.service.RentalService"
      cache-home="true"
      lookup-home-on-startup="true"
      resource-ref="true">

  <jee:remote-slsb id="complexRemoteEjb"
      jndi-name="ejb/MyRemoteBean"
      business-interface="com.foo.service.RentalService"
      cache-home="true"
      lookup-home-on-startup="true"
      resource-ref="true"
      home-interface="com.foo.service.RentalService"
      refresh-home-on-connect-failure="true">
Sunday 13 May 2012                                         13
Remoting




Sunday 13 May 2012              14
Podporované protokoly

                     • Client/Server
                      • RMI
                      • Hessian/Burlap
                      • HttpInvoker
                      • JAX-RPC, JAX-WS


Sunday 13 May 2012                           15
HttpInvoker service
     <servlet>
                                                                        web.xml
       <servlet-name>remoting</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     </servlet>

     <servlet-mapping>
       <servlet-name>remoting</servlet-name>
       <url-pattern>/remoting/*</url-pattern>
     </servlet-mapping>




                                        remoting-servlet.xml

  <bean name="/ReservationService"
  class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
    	 <property name="service" ref="web.reservationService"/>
       	 <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/>
  </bean>



Sunday 13 May 2012                                                                        16
HttpInvoker client


  <bean id="client.reservationService"
  class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
     <property name="serviceUrl" value="http://localhost:8080/servlet/remoting/ReservationService"/>
     <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/>
  </bean>




Sunday 13 May 2012                                                                                     17
JMS




Sunday 13 May 2012         18
Podporované typy


                     • MDB
                        • AbstractJmsMessageDrivenBean
                     • Spring MDB
                     • Client


Sunday 13 May 2012                                       19
Mail




Sunday 13 May 2012          20
import org.springframework.mail.SimpleMailMessage;
 import org.springframework.mail.MailSender;

 @Service
 public class EmailExample {

     @Autowired
     private MailSender mailSender;
     @Autowired
     private SimpleMailMessage templateMessage;

     public void sayHello() {
         SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
         msg.setTo(order.getCustomer().getEmailAddress());
         msg.setText(“HelloWorld”);
         this.mailSender.send(msg);
     }
 }




 <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
   <property name="host" value="mail.mycompany.com"/>
 </bean>

 <!-- this is a template message that we can pre-load with default state -->
 <bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
   <property name="from" value="customerservice@mycompany.com"/>
   <property name="subject" value="Your order"/>
 </bean>




Sunday 13 May 2012                                                                     21
org.springframework.mail.javamail.MimeMessageHelp
er

Mais conteúdo relacionado

Semelhante a Spring J2EE

GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0Arun Gupta
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Max Andersen
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
Jsf2 overview
Jsf2 overviewJsf2 overview
Jsf2 overviewsohan1234
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tipsShakti Shrestha
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)vikram singh
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGESKalpana T
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 

Semelhante a Spring J2EE (20)

GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Jsf2 overview
Jsf2 overviewJsf2 overview
Jsf2 overview
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
14 mvc
14 mvc14 mvc
14 mvc
 
EJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 PreludeEJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 Prelude
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tips
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
10 J D B C
10  J D B C10  J D B C
10 J D B C
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 

Mais de Roman Pichlík

MongoDB for Java Developers
MongoDB for Java DevelopersMongoDB for Java Developers
MongoDB for Java DevelopersRoman Pichlík
 
Nosql from java developer pov
Nosql from java developer povNosql from java developer pov
Nosql from java developer povRoman Pichlík
 
Spring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou TvariSpring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou TvariRoman Pichlík
 
Dependency Injection Frameworky
Dependency Injection FrameworkyDependency Injection Frameworky
Dependency Injection FrameworkyRoman Pichlík
 

Mais de Roman Pichlík (9)

Spring ioc-advanced
Spring ioc-advancedSpring ioc-advanced
Spring ioc-advanced
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Spring dao
Spring daoSpring dao
Spring dao
 
Spring aop
Spring aopSpring aop
Spring aop
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web Services
 
MongoDB for Java Developers
MongoDB for Java DevelopersMongoDB for Java Developers
MongoDB for Java Developers
 
Nosql from java developer pov
Nosql from java developer povNosql from java developer pov
Nosql from java developer pov
 
Spring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou TvariSpring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou Tvari
 
Dependency Injection Frameworky
Dependency Injection FrameworkyDependency Injection Frameworky
Dependency Injection Frameworky
 

Último

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfUK Journal
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 

Último (20)

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 

Spring J2EE

  • 1. Spring framework Motto: Musíte rozbít vejce když chcete udělat omeletu Spring framework training materials by Roman Pichlík is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Sunday 13 May 2012 1
  • 2. Java EE Kurz jak používat Java EE a nezbláznit se z toho Sunday 13 May 2012 2
  • 3. Co Spring nabízí • EJB • JMS • JNDI • JCA • Remoting • Napojení na služby Sunday 13 May 2012 3
  • 4. EJB • Zjednoduššené vytváření EJB • SLSB, SLFB, MDB • AbstractStatelessSessionBean • AbstractStatefulSessionBean • AbstractJmsMessageDrivenBean Sunday 13 May 2012 4
  • 5. Jak na vlastní beanu Sunday 13 May 2012 5
  • 6. Vlastní business rozhraní public interface ReservationService { public boolean reserveBook(Long bookId, Date from, Date to, User user); } Sunday 13 May 2012 6
  • 7. Implementace @Service(value="reservationService") public class ReservationServiceImpl implements ReservationService { @Autowired private BookService bookService; public boolean reserveBook(Long bookId, Date from, Date to, User user) { Book book = bookService.getBook(bookId); if(book == null) { throw new RuntimeException("Sorry, the book doesn't exist"); } return true; } } Sunday 13 May 2012 7 Spring bean, mozno testovat
  • 8. EJB facade Sunday 13 May 2012 8
  • 9. Vlastní fasáda Předek, zaručující Spring EJB má stejné rozhraní podport jako Spring beana public class ReservationServiceEJBFacade extends AbstractStatelessSessionBean implements ReservationService { private static final long serialVersionUID = 1L; private ReservationService reservationService; Získání spring @Override beany protected void onEjbCreate() throws CreateException { reservationService = getBeanFactory().getBean("reservationService"); } public boolean reserveBook(Long bookId, Date from, Date to, User user) { return reservationService.reserveBook(bookId, from, to, user); } } Sunday 13 May 2012 9 -stejny business interface nam umuznuje delegovat volani
  • 10. Home a Local Interface import javax.ejb.CreateException; import javax.ejb.EJBLocalHome; public interface ReservationServiceHome extends EJBLocalHome { public ReservationServiceLocal create() throws CreateException; } import javax.ejb.EJBLocalObject; import cz.sweb.pichlik.ReservationService; public interface ReservationServiceLocal extends EJBLocalObject, ReservationService { } Sunday 13 May 2012 10
  • 11. Jak se Spring startuje <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/ XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb- jar_2_1.xsd" version="2.1" id="ejb-jar_ID"> <description>Book service EJB facade</description> <display-name>ejbs</display-name> Určuje kontext, který se bude <enterprise-beans> bootovat <session> <description>Book service EJB facade</description> <ejb-name>ReservationServiceEJBFacade</ejb-name> <local-home>cz.sweb.pichlik.ejb.ReservationServiceHome</local-home> <local>cz.sweb.pichlik.ejb.ReservationServiceLocal</local> <ejb-class>cz.sweb.pichlik.ejb.ReservationServiceEJBFacade</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> <env-entry> <env-entry-name>ejb/BeanFactoryPath</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>classpath*:META-INF/businessContext.xml</env-entry-value> </env-entry> </session> Sunday 13 May 2012 11 - kazda instance beany si vytvari vlastni kontext.
  • 13. Lookup generic, local&remote <jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource" cache="true" resource-ref="true" lookup-on-startup="false" expected-type="" proxy-interface="com.myapp.Foo"/> <jee:local-slsb id="complexLocalEjb" jndi-name="ejb/RentalServiceBean" business-interface="com.foo.service.RentalService" cache-home="true" lookup-home-on-startup="true" resource-ref="true"> <jee:remote-slsb id="complexRemoteEjb" jndi-name="ejb/MyRemoteBean" business-interface="com.foo.service.RentalService" cache-home="true" lookup-home-on-startup="true" resource-ref="true" home-interface="com.foo.service.RentalService" refresh-home-on-connect-failure="true"> Sunday 13 May 2012 13
  • 15. Podporované protokoly • Client/Server • RMI • Hessian/Burlap • HttpInvoker • JAX-RPC, JAX-WS Sunday 13 May 2012 15
  • 16. HttpInvoker service <servlet> web.xml <servlet-name>remoting</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>remoting</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping> remoting-servlet.xml <bean name="/ReservationService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service" ref="web.reservationService"/> <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/> </bean> Sunday 13 May 2012 16
  • 17. HttpInvoker client <bean id="client.reservationService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://localhost:8080/servlet/remoting/ReservationService"/> <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/> </bean> Sunday 13 May 2012 17
  • 18. JMS Sunday 13 May 2012 18
  • 19. Podporované typy • MDB • AbstractJmsMessageDrivenBean • Spring MDB • Client Sunday 13 May 2012 19
  • 21. import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.MailSender; @Service public class EmailExample { @Autowired private MailSender mailSender; @Autowired private SimpleMailMessage templateMessage; public void sayHello() { SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(order.getCustomer().getEmailAddress()); msg.setText(“HelloWorld”); this.mailSender.send(msg); } } <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="mail.mycompany.com"/> </bean> <!-- this is a template message that we can pre-load with default state --> <bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="customerservice@mycompany.com"/> <property name="subject" value="Your order"/> </bean> Sunday 13 May 2012 21 org.springframework.mail.javamail.MimeMessageHelp er