SlideShare a Scribd company logo
1 of 50
Multi Client Development with Spring MVC
@ Java2Days
Josh Long
Spring Developer Advocate
SpringSource, a Division of VMware
http://www.joshlong.com || @starbuxman || josh.long@springsource.com




                                                              © 2009 VMware Inc. All rights reserved
About Josh Long

Spring Developer Advocate
twitter: @starbuxman
josh.long@springsource.com




                             2
About Josh Long

Spring Developer Advocate
twitter: @starbuxman
josh.long@springsource.com

Contributor To:

•Spring Integration
•Spring Batch
•Spring Hadoop
•Activiti Workflow Engine
•Akka Actor engine




                             3
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 /
   RIA
                                                             Big Data


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




                                                                                               6
Not All Sides Are Equal




                          7
Spring Web Support




                     8
New in 3.1: XML-free web applications

 In a servlet 3 container, you can also use Java configuration,
 negating the need for web.xml:


 public class SampleWebApplicationInitializer implements WebApplicationInitializer {

     public void onStartup(ServletContext sc) throws ServletException {

         AnnotationConfigWebApplicationContext ac =
                   new AnnotationConfigWebApplicationContext();
         ac.setServletContext(sc);
         ac.scan( “a.package.full.of.services”, “a.package.full.of.controllers” );

         sc.addServlet("spring", new DispatcherServlet(webContext));

     }
 }




                                                                                       9
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




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

 @Controller
 public class CustomerController {


 }




                                          13
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

                                                   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() {
         // ...
         return “home”;
     }

 }




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

                                                    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( HttpServletRequest request) {
         String contextPath = request.getContextPath();
         // ...
         return “home”;
     }

 }




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

                                                                      16
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

                                                                                       17
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

                                                                       18
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

                                                                                   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 String processTheRequest( HttpServletRequest request, Model model) {
         return “home”;
     }

 }




                                                                                   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 View processTheRequest( HttpServletRequest request, Model model) {
         return new XsltView(...);
     }

 }




                                                                                 21
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 InputStream processTheRequest( HttpServletRequest request, Model model) {
         return new FileInputStream( ...) ;
     }

 }




                                                                                        22
DEMO
 Demos
 • Simple Spring MVC based Application




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




                     24
dumb terminals ruled the earth....




                                     25
then something magical happened: the web




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




                                                                27
....then the web stopped sucking




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




                                                  29
REST




       30
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
                                                                                        31
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
                                                                                 34
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
                                                            35
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;

 }




                                                                  36
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

                                                                                      37
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

                                                                                      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>
DEMO
 Demos:
• Spring REST service
• Spring REST client




                        Not confidential. Tell everyone.
Spring Mobile




                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??)




                                                                  42
DEMO
 Demos:
• Mobile clients using client specific rendering




                                  Not confidential. Tell everyone.
Spring Android




                 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




                                                                45
OK, so.....




              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));
!    }




                                                                                 47
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 (See my friend Sergi’s talk!)
• Spring HATEOAS - take your REST-fu to the next level with support for HTTP as the
 engine of application state
• Spring Security OAuth - secure RESTful web services using OAuth, the same security
 technology that Twitter, Facebook, etc.
• Spring Social - RestTemplate is powerful, but some APIs are overwhelming, and OAuth
 client communication can be daunting. Spring Social makes it easier.
@starbuxman | josh.long@springsource.com
        http://slideshare.net/joshlong




           Questions?

More Related Content

What's hot

Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot ActuatorRowell Belen
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservicesNilanjan Roy
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsGuy Nir
 
a Running Tour of Cloud Foundry
a Running Tour of Cloud Foundrya Running Tour of Cloud Foundry
a Running Tour of Cloud FoundryJoshua Long
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring SessionDavid Gómez García
 
Don't Wait! Develop Responsive Applications with Java EE7 Instead
Don't Wait! Develop Responsive Applications with Java EE7 InsteadDon't Wait! Develop Responsive Applications with Java EE7 Instead
Don't Wait! Develop Responsive Applications with Java EE7 InsteadWASdev Community
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVCJohn Lewis
 
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
 
Spring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerSpring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerZeroTurnaround
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsLukasz Lysik
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 

What's hot (20)

Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
 
a Running Tour of Cloud Foundry
a Running Tour of Cloud Foundrya Running Tour of Cloud Foundry
a Running Tour of Cloud Foundry
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring4 whats up doc?
Spring4 whats up doc?Spring4 whats up doc?
Spring4 whats up doc?
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
 
Don't Wait! Develop Responsive Applications with Java EE7 Instead
Don't Wait! Develop Responsive Applications with Java EE7 InsteadDon't Wait! Develop Responsive Applications with Java EE7 Instead
Don't Wait! Develop Responsive Applications with Java EE7 Instead
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
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
 
Spring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerSpring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen Hoeller
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 

Similar to Multi Client Development with Spring

Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVAPeter Maas
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxAbhijayKulshrestha1
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web FrameworkLuther Baker
 
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
 
Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUGSpring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUGTed Pennings
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New FeaturesJay Lee
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applicationselliando dias
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieOPEN KNOWLEDGE GmbH
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
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
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsJack-Junjie Cai
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentVolodymyr Voytyshyn
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 

Similar to Multi Client Development with Spring (20)

Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVA
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
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
 
Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUGSpring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUG
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
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
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applications
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 

More from Joshua Long

Economies of Scaling Software
Economies of Scaling SoftwareEconomies of Scaling Software
Economies of Scaling SoftwareJoshua Long
 
Bootiful Code with Spring Boot
Bootiful Code with Spring BootBootiful Code with Spring Boot
Bootiful Code with Spring BootJoshua 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
 
the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013Joshua Long
 
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonJoshua Long
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Extending spring
Extending springExtending spring
Extending 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
 
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 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
 
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
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinJoshua Long
 

More from Joshua Long (20)

Economies of Scaling Software
Economies of Scaling SoftwareEconomies of Scaling Software
Economies of Scaling Software
 
Bootiful Code with Spring Boot
Bootiful Code with Spring BootBootiful Code with Spring Boot
Bootiful Code with Spring Boot
 
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?
 
the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013
 
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Extending spring
Extending springExtending spring
Extending 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
 
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 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
 
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
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and Vaadin
 

Recently uploaded

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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
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
 

Recently uploaded (20)

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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.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
 

Multi Client Development with Spring

  • 1. Multi Client Development with Spring MVC @ Java2Days Josh Long Spring Developer Advocate SpringSource, a Division of VMware http://www.joshlong.com || @starbuxman || josh.long@springsource.com © 2009 VMware Inc. All rights reserved
  • 2. About Josh Long Spring Developer Advocate twitter: @starbuxman josh.long@springsource.com 2
  • 3. About Josh Long Spring Developer Advocate twitter: @starbuxman josh.long@springsource.com Contributor To: •Spring Integration •Spring Batch •Spring Hadoop •Activiti Workflow Engine •Akka Actor engine 3
  • 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 / RIA Big Data The Spring framework the cloud: lightweight traditional CloudFoundry WebSphere tc Server Google App Engine JBoss AS Tomcat Amazon BeanStalk WebLogic Jetty Others (on legacy versions, too!) 6
  • 7. Not All Sides Are Equal 7
  • 9. New in 3.1: XML-free web applications  In a servlet 3 container, you can also use Java configuration, negating the need for web.xml: public class SampleWebApplicationInitializer implements WebApplicationInitializer { public void onStartup(ServletContext sc) throws ServletException { AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext(); ac.setServletContext(sc); ac.scan( “a.package.full.of.services”, “a.package.full.of.controllers” ); sc.addServlet("spring", new DispatcherServlet(webContext)); } } 9
  • 10. 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
  • 11. 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
  • 12. Thin, Thick, Web, Mobile and Rich Clients: Spring MVC 12
  • 13. The Anatomy of a Spring MVC @Controller Spring MVC configuration - config @Controller public class CustomerController { } 13
  • 14. 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 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() { // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/resource 15
  • 16. 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 16
  • 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( @RequestParam(“search”) String searchQuery ) { // ... return “home”; } } GET http://127.0.0.1:8080/url/of/my/resource?search=Spring 17
  • 18. 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 18
  • 19. 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 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 String processTheRequest( HttpServletRequest request, Model model) { return “home”; } } 20
  • 21. 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(...); } } 21
  • 22. 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 InputStream processTheRequest( HttpServletRequest request, Model model) { return new FileInputStream( ...) ; } } 22
  • 23. DEMO  Demos • Simple Spring MVC based Application Not confidential. Tell everyone.
  • 25. dumb terminals ruled the earth.... 25
  • 26. then something magical happened: the web 26
  • 27. but the web didn’t know how to do UI state... so we hacked... 27
  • 28. ....then the web stopped sucking 28
  • 29. How Powerful is JavaScript? ...It Boots Linux!! 29
  • 30. REST 30
  • 31. 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 31
  • 32. 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
  • 33. 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)
  • 34. 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 34
  • 35. 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 35
  • 36. 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; } 36
  • 37. 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 37
  • 38. 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 38
  • 39. 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>
  • 40. DEMO  Demos: • Spring REST service • Spring REST client Not confidential. Tell everyone.
  • 42. 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??) 42
  • 43. DEMO  Demos: • Mobile clients using client specific rendering Not confidential. Tell everyone.
  • 45. 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 45
  • 47. 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)); ! } 47
  • 48. Thin, Thick, Web, Mobile and Rich Clients: Mobile  Demos: • consuming the Spring REST service from Android
  • 49. And The REST of it • Spring Data REST - exposes (JPA, MongoDB, GemFire, Neo4J, Redis) repositories built on Spring Data repositories (See my friend Sergi’s talk!) • Spring HATEOAS - take your REST-fu to the next level with support for HTTP as the engine of application state • Spring Security OAuth - secure RESTful web services using OAuth, the same security technology that Twitter, Facebook, etc. • Spring Social - RestTemplate is powerful, but some APIs are overwhelming, and OAuth client communication can be daunting. Spring Social makes it easier.
  • 50. @starbuxman | josh.long@springsource.com http://slideshare.net/joshlong Questions?

Editor's Notes

  1. \n
  2. \n\n
  3. Hello, thank you or having me. Im pleased to have the opportunity to introduce you today to Spring and the SpringSource Tool Suite \n\nMy anem is Josh Long. I serve as the developer advocate for the Spring framework. I&amp;#x2019;ve used it in earnest and advocated it for many years now. i&amp;#x2019;m an author on 3 books on the technology, as well as a comitter to many of the Spring projects. Additionally, I take community activism very seriously and do my best to participate in the community. Sometimes this means answering question on Twitter, or in the forums, or helping contribute to the InfoQ.com and Artima.com communities\n
  4. Hello, thank you or having me. Im pleased to have the opportunity to introduce you today to Spring and the SpringSource Tool Suite \n\nMy anem is Josh Long. I serve as the developer advocate for the Spring framework. I&amp;#x2019;ve used it in earnest and advocated it for many years now. i&amp;#x2019;m an author on 3 books on the technology, as well as a comitter to many of the Spring projects. Additionally, I take community activism very seriously and do my best to participate in the community. Sometimes this means answering question on Twitter, or in the forums, or helping contribute to the InfoQ.com and Artima.com communities\n
  5. \n
  6. \n
  7. these different framerworks let u tackle any problem youre likely to want to solve today \n- we support javee1.4 + 1.5 + 1.6; \n\nsits above target platform \nruns in cloud \n\n
  8. \n
  9. \n
  10. \n
  11. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  12. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  13. Familiar to somebody who&amp;#x2019;s used Struts:\n Models (like Struts ActionForms)\n Views (like Struts views: tiles, .jsp(x)s, velocity, PDF, Excel, etc.) \n Controllers (like Struts Actions)\n\n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pieces are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  35. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pieces are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  42. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  43. \n
  44. \n
  45. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  46. \n
  47. \n
  48. \n
  49. \n
  50. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  51. \n
  52. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  53. \n
  54. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  55. another example of the fact that often the client side model won&amp;#x2019;t represent the server side model \n\n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  139. \n