Gateway Object

Overview;

The Gateway Object pattern is used to define access into our service based application. That is, the Gateway handles HTTP requests and responses and potentially also XML, JSON, and other format exchanges. The Gateway should only be used as a gateway into the Service Layer and directly to a single Service Object.

Because of the above mentioned role of the Gateway Object, I typically write an InvokerGateway object which is capable of handling all HTTP requests and responses into and out of the system using a unified service method invoker interface.

Gateways should also handle exceptions as they are thrown from the service or dao layers. Gateways should translate these into human readable and machine parseable packets.

Rules;

  • Handles all HTTP / JSON / XML transfer protocol marshelling.
  • Is not wrapped in transactions. 
  • All methods considered public (open to the web) and should be properly secured. 
  • Should have a RequestURLMapper on each method. 
  • Does not contain business logic.
  • Does not query the dao layer. 


Gateway Invoker Example;


The URL /app/invoke/{service}/{method} could be used where /invoke/ is the key that the generic controller object picks up on and directs the request to the proper service layer method. The InvokeGateway would also pass along any parameters (POST or GET or PUT, etc) to the service method and the service method would then be in charge of using what it wants. This is achieved via Groovy closures in which named parameters can be passed.





0 comments:

Disqus for Wookets Wove