Skip to content
lapistano edited this page Jan 3, 2011 · 2 revisions

This controller exposes itself as a web-service. This is done using Symfony2 to route incoming requests to a specific method of this controller class. The route is configured in the file routing.yml in the Resources/config directory of the Bundle directory. Architecture. The architecture of this service is as easy as straight forward. It mainly depends on a base importer. Since it is not mandatory to use the base implementation there is an interface defining he contract to be respected on a custom importer. The class diagram shows the architecture as described.

ImportController

This controller handles the communication to the outside world. It is literally the 'firewall' of the system verifying and filtering the incoming request. Thus it has not import-logic at all it mainly gets configured by the dependent import-module. Only an ip white-list configuration is available for direct configuration (see app/config/config.yml for an example). Once the request has passed the 'firewall', its content gets extracted, verified (e.g. the DTD if configured to be done), and passed the the import-module.

The controller must not implement any logic to import data in to the storage. This has to be handled in the import-module to be injected. This is to keep the architecture and the possible options of the controller to handle different formats flexible and easy to extend.

Importer*

This stage of the import process is the brain of the process. In cooperation with the base class it transcodes the given content to format understandable for the storage engine. The * next to Importer is a wild-card telling you that the name of every import module has to be prefixed with Importer.

ImporterBase

This class consolidates base functionality of an importer in to a reusable format. It is recommended to be used as parent of an import module but not mandatory. It also implements the import-interface defining the api of each import-module.

ImporterInterface

Since it is not mandatory to extend the importer base class the need of a contract to define the api of an import module is necessary.

Configuration

Routing

The routing is done by Symfony2 specific configuration files which are explained on the Symfony2 website. The following code is an example of the current configuration. File: app/config/routing.yml

import:
     resource: ImportBundle/Resources/config/routing.yml
     File: src/Application/ImportBundle/Resources/config/routing.yml
     import_ws:
         pattern: /:dataType
         defaults: { _controller: import.controller:indexAction }

Setup

The basic setup of this controller is done as a service within Symfony2. The code example is the current configuration of this service and is located within the "service" section of the config.yml file. It defines the class ImportController as the handler of this service and the arguments to be passed. Since not each and every import model is defined the set of arguments may change in the future.

File: app/config/config.yml

import.controller:
     class: Application\ImportBundle\Controller\ImportController
     arguments:
         - whitelist:
           liipzh: [192.168.80.0/24]
         - @request
         - @response
         - fazbooks: @?import.importer.faz.books
         - @?logger

HTTP response codes

This section lists the used HTTP response codes to communicate the status of the handled request.

OK (200), No Content (204)

This response code will be returned if the request passed the verification and validation, and the content has been imported without any difficulties.

Bad Request (400)

This response code will be returned if the request does not pass the verification in terms of

  • a charset not matching the defined charset set by RequestMatcher::matchCharset(array $charsets) (usually UTF-8 is recommended)
  • a path info not matching the defined PATH_INFO declared by RequestMatcher::matchPath($regexp)
  • a not matching HTTP header field (see: Wikipedia HTTP request header fields)
  • a response does not have a content or is an invalid xml stream.

Unsupported Media Type (415)

This response code will be returned if the request does not match the defined request format. This is basically represented by the Accept HTTP and CONTENT_TYPE header field. The Content-Type header field will only be available for a request using the PUT or POST method. A list of all HTTP header types is available at Wikipedia Internet media type page.

Internal Server Error (500)

This response code will be returned when no more specific message is suitable.

Not Implemented (501)

This response code will be returned if the request method does not match the expected one.

Service Unavailable (503)

This response code will be returned if the request is declined because of

  • the sender ip address does not match the defined one
  • the sender ip address is not defined in a ip address white-list
  • the sending host does not match a defined host.