Java Webservice Basic

The following example shows ho to start a web service under Java6 or higher. This example does not show the implementation of the service itself, but the configuration of the web server. The implementation of the service is the object serviceImpl. There is explicitly created an object of the class com.sun.net.httpserver.HttpServer which is then configured.

There is no exception handling shown here.

[code lang=”java”]
import javax.xml.ws.Endpoint;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpServer;

httpServer = HttpServer.create(new InetSocketAddress(interfaceName, port), 0);
HttpContext httpContext = httpServer.createContext("/path");
Endpoint endpoint = Endpoint.create(serviceImpl);
endpoint.publish(httpContext);
[/code]

Further articles will describe how to configure more aspects of the server (threads, SSL, …)

Leave a Reply

Your email address will not be published. Required fields are marked *