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

Securing the RabbitCounter Service

The Endpoint.publish method does not support HTTPS connections. However, core Java 6 includes an HttpServer class and its subclass HttpsServer, which can be used to publish a service under HTTPS. (The Endpoint publisher, in fact, uses the HttpServer class under the hood.) The HttpsServer can be used by itself to publish a RESTful service such as the RabbitCounter. Here is a revised publisher for the RabbitCounter service, a publisher that accepts HTTPS connections:

package ch05.rc; import java.net.InetSocketAddress; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLEngine; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.security.cert.X509Certificate; import java.security.SecureRandom; import java.security.KeyStore; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManagerFactory; import java.io.FileInputStream; import javax.xml.ws.http.HTTPException; import java.io.OutputStream; import java.io.InputStream; import java.io.IOException; import java.util.Collections; import java.util.Map; import java.util.HashMap; import java.util.Collection; import java.util.List; import java.util.ArrayList; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpsServer; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpsParameters; ...

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