Tuesday, January 09, 2007

Service as a Webpage: Information Handlers in servENT

During the previous examples we have seen that we can invoke services via a custom commandline client or even using a REST-like approach. As the servent is integrated with Jetty, it is possible to extend the our service to implement a Handler (org.dbe.servent.http.ServiceHandler) that extend (or is based) the Jetty Handlers.

By implementing the ServiceHandler interface (2 methods init() and handle()) we can provide the service with a Web interface via the service real endpoint that can be used to interop with the service. This way is also ideal for implementing the REST that we discussed earlier. (However we need to search for the service as we need to know the real endpoint)

To integrate a ServiceHandler in our service, we need to do a couple of things. First of all is to declare in deployment.props that our service has a Handler. This is done by assigning the property “handler” to point to the class that implements the ServiceHandler interface (see below)

File: deployment.props

The second thing that we need to do is to implement the declared hander. See example below. In our case we have called the service itself from the Handler.

And it is accessed with for example with a web browser by pointing to the endpoint of the service, as a standard URI. In our example the output is the webpage itself.


Post a Comment

<< Home