O'Reilly logo

Java Web Services: Up and Running by Martin Kalin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Container-Managed Security for Web Services

This most recent version of the RabbitCounter service does provide user authentication, but not in a way that scales. A better approach would be to use a web service container that provides not only user authentication but also wire-level security. Tomcat, the reference implementation for a Java web container, can provide both. Chapter 4 showed how Tomcat can be used to publish RESTful web services as servlets. Tomcat also can publish SOAP-based services. Tomcat can publish either a @WebService or a @WebServiceProvider.

The example to illustrate how Tomcat provides container-managed security is built in two steps. The first step publishes a SOAP-based service with Tomcat, and the second step adds security. A later example is a secured @WebServiceProvider under Tomcat.

Deploying a @WebService Under Tomcat

The SOAP-based service is organized in the usual way. Here is the code for the TempConvert SEI:

package ch05.tc;
import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public interface TempConvert {
    @WebMethod float c2f(float c);
    @WebMethod float f2c(float f);
}

And here is the code for the corresponding SIB:

package ch05.tc;
import javax.jws.WebService;

@WebService(endpointInterface = "ch05.tc.TempConvert")
public class TempConvertImpl implements TempConvert {
    public float c2f(float t) { return 32.0f + (t * 9.0f / 5.0f); }
    public float f2c(float t) { return (5.0f / 9.0f) * (t - 32.0f); }
}

For deployment under Tomcat, the service ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required