Service Controller
How can the correct web service be executed without having to maintain complex parsing and routing logic?
All web services are dependent on mechanisms that receive requests, evaluate the request's meaning, and route requests to
procedures (i.e. class methods, request handlers) which implement the service behaviors.
Service designers may centralize this logic in a Front Controller.
This pattern works quite well if the correct service can be selected by simply parsing the requested URI.
Unfortunately, this is not always the case. The routing logic can become much more complex if the service must be selected based on the client's preferred
media types, message header values, or message body content.
Developers could benefit from a simple declarative approach that can be interpreted by a Front Controller.
Create a class that identifies a set of related services. Annotate each class method with routing expressions that can be interpreted by a Front Controller.
Service Controllers are classes that contain one or more public methods (a.k.a. Request Handlers, Web Methods)
that control the execution of business tasks and coordinate access to resources (e.g. files, documents, images, etc).
The rules that define which handlers should be invoked for different requests are provided through annotations known collectively as
Routing Expressions. These expressions typically precede each web method in the Service Controller, and are interpreted by the
Front Controller of frameworks like
JAX-WS,
JAX-RS,
Axis2, and
WCF.
When a web server receives a request, the framework selects and invokes the appropriate handler by evaluating various aspects
of the request against these expressions. The types of Routing Expressions used in the Service Controller depends on the
Service API style.
Frameworks that support Resource APIs employ
URI Templates,
Request Method Designators, and Media Type Annotations.
Frameworks that support RPC and
Message APIs often use annotations that evaluate
SOAPAction or
WS-Addressing Action headers.
Service Controllers are often used in conjunction with data-binding technologies like
JAXB or
WCF's .Net Data Contract Serializer.
These technologies are optional, and developers may choose to work with lower level streams.