SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
A UNIFIED SOAP / JSON API
                      using Symfony2




Tuesday, 12 June 12
ABOUT ME


    • Craig           Marvelley

    • Developer           at Box UK

    • @craigmarvelley

    • Using           Symfony for ~ 1 year



Tuesday, 12 June 12
THE PROBLEM

                      WEBSITE


                                              LEGACY APIS
                                                (SOAP)


         MOBILE DEVICES



Tuesday, 12 June 12
THE SOLUTION

                                SOAP
                      WEBSITE


                                        FACADE API   SOAP   LEGACY APIS
                                       (SOAP/JSON)            (SOAP)

                                JSON
         MOBILE DEVICES



Tuesday, 12 June 12
Request
                           /json                  /soap




              JSONController                       SOAPController




                                   Processing
                                    Service



                      JSON Response                       SOAP Response
Tuesday, 12 June 12
KEY COMPONENTS

    • Individual       request classes to encapsulate data

    •A    custom ParamConverter creates objects from JSON
        requests

    • Objects         created from SOAP requests according to WSDL

    • WebserviceManager      class performs processing and creates an
        individual response object

    • Response         is returned to appropriate controller, and output

Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleRequest;

use BoxUKBundleApiBundleRequest;
use SymfonyComponentValidatorConstraints as Assert;
use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap;

/**
 * @AssertCallback(methods={
 *     { "BoxUKBundleApiBundleRequestValidator", "isValidDomainName"}
 * })
 */
class DomainInfoRequest extends AbstractRequest {

        /**
         * @AssertNotBlank()
         * @SoapComplexType("string")
         */
        private $domainName;

        public function setDomainName( $domainName ) {
            $this->domainName = $domainName;
        }

        public function getDomainName() {
            return $this->domainName;
        }

}

Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleRequest;

use BoxUKBundleApiBundleRequest;
use SymfonyComponentValidatorConstraints as Assert;
use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap;

/**
 * @AssertCallback(methods={
 *     { "BoxUKBundleApiBundleRequestValidator", "isValidDomainName"}
 * })
 */
class DomainInfoRequest extends AbstractRequest {

        /**
         * @AssertNotBlank()
         * @SoapComplexType("string")
         */
        private $domainName;

        public function setDomainName( $domainName ) {
            $this->domainName = $domainName;
        }

        public function getDomainName() {
            return $this->domainName;
        }

}

Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleRequest;

use BoxUKBundleApiBundleRequest;
use SymfonyComponentValidatorConstraints as Assert;
use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap;

/**
 * @AssertCallback(methods={
 *     { "BoxUKBundleApiBundleRequestValidator", "isValidDomainName"}
 * })
 */
class DomainInfoRequest extends AbstractRequest {

        /**
         * @AssertNotBlank()
         * @SoapComplexType("string")
         */
        private $domainName;

        public function setDomainName( $domainName ) {
            $this->domainName = $domainName;
        }

        public function getDomainName() {
            return $this->domainName;
        }

}

Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleController;

use SymfonyBundleFrameworkBundleControllerController;
use BoxUKBundleApiBundleRequestDomainInfoRequest;

/**
  * @Route("/json")
  */
class JsonController extends Controller
{
     /**
       * @Route("/domainInfo")
       * @Method("GET")
       */
     public function domainInfoAction(DomainInfoRequest $request) {
          return $this->respond( $this->getManager()->domainInfo( $request ) );
     }

         /**
           * @return BoxUKBundleApiBundleManagementWebserviceManager
           */
         protected function getManager() {
              return $this->container->get( 'box_uk.api.webservice_manager' );
         }

         ....
}


Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleController;
use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap;
use SymfonyComponentDependencyInjectionContainerAware;

class SoapController extends ContainerAware
{
    /**
      * @SoapMethod("domainInfo")
      * @SoapParam("request", phpType = "BoxUKBundleApiBundleRequest
DomainInfoRequest")
      * @SoapResult(phpType = "BoxUKBundleApiBundleResponseDomainInfoRequest")
      */
    public function domainInfoAction(DomainInfoRequest $request)
    {
         $response = $this->getManager()->domainInfo($request);
         return $this->respond($response);
    }

        ....
}




Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleController;
use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap;
use SymfonyComponentDependencyInjectionContainerAware;

class SoapController extends ContainerAware
{
    /**
      * @SoapMethod("domainInfo")
      * @SoapParam("request", phpType = "BoxUKBundleApiBundleRequest
DomainInfoRequest")
      * @SoapResult(phpType = "BoxUKBundleApiBundleResponseDomainInfoRequest")
      */
    public function domainInfoAction(DomainInfoRequest $request)
    {
         $response = $this->getManager()->domainInfo($request);
         return $this->respond($response);
    }

        ....
}




Tuesday, 12 June 12
<?php

namespace BoxUKBundleApiBundleController;
use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap;
use SymfonyComponentDependencyInjectionContainerAware;

class SoapController extends ContainerAware
{
    /**
     * @param BoxUKBundleApiBundleResponse $response
     * @return mixed
     */
    protected function respond( $response ) {

                if ( !$response->getSuccess() ) {
                    $code = $response->getCode();
                    throw new SoapFault(
                        $faultcode,
                        $response->getErrorMessage(),
                        null,
                        $response->getErrorCode()
                     );
                }

                return $this->getSoapResponse()->setReturnValue( $response );
        }
}




Tuesday, 12 June 12
WEBSERVICE MANAGER
    • Registered           as a service in services.xml

    • Injected           into both JSON and SOAP controllers

    • Validates          request content according to annotations

    • Handles            communication with legacy webservice API

    • Uses            Monolog for fine-grained logging (error & activity)

    • Uses            Doctrine2 to access and persist data

    • Constructs            responses
Tuesday, 12 June 12
HANDY SYMFONY2 FEATURES

    • Used            a custom annotation serializer to transform objects into
        JSON

    • Used   a ParamConverter to transform Symfony Request into
        agnostic Request objects (JSON only)

    • Used    a kernel listener to automatically validate user’s access
        key (JSON only)

    • Used    commands with a crontab to perform periodic updates
        to the database

Tuesday, 12 June 12
COOL BUNDLES
    • BeSimpleSoapBundle    - Provides SOAP integration for
        Symfony2, automatically serialize/deserialise data to objects.
        USES ZENDSOAP!

    • LiipFunctionalTestBundle    - Enhanced functional tests, database
        caching

    • DoctrineFixturesBundle     - For maintaining test data for
        functional tests

    • DoctrineMigrationsBundle      - For versioning the database
        schema
Tuesday, 12 June 12
TESTING

    • Lots            and lots of unit tests

    • Functional            tests for controller actions

    • Used             a developer-in-test

    • He         used SoapUI to create test cases

    • Automated              SOAP request/responses from WSDL


Tuesday, 12 June 12
THANKS FOR LISTENING!
                      https://joind.in/talk/view/6667
                           @craigmarvelley



Tuesday, 12 June 12

Mais conteúdo relacionado

Mais procurados

[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rulesSrijan Technologies
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
A real-world Relay application in production - Stefano Masini - Codemotion Am...
A real-world Relay application in production - Stefano Masini - Codemotion Am...A real-world Relay application in production - Stefano Masini - Codemotion Am...
A real-world Relay application in production - Stefano Masini - Codemotion Am...Codemotion
 
Apache Aries Overview
Apache Aries   OverviewApache Aries   Overview
Apache Aries OverviewIan Robinson
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7Dongho Cho
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityAtul Saurabh
 
Commons Pool and DBCP
Commons Pool and DBCPCommons Pool and DBCP
Commons Pool and DBCPPhil Steitz
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Java MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & OptimizationJava MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & OptimizationKenny Gryp
 
SpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSLSpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSLSunghyouk Bae
 
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)DK Lee
 

Mais procurados (20)

[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
A real-world Relay application in production - Stefano Masini - Codemotion Am...
A real-world Relay application in production - Stefano Masini - Codemotion Am...A real-world Relay application in production - Stefano Masini - Codemotion Am...
A real-world Relay application in production - Stefano Masini - Codemotion Am...
 
Apache Aries Overview
Apache Aries   OverviewApache Aries   Overview
Apache Aries Overview
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
Getting Started-with-Laravel
Getting Started-with-LaravelGetting Started-with-Laravel
Getting Started-with-Laravel
 
COScheduler
COSchedulerCOScheduler
COScheduler
 
Connection Pooling
Connection PoolingConnection Pooling
Connection Pooling
 
22jdbc
22jdbc22jdbc
22jdbc
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Commons Pool and DBCP
Commons Pool and DBCPCommons Pool and DBCP
Commons Pool and DBCP
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Java MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & OptimizationJava MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & Optimization
 
SpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSLSpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSL
 
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter PilgrimJavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
 
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 

Semelhante a A Unified SOAP/JSON API with Symfony2

Ember and containers
Ember and containersEmber and containers
Ember and containersMatthew Beale
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React NativeSoftware Guru
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)Montreal JUG
 
spring3.2 java config Servler3
spring3.2 java config Servler3spring3.2 java config Servler3
spring3.2 java config Servler3YongHyuk Lee
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppSyed Shahul
 
Cloud, Cache, and Configs
Cloud, Cache, and ConfigsCloud, Cache, and Configs
Cloud, Cache, and ConfigsScott Taylor
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Creating native apps with WordPress
Creating native apps with WordPressCreating native apps with WordPress
Creating native apps with WordPressMarko Heijnen
 
Spring into rails
Spring into railsSpring into rails
Spring into railsHiro Asari
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Leejaxconf
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteLeonardo Proietti
 
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code ExampleMaven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code ExampleNikhil Bhalwankar
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Android Jetpack: Room persistence library
Android Jetpack: Room persistence libraryAndroid Jetpack: Room persistence library
Android Jetpack: Room persistence libraryThao Huynh Quang
 

Semelhante a A Unified SOAP/JSON API with Symfony2 (20)

Ember and containers
Ember and containersEmber and containers
Ember and containers
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React Native
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
spring3.2 java config Servler3
spring3.2 java config Servler3spring3.2 java config Servler3
spring3.2 java config Servler3
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
 
Callimachus
CallimachusCallimachus
Callimachus
 
Cloud, Cache, and Configs
Cloud, Cache, and ConfigsCloud, Cache, and Configs
Cloud, Cache, and Configs
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Creating native apps with WordPress
Creating native apps with WordPressCreating native apps with WordPress
Creating native apps with WordPress
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
 
JRuby and You
JRuby and YouJRuby and You
JRuby and You
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code ExampleMaven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Spring J2EE
Spring J2EESpring J2EE
Spring J2EE
 
Android Jetpack: Room persistence library
Android Jetpack: Room persistence libraryAndroid Jetpack: Room persistence library
Android Jetpack: Room persistence library
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

A Unified SOAP/JSON API with Symfony2

  • 1. A UNIFIED SOAP / JSON API using Symfony2 Tuesday, 12 June 12
  • 2. ABOUT ME • Craig Marvelley • Developer at Box UK • @craigmarvelley • Using Symfony for ~ 1 year Tuesday, 12 June 12
  • 3. THE PROBLEM WEBSITE LEGACY APIS (SOAP) MOBILE DEVICES Tuesday, 12 June 12
  • 4. THE SOLUTION SOAP WEBSITE FACADE API SOAP LEGACY APIS (SOAP/JSON) (SOAP) JSON MOBILE DEVICES Tuesday, 12 June 12
  • 5. Request /json /soap JSONController SOAPController Processing Service JSON Response SOAP Response Tuesday, 12 June 12
  • 6. KEY COMPONENTS • Individual request classes to encapsulate data •A custom ParamConverter creates objects from JSON requests • Objects created from SOAP requests according to WSDL • WebserviceManager class performs processing and creates an individual response object • Response is returned to appropriate controller, and output Tuesday, 12 June 12
  • 7. <?php namespace BoxUKBundleApiBundleRequest; use BoxUKBundleApiBundleRequest; use SymfonyComponentValidatorConstraints as Assert; use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap; /** * @AssertCallback(methods={ * { "BoxUKBundleApiBundleRequestValidator", "isValidDomainName"} * }) */ class DomainInfoRequest extends AbstractRequest { /** * @AssertNotBlank() * @SoapComplexType("string") */ private $domainName; public function setDomainName( $domainName ) { $this->domainName = $domainName; } public function getDomainName() { return $this->domainName; } } Tuesday, 12 June 12
  • 8. <?php namespace BoxUKBundleApiBundleRequest; use BoxUKBundleApiBundleRequest; use SymfonyComponentValidatorConstraints as Assert; use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap; /** * @AssertCallback(methods={ * { "BoxUKBundleApiBundleRequestValidator", "isValidDomainName"} * }) */ class DomainInfoRequest extends AbstractRequest { /** * @AssertNotBlank() * @SoapComplexType("string") */ private $domainName; public function setDomainName( $domainName ) { $this->domainName = $domainName; } public function getDomainName() { return $this->domainName; } } Tuesday, 12 June 12
  • 9. <?php namespace BoxUKBundleApiBundleRequest; use BoxUKBundleApiBundleRequest; use SymfonyComponentValidatorConstraints as Assert; use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap; /** * @AssertCallback(methods={ * { "BoxUKBundleApiBundleRequestValidator", "isValidDomainName"} * }) */ class DomainInfoRequest extends AbstractRequest { /** * @AssertNotBlank() * @SoapComplexType("string") */ private $domainName; public function setDomainName( $domainName ) { $this->domainName = $domainName; } public function getDomainName() { return $this->domainName; } } Tuesday, 12 June 12
  • 10. <?php namespace BoxUKBundleApiBundleController; use SymfonyBundleFrameworkBundleControllerController; use BoxUKBundleApiBundleRequestDomainInfoRequest; /** * @Route("/json") */ class JsonController extends Controller { /** * @Route("/domainInfo") * @Method("GET") */ public function domainInfoAction(DomainInfoRequest $request) { return $this->respond( $this->getManager()->domainInfo( $request ) ); } /** * @return BoxUKBundleApiBundleManagementWebserviceManager */ protected function getManager() { return $this->container->get( 'box_uk.api.webservice_manager' ); } .... } Tuesday, 12 June 12
  • 11. <?php namespace BoxUKBundleApiBundleController; use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap; use SymfonyComponentDependencyInjectionContainerAware; class SoapController extends ContainerAware { /** * @SoapMethod("domainInfo") * @SoapParam("request", phpType = "BoxUKBundleApiBundleRequest DomainInfoRequest") * @SoapResult(phpType = "BoxUKBundleApiBundleResponseDomainInfoRequest") */ public function domainInfoAction(DomainInfoRequest $request) { $response = $this->getManager()->domainInfo($request); return $this->respond($response); } .... } Tuesday, 12 June 12
  • 12. <?php namespace BoxUKBundleApiBundleController; use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap; use SymfonyComponentDependencyInjectionContainerAware; class SoapController extends ContainerAware { /** * @SoapMethod("domainInfo") * @SoapParam("request", phpType = "BoxUKBundleApiBundleRequest DomainInfoRequest") * @SoapResult(phpType = "BoxUKBundleApiBundleResponseDomainInfoRequest") */ public function domainInfoAction(DomainInfoRequest $request) { $response = $this->getManager()->domainInfo($request); return $this->respond($response); } .... } Tuesday, 12 June 12
  • 13. <?php namespace BoxUKBundleApiBundleController; use BeSimpleSoapBundleServiceDefinitionAnnotation as Soap; use SymfonyComponentDependencyInjectionContainerAware; class SoapController extends ContainerAware { /** * @param BoxUKBundleApiBundleResponse $response * @return mixed */ protected function respond( $response ) { if ( !$response->getSuccess() ) { $code = $response->getCode(); throw new SoapFault( $faultcode, $response->getErrorMessage(), null, $response->getErrorCode() ); } return $this->getSoapResponse()->setReturnValue( $response ); } } Tuesday, 12 June 12
  • 14. WEBSERVICE MANAGER • Registered as a service in services.xml • Injected into both JSON and SOAP controllers • Validates request content according to annotations • Handles communication with legacy webservice API • Uses Monolog for fine-grained logging (error & activity) • Uses Doctrine2 to access and persist data • Constructs responses Tuesday, 12 June 12
  • 15. HANDY SYMFONY2 FEATURES • Used a custom annotation serializer to transform objects into JSON • Used a ParamConverter to transform Symfony Request into agnostic Request objects (JSON only) • Used a kernel listener to automatically validate user’s access key (JSON only) • Used commands with a crontab to perform periodic updates to the database Tuesday, 12 June 12
  • 16. COOL BUNDLES • BeSimpleSoapBundle - Provides SOAP integration for Symfony2, automatically serialize/deserialise data to objects. USES ZENDSOAP! • LiipFunctionalTestBundle - Enhanced functional tests, database caching • DoctrineFixturesBundle - For maintaining test data for functional tests • DoctrineMigrationsBundle - For versioning the database schema Tuesday, 12 June 12
  • 17. TESTING • Lots and lots of unit tests • Functional tests for controller actions • Used a developer-in-test • He used SoapUI to create test cases • Automated SOAP request/responses from WSDL Tuesday, 12 June 12
  • 18. THANKS FOR LISTENING! https://joind.in/talk/view/6667 @craigmarvelley Tuesday, 12 June 12