Introduction
Web Service Technology
J2EE for web service.
Developing Web Services
2
Definition:
A Web Service is a standardized software component accessible over the internet
using protocols like HTTP.
It enables machine-to-machine communication using XML or JSON.
Key Features:
Platform-independent
Language-neutral
Uses open standards (SOAP, WSDL, UDDI, REST)
3
Achieved via standardized protocols (SOAP/REST) and data formats
(XML/JSON).
Example: A Java-based service can be consumed by a .NET client using HTTP and
XML.
4
J2EE Contributions:
Provides APIs and runtime for building scalable, secure web services.
Supports both SOAP (via JAX-WS) and REST (via JAX-RS).
Common Components:
Component Role
Servlets Handle HTTP requests/responses
JSP Dynamic content generation
EJB Business logic layer
JAX-WS SOAP-based service development
JAX-RS RESTful service development
JNDI, JMS, JDBC Integration and resource access
5
Use Case: Student Info Service
Steps:
1. Define SEI (Service Endpoint Interface):
@WebService
public interface StudentService {
@WebMethod
String getStudentDetails(String id);
}
6
2. Implement SEI:
@WebService(endpointInterface =
"[Link]")
public class StudentServiceImpl implements
StudentService {
public String getStudentDetails(String id) {
return "Name: John, ID: " + id;
}
}
7
3. Deploy to J2EE Server (e.g., GlassFish):
Package as WAR
Use WSDL auto-generation
4. Client Access:
Use SOAP client (e.g., Apache Axis or JAX-WS client)
8
Example: Weather API
Annotations Used:
@Path, @GET, @POST, @Produces, @Consumes
Sample Code:
@Path("/weather")
public class WeatherService {
@GET
@Path("/{city}")
@Produces(MediaType.APPLICATION_JSON)
public Weather getWeather(@PathParam("city") String city) {
return new Weather(city, 32.5, "Sunny");
} 9
}
Feature SOAP REST
HTTP methods (GET,
Protocol XML over HTTP
POST, etc.)
Data Format XML JSON, XML
Faster (lightweight
Performance Slower (verbose XML)
JSON)
Scalability Less scalable Highly scalable
Security WS-Security HTTPS, OAuth
10
11
12