본문 바로가기

.Trend/IT

[RoR] Web Service on Rails

참고] Action Web Service ==> AWS

  1. AWS 는 ?
    1. AWS 는 Rails 어플리케이션에서, SOAP / XML-RPX protocol 의 지원을 한다.( 서버측 )
    2. W3C speicification의 모든 규정을 만족하지 않을 뿐더러, XML-RPC 지원 또한 Full로 지원하지 않는다.
  2. API 정의
    1. Script
      shell> ruby script/generate web_service <srvc_name#1> <definition#1> ... <definition#n>

      E.g>  ruby script/generation web_service Backend find_all_products find_product_by_id

      결과> API정의와 이를 활용하는 Controller를 만든다. (Script)
               필요에 맞게, API def 변경, 또 이에 따른 Controller 도 변경함.
    2.  Stub API definition
       class BackendAPI < ActionWebService::API::Base
            api_method :find_all_prodcuts
            api_method :find_product_by_id
       end
       Skeleton controller
       class BackendController < ApplicationController
            wsdl_service_name 'Backend'
            def find_all_products
            end
            def find_product_by_id
            end
      end
       
       Finished.. (API definition 변경)
       class ProductApi < ActionWebService::API:Base
           api_method :find_all_prodcuts,
                               :returns => [[:int]]
           api_method :find_product_by_id,
                               :expects => [:int],
                               :returns => [Product]
       end
       Web Service 변경
       class BackendController < ApplicationController
           wsdl_service_name 'Backend'
           web_service_api ProductApi
           web_service_scaffold :invoke
           def find_all_products
               Product.find(:all).map{ |prodcut| product.id}
           end
           def find_product_by_id(id)
               Product.find(id)
           end
       end


    3. Method Signatures
      - api_method()
         이를 이용하여, Web Service에서 각 사용할 Method을 선언한다.
         Signatures을 사용하여, Method의 호출 및 return type을 결정한다.
      - Option
         api_method()는 ":expects" , ":returns" 옵션을 사용할수가 있다.
         ":expects" => Method parameter 각각의 type을 정의
         ":returns" => Method return type을 정의>
    4. Temp
  3. Dispatching Modes

    Remote caller측에서, endpoint URL로 "invokation request"을 보낸다.
    이후, AWS에서는 이 request을 받아와 해당 service을 구현하고 있는
    Object내 method로 Mapping을 담당한다. (Dispatching)
    1. Direct Dispatching (default)

      image

      API defintion (여기서는 NewPost()) 이 Controller에 직접 붙어서,
      API method 구현이, Controller내 Public instance method로 대체된다.
    2. Layers Dispatching

      하나의 Contoller에 여러 API들을 구현하게끔 구성된다.
      즉, 모든 API들에 대해, endpoint URL은 유일하다.
    3. Delegated Dispatching

      Layered Dispathincg과 비슷하지만, API당 하나의 unique endpoint URL이 있다는것.
      "web_service_dispatching_mode" 을 통해여, Controller 의 dispatching mode을
      결정 할 수 있다.

      image
  4. Using Alternate Dispatching
    1. Layered Dispatching Mode
    2. Implementing Delegating Dispatching
  5. Method Invocation Interception
  6. Tesing Web Services
    1. External Client Applications -SOAP
    2. External Client Applications -XML-RPC
  7. Protocol Clients
    1. Temp