SlideShare a Scribd company logo
1 of 49
Download to read offline
Josh Long (⻰龙之春)
                            @starbuxman
                             joshlong.com
            josh.long@springsource.com
                   slideshare.net/joshlong




                                 Multi Client Development with Spring



© 2013 SpringSource, by VMware
Josh Long (⻰龙之春)
                @starbuxman
                 joshlong.com
josh.long@springsource.com
       slideshare.net/joshlong
Josh Long (⻰龙之春)
                @starbuxman
                 joshlong.com
josh.long@springsource.com
       slideshare.net/joshlong



Contributor To:

•Spring Integration
•Spring Batch
•Spring Hadoop
•Activiti Workflow Engine
Why Are We Here?




            “   Software entities (classes,
                modules, functions, etc.) should
                be open for extension, but closed
                for modification.
                                                    ”
                                   -Bob Martin




4
Why Are We Here?




                   do NOT reinvent
                   the Wheel!



5
Spring’s aim:
bring simplicity to java development

                                                                                data
                web tier
                                                batch       integration &      access
                  &          service tier                                                          mobile
                                             processing      messaging      / NoSQL / Big
                 RIA
                                                                                Data



                                            The Spring framework
          the cloud                           lightweight                       traditional
                     CloudFoundry
                   Google App Engine                      tc Server                      WebSphere
                   Amazon BeanStalk                        Tomcat                         JBoss AS
                      CloudBees                              Jetty                       WebLogic
                                                                                    (on legacy versions, too!)
                       OpenShift



                                                                                                                 6
Spring Web Support




7
Thin, Thick, Web, Mobile and Rich Clients: Web Core

§ Spring Dispatcher Servlet
 • Objects don’t have to be web-specific.
 • Spring web supports lower-level web machinery: ‘
  •   HttpRequestHandler (supports remoting: Caucho, Resin, JAX RPC)
  •   DelegatingFilterProxy.
  •   HandlerInterceptor wraps requests to HttpRequestHandlers
  •   ServletWrappingController lets you force requests to a servlet through the Spring Handler chain
  •   OncePerRequestFilter ensures that an action only occurs once, no matter how many filters are applied. Provides a nice way to avoid duplicate
      filters
 • Spring provides access to the Spring application context using WebApplicationContextUtils, which has a static method to look up
  the context, even in environments where Spring isn’t managing the web components
Thin, Thick, Web, Mobile and Rich Clients: Web Core

§ Spring provides the easiest way to integrate with your web framework of choice
 • Spring Faces for JSF 1 and 2
 • Struts support for Struts 1
 • Tapestry, Struts 2, Stripes, Wicket, Vaadin, Play framework, etc.
 • GWT, Flex
Thin, Thick, Web, Mobile and Rich Clients: Spring MVC




                                                        10
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {


 }




                                          11
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”)
     public String processTheRequest() {
         // ...
         return “home”;
     }

 }




GET http://127.0.0.1:8080/url/of/my/resource


                                                    12
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public String processTheRequest() {
         // ...
         return “home”;
     }

 }




GET http://127.0.0.1:8080/url/of/my/resource


                                                    13
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public String processTheRequest( HttpServletRequest request) {
         String contextPath = request.getContextPath();
         // ...
         return “home”;
     }

 }




GET http://127.0.0.1:8080/url/of/my/resource


                                                                      14
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public String processTheRequest( @RequestParam(“search”) String searchQuery ) {
         // ...
         return “home”;
     }

 }




GET http://127.0.0.1:8080/url/of/my/resource?search=Spring


                                                                                       15
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/{id}”,
                     method = RequestMethod.GET)
     public String processTheRequest( @PathVariable(“id”) Long id) {
         // ...
         return “home”;
     }

 }




GET http://127.0.0.1:8080/url/of/my/2322


                                                                       16
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/{id}” )
     public String processTheRequest( @PathVariable(“id”) Long customerId,
                                      Model model ) {
         model.addAttribute(“customer”, service.getCustomerById( customerId ) );
         return “home”;
     }

     @Autowired CustomerService service;

 }




GET http://127.0.0.1:8080/url/of/my/232


                                                                                   17
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public String processTheRequest( HttpServletRequest request, Model model) {
         return “home”;
     }

 }




                                                                                   18
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public View processTheRequest( HttpServletRequest request, Model model) {
         return new XsltView(...);
     }

 }




                                                                                 19
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public ResponseEntity<byte[]> processTheRequest( HttpServletRequest request, Model model) {
         return new ResponseEntity<byte[]>( bytes, ...) ;
     }

 }




                                                                                                   20
DEMO
§ Demos
 • Simple Spring MVC based Application




                                         Not confidential. Tell everyone.
the new hotness...




                     22
dumb terminals ruled the earth....




                                     23
then something magical happened: the web




                                           24
but the web didn’t know how to do UI state... so we hacked...




                                                                25
....then the web leveled up




                              26
How Powerful is JavaScript? ...It Boots Linux!!




                                                  27
REST




       28
Thin, Thick, Web, Mobile and Rich Clients: REST

§ Origin
 • The term Representational State Transfer was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation.
§ His paper suggests these four design principles:
 • Use HTTP methods explicitly.
   • POST, GET, PUT, DELETE
   • CRUD operations can be mapped to these existing methods
 • Be stateless.
   • State dependencies limit or restrict scalability
 • Expose directory structure-like URIs.
   • URI’s should be easily understood
 • Transfer XML, JavaScript Object Notation (JSON), or both.
   • Use XML or JSON to represent data objects or attributes




                                                               CONFIDENTIAL
                                                                                                                               29
REST on the Server

§ Spring MVC is basis for REST support
 • Spring’s server side REST support is based on the standard controller model
§ JavaScript and HTML5 can consume JSON-data payloads
REST on the Client

§ RestTemplate
 • provides dead simple, idiomatic RESTful services consumption
 • can use Spring OXM, too.
 • Spring Integration and Spring Social both build on the RestTemplate where possible.
§ Spring supports numerous converters out of the box
 • JAXB
 • JSON (Jackson)
Building clients for your RESTful services: RestTemplate

§ Google search example
 RestTemplate restTemplate = new RestTemplate();
 String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}";
 String result = restTemplate.getForObject(url, String.class, "SpringSource");



§ Multiple parameters
 RestTemplate restTemplate = new RestTemplate();
 String url = "http://example.com/hotels/{hotel}/bookings/{booking}";
 String result = restTemplate.getForObject(url, String.class, "42", “21”);




                                                             CONFIDENTIAL
                                                                                        32
Thin, Thick, Web, Mobile and Rich Clients: RestTemplate

§ RestTemplate class is the heart the client-side story
 • Entry points for the six main HTTP methods
   •   DELETE - delete(...)
   •   GET - getForObject(...)
   •   HEAD - headForHeaders(...)
   •   OPTIONS - optionsForAllow(...)
   •   POST - postForLocation(...)
   •   PUT - put(...)
   •   any HTTP operation - exchange(...) and execute(...)




                                                             CONFIDENTIAL
                                                                            33
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/resource”,
                     method = RequestMethod.GET)
     public @ResponseBody Customer processTheRequest(   ... ) {
        Customer c = service.getCustomerById( id) ;
        return c;
     }

     @Autowired CustomerService service;

 }




                                                                  34
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/someurl”,
                     method = RequestMethod.POST)
     public String processTheRequest( @RequestBody Customer postedCustomerObject) {
         // ...
         return “home”;
     }

 }




POST http://127.0.0.1:8080/url/of/my/someurl


                                                                                      35
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @RequestMapping(value=”/url/of/my/{id}”,
                     method = RequestMethod.POST)
     public String processTheRequest( @PathVariable(“id”) Long customerId,
                                      @RequestBody Customer postedCustomerObject) {
         // ...
         return “home”;
     }

 }




POST http://127.0.0.1:8080/url/of/my/someurl


                                                                                      36
The Anatomy of a Spring MVC @Controller
      Spring MVC configuration - config

 @Controller
 public class CustomerController {

     @ResponseStatus( HttpStatus.CREATED )
     @RequestMapping(value=”/url/of/my/{id}”, method = RequestMethod.POST)
     public ResponseEntity<?> processTheRequest() {
         // ...
     }

 }




POST http://127.0.0.1:8080/url/of/my/someurl


                                                                             37
What About the Browsers, Man?

• Problem: modern browsers only speak GET and POST
• Solution: use Spring’s HiddenHttpMethodFilter only then send _method request parameter in the request



<filter>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <url-pattern>/</url-pattern>
    <servlet-name>appServlet</servlet-name>
  </filter-mapping>
DEMO
§ Demos:
• Spring REST service
• Spring REST client




                        Not confidential. Tell everyone.
Spring Mobile




                40
Thin, Thick, Web, Mobile and Rich Clients: Mobile

§ Best strategy? Develop Native
 • Fallback to client-optimized web applications
§ Spring MVC 3.1 mobile client-specific content negotiation and rendering
 • for other devices
   • (there are other devices besides Android??)




                                                                             41
DEMO
§ Demos:
• Mobile clients using client specific rendering
• preferences, device resolver, site switching, device delegating view resolver




                                                 Not confidential. Tell everyone.
Spring Android




                 43
Thin, Thick, Web, Mobile and Rich Clients: Mobile

                    § Spring REST is ideal for mobile devices
                    § Spring MVC 3.1 mobile client-specific content negotiation and rendering
                     • for other devices
                    § Spring Android
                     • RestTemplate




                                                                                             44
OK, so.....




              45
Thin, Thick, Web, Mobile and Rich Clients: Mobile

           CustomerServiceClient - client



!    private <T> T extractResponse( ResponseEntity<T> response) {
!    !     if (response != null && response().value() == 200) {
!    !     !    return response.getBody();
!    !     }
!    !     throw new RuntimeException("couldn't extract response.");
!    }

!    @Override
!    public Customer updateCustomer(long id, String fn, String ln) {
!    !     String urlForPath = urlForPath("customer/{customerId}");!   !
!    !     return extractResponse(this.restTemplate.postForEntity(
                  urlForPath, new Customer(id, fn, ln), Customer.class, id));
!    }




                                                                                46
Thin, Thick, Web, Mobile and Rich Clients: Mobile

§ Demos:
• consuming the Spring REST service from Android
And The REST of it

• Spring Data REST - exposes (JPA, MongoDB, GemFire, Neo4J, Redis) repositories built on Spring Data repositories
• Spring HATEOAS - take your REST-fu to the next level with support for HTTP as the engine of application state
• Spring Social - provides connectivity and authentication support for OAuth
• Spring Security OAuth - provides a way to expose RESTful endpoints through OAuth on the server-side
Josh Long (⻰龙之春)
                @starbuxman
                 joshlong.com
josh.long@springsource.com
       slideshare.net/joshlong




                                 Questions?

More Related Content

More from Joshua Long

Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring BootJoshua Long
 
Have You Seen Spring Lately?
Have You Seen Spring Lately?Have You Seen Spring Lately?
Have You Seen Spring Lately?Joshua Long
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update finalJoshua Long
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryJoshua Long
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud FoundryJoshua Long
 
Spring in-the-cloud
Spring in-the-cloudSpring in-the-cloud
Spring in-the-cloudJoshua Long
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeThe Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeJoshua Long
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom Joshua Long
 
Multi client Development with Spring
Multi client Development with SpringMulti client Development with Spring
Multi client Development with SpringJoshua Long
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the ScenesJoshua Long
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampJoshua Long
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundryJoshua Long
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenJoshua Long
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom UsageJoshua Long
 
Using Spring's IOC Model
Using Spring's IOC ModelUsing Spring's IOC Model
Using Spring's IOC ModelJoshua Long
 
Enterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud FoundryEnterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud FoundryJoshua Long
 

More from Joshua Long (20)

Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
 
Boot It Up
Boot It UpBoot It Up
Boot It Up
 
Have You Seen Spring Lately?
Have You Seen Spring Lately?Have You Seen Spring Lately?
Have You Seen Spring Lately?
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update final
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud Foundry
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundry
 
Spring in-the-cloud
Spring in-the-cloudSpring in-the-cloud
Spring in-the-cloud
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeThe Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom
 
Multi client Development with Spring
Multi client Development with SpringMulti client Development with Spring
Multi client Development with Spring
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the Scenes
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud Foundry
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in Heaven
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom Usage
 
Using Spring's IOC Model
Using Spring's IOC ModelUsing Spring's IOC Model
Using Spring's IOC Model
 
Enterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud FoundryEnterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud Foundry
 

Recently uploaded

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Multi Client Development with Spring

  • 1. Josh Long (⻰龙之春) @starbuxman joshlong.com josh.long@springsource.com slideshare.net/joshlong Multi Client Development with Spring © 2013 SpringSource, by VMware
  • 2. Josh Long (⻰龙之春) @starbuxman joshlong.com josh.long@springsource.com slideshare.net/joshlong
  • 3. Josh Long (⻰龙之春) @starbuxman joshlong.com josh.long@springsource.com slideshare.net/joshlong Contributor To: •Spring Integration •Spring Batch •Spring Hadoop •Activiti Workflow Engine
  • 4. Why Are We Here? “ Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. ” -Bob Martin 4
  • 5. Why Are We Here? do NOT reinvent the Wheel! 5
  • 6. Spring’s aim: bring simplicity to java development data web tier batch integration & access & service tier mobile processing messaging / NoSQL / Big RIA Data The Spring framework the cloud lightweight traditional CloudFoundry Google App Engine tc Server WebSphere Amazon BeanStalk Tomcat JBoss AS CloudBees Jetty WebLogic (on legacy versions, too!) OpenShift 6
  • 8. Thin, Thick, Web, Mobile and Rich Clients: Web Core § Spring Dispatcher Servlet • Objects don’t have to be web-specific. • Spring web supports lower-level web machinery: ‘ • HttpRequestHandler (supports remoting: Caucho, Resin, JAX RPC) • DelegatingFilterProxy. • HandlerInterceptor wraps requests to HttpRequestHandlers • ServletWrappingController lets you force requests to a servlet through the Spring Handler chain • OncePerRequestFilter ensures that an action only occurs once, no matter how many filters are applied. Provides a nice way to avoid duplicate filters • Spring provides access to the Spring application context using WebApplicationContextUtils, which has a static method to look up the context, even in environments where Spring isn’t managing the web components
  • 9. Thin, Thick, Web, Mobile and Rich Clients: Web Core § Spring provides the easiest way to integrate with your web framework of choice • Spring Faces for JSF 1 and 2 • Struts support for Struts 1 • Tapestry, Struts 2, Stripes, Wicket, Vaadin, Play framework, etc. • GWT, Flex
  • 10. Thin, Thick, Web, Mobile and Rich Clients: Spring MVC 10
  • 11. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { } 11
  • 12. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”) public String processTheRequest() { // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/resource 12
  • 13. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public String processTheRequest() { // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/resource 13
  • 14. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public String processTheRequest( HttpServletRequest request) { String contextPath = request.getContextPath(); // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/resource 14
  • 15. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public String processTheRequest( @RequestParam(“search”) String searchQuery ) { // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/resource?search=Spring 15
  • 16. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/{id}”, method = RequestMethod.GET) public String processTheRequest( @PathVariable(“id”) Long id) { // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/2322 16
  • 17. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/{id}” ) public String processTheRequest( @PathVariable(“id”) Long customerId, Model model ) { model.addAttribute(“customer”, service.getCustomerById( customerId ) ); return “home”; } @Autowired CustomerService service; } GET http://127.0.0.1:8080/url/of/my/232 17
  • 18. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public String processTheRequest( HttpServletRequest request, Model model) { return “home”; } } 18
  • 19. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public View processTheRequest( HttpServletRequest request, Model model) { return new XsltView(...); } } 19
  • 20. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public ResponseEntity<byte[]> processTheRequest( HttpServletRequest request, Model model) { return new ResponseEntity<byte[]>( bytes, ...) ; } } 20
  • 21. DEMO § Demos • Simple Spring MVC based Application Not confidential. Tell everyone.
  • 23. dumb terminals ruled the earth.... 23
  • 24. then something magical happened: the web 24
  • 25. but the web didn’t know how to do UI state... so we hacked... 25
  • 26. ....then the web leveled up 26
  • 27. How Powerful is JavaScript? ...It Boots Linux!! 27
  • 28. REST 28
  • 29. Thin, Thick, Web, Mobile and Rich Clients: REST § Origin • The term Representational State Transfer was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. § His paper suggests these four design principles: • Use HTTP methods explicitly. • POST, GET, PUT, DELETE • CRUD operations can be mapped to these existing methods • Be stateless. • State dependencies limit or restrict scalability • Expose directory structure-like URIs. • URI’s should be easily understood • Transfer XML, JavaScript Object Notation (JSON), or both. • Use XML or JSON to represent data objects or attributes CONFIDENTIAL 29
  • 30. REST on the Server § Spring MVC is basis for REST support • Spring’s server side REST support is based on the standard controller model § JavaScript and HTML5 can consume JSON-data payloads
  • 31. REST on the Client § RestTemplate • provides dead simple, idiomatic RESTful services consumption • can use Spring OXM, too. • Spring Integration and Spring Social both build on the RestTemplate where possible. § Spring supports numerous converters out of the box • JAXB • JSON (Jackson)
  • 32. Building clients for your RESTful services: RestTemplate § Google search example RestTemplate restTemplate = new RestTemplate(); String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}"; String result = restTemplate.getForObject(url, String.class, "SpringSource"); § Multiple parameters RestTemplate restTemplate = new RestTemplate(); String url = "http://example.com/hotels/{hotel}/bookings/{booking}"; String result = restTemplate.getForObject(url, String.class, "42", “21”); CONFIDENTIAL 32
  • 33. Thin, Thick, Web, Mobile and Rich Clients: RestTemplate § RestTemplate class is the heart the client-side story • Entry points for the six main HTTP methods • DELETE - delete(...) • GET - getForObject(...) • HEAD - headForHeaders(...) • OPTIONS - optionsForAllow(...) • POST - postForLocation(...) • PUT - put(...) • any HTTP operation - exchange(...) and execute(...) CONFIDENTIAL 33
  • 34. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/resource”, method = RequestMethod.GET) public @ResponseBody Customer processTheRequest( ... ) { Customer c = service.getCustomerById( id) ; return c; } @Autowired CustomerService service; } 34
  • 35. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/someurl”, method = RequestMethod.POST) public String processTheRequest( @RequestBody Customer postedCustomerObject) { // ... return “home”; } } POST http://127.0.0.1:8080/url/of/my/someurl 35
  • 36. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @RequestMapping(value=”/url/of/my/{id}”, method = RequestMethod.POST) public String processTheRequest( @PathVariable(“id”) Long customerId, @RequestBody Customer postedCustomerObject) { // ... return “home”; } } POST http://127.0.0.1:8080/url/of/my/someurl 36
  • 37. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { @ResponseStatus( HttpStatus.CREATED ) @RequestMapping(value=”/url/of/my/{id}”, method = RequestMethod.POST) public ResponseEntity<?> processTheRequest() { // ... } } POST http://127.0.0.1:8080/url/of/my/someurl 37
  • 38. What About the Browsers, Man? • Problem: modern browsers only speak GET and POST • Solution: use Spring’s HiddenHttpMethodFilter only then send _method request parameter in the request <filter> <filter-name>hiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>hiddenHttpMethodFilter</filter-name> <url-pattern>/</url-pattern> <servlet-name>appServlet</servlet-name> </filter-mapping>
  • 39. DEMO § Demos: • Spring REST service • Spring REST client Not confidential. Tell everyone.
  • 41. Thin, Thick, Web, Mobile and Rich Clients: Mobile § Best strategy? Develop Native • Fallback to client-optimized web applications § Spring MVC 3.1 mobile client-specific content negotiation and rendering • for other devices • (there are other devices besides Android??) 41
  • 42. DEMO § Demos: • Mobile clients using client specific rendering • preferences, device resolver, site switching, device delegating view resolver Not confidential. Tell everyone.
  • 44. Thin, Thick, Web, Mobile and Rich Clients: Mobile § Spring REST is ideal for mobile devices § Spring MVC 3.1 mobile client-specific content negotiation and rendering • for other devices § Spring Android • RestTemplate 44
  • 46. Thin, Thick, Web, Mobile and Rich Clients: Mobile CustomerServiceClient - client ! private <T> T extractResponse( ResponseEntity<T> response) { ! ! if (response != null && response().value() == 200) { ! ! ! return response.getBody(); ! ! } ! ! throw new RuntimeException("couldn't extract response."); ! } ! @Override ! public Customer updateCustomer(long id, String fn, String ln) { ! ! String urlForPath = urlForPath("customer/{customerId}");! ! ! ! return extractResponse(this.restTemplate.postForEntity( urlForPath, new Customer(id, fn, ln), Customer.class, id)); ! } 46
  • 47. Thin, Thick, Web, Mobile and Rich Clients: Mobile § Demos: • consuming the Spring REST service from Android
  • 48. And The REST of it • Spring Data REST - exposes (JPA, MongoDB, GemFire, Neo4J, Redis) repositories built on Spring Data repositories • Spring HATEOAS - take your REST-fu to the next level with support for HTTP as the engine of application state • Spring Social - provides connectivity and authentication support for OAuth • Spring Security OAuth - provides a way to expose RESTful endpoints through OAuth on the server-side
  • 49. Josh Long (⻰龙之春) @starbuxman joshlong.com josh.long@springsource.com slideshare.net/joshlong Questions?