Welcome Guest!
Create Account | Login
Locator+ Code:

FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

email article
printer friendly

Write and Configure JAX-RPC Handlers
Avoid the limitations of an interceptor model to provide services. See how to write and configure handler components for generic and specific implementations
by Kevin Jones

Posted January 7, 2004

Developers can use Java API for XML-based Remote Procedure Calls (JAX-RPC) to map Web service operations onto Java method calls. The concept is fairly straightforward. A Web service consists of one or more operations, and each operation typically contains an input message and an output message. Each operation typically maps to a method on a Java interface, with the input message mapping to method parameters and the output message mapping to the method return type.

This scenario is very similar to many RPC APIs and has similar advantages and disadvantages to those APIs. One obvious issue is that of providing service. If each operation requires the same set of services, such as security or logging, how do you provide those services?

One solution is to have each method call some helper class and have that class provide the services. However, this solution is far from ideal. In J2EE the typical way of providing layered services is by an interceptor model. For example, in Web applications there are filters, while in EJB the container provides an interposer that is configured declaratively to provide a set of services for an end point.

JAX-RPC implementations are typically performed as either Web application-based or Enterprise JavaBeans (EJB)-based solutions; however, using filters or interposers in these cases is not the best solution. Filters are there to file raw HTTP messages, so any filter would need to intercept the HTTP request and then read in and process the XML before passing the request on. EJB does, but as yet there is no direct support in EJB for providing interposition of SOAP messages.

To overcome these limitations the JAX-RPC specification defines something called handlers. A handler is a component that can be associated with an entire Web service or with a particular Web service interface. A Web service can have a number of ports—a port is analogous to a Java interface—and a handler can be associated with just an interface. Handlers can be very generic, such as logging or caching handlers, or very specific, such as handlers that want to process an application-specific SOAP header. Here we will look at how to write generic handlers and how to configure them for a JAX-RPC client and a JAX-RPC server.

Writing Handlers
A handler is a Java class that implements the javax.xml.rpc.handler.Handler interface. This interface has six methods, and you usually don't need to implement all of them. To help developers the JAX-RPC API also contains a GenericHandler adapter class that implements all of the methods of Handler apart from getHeaders (the details are beyond the scope of this article). The easiest way to write a handler is to extend GenericHandler:

public class LoggingHandler 
  extends GenericHandler
  // must implement this
  public QName[] getHeaders(){
    return new QName[0];

Back to top

Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTPOnline Home