SmartCampus
A production-ready RESTful API built with JAX-RS (Jersey) for managing campus rooms and IoT sensors. Features full CRUD, sensor reading history, sub-resource locators, query filtering, HATEOAS discovery, and a global exception mapper — all running on an embedded Grizzly HTTP server.
Demo Video
Key Features
JAX-RS Sub-Resource Locators
Sensor readings are handled by a dedicated SensorReadingResource class, keeping each resource focused on a single responsibility.
Thread-Safe In-Memory Store
All data lives in a singleton DataStore backed by ConcurrentHashMap — safe under concurrent HTTP requests without manual synchronization.
Global Exception Mapper
Catches all unhandled exceptions and returns generic error responses, preventing stack traces and internal details from leaking to clients.
Request/Response Logging Filter
A JAX-RS ContainerRequestFilter logs every request and response automatically — no manual logging boilerplate in resource methods.
HATEOAS Discovery
The root endpoint returns navigable links to all resources so clients can explore the API without hardcoding URLs.
API Endpoints
/api/v1Discovery — lists all available resource links/api/v1/roomsFetch all campus rooms/api/v1/roomsCreate a new room/api/v1/rooms/{roomId}Delete room — 409 if sensors attached/api/v1/sensors?type=CO2Filter sensors by type via @QueryParam/api/v1/sensors/{id}/readingsLog a sensor reading — 403 if MAINTENANCEBase URL: http://localhost:8080/api/v1
Tech Stack
Project Structure
smart-campus-api/
├── pom.xml
└── src/main/java/com/smartcampus/
├── Main.java
├── SmartCampusApplication.java
├── model/
│ ├── Room.java
│ ├── Sensor.java
│ └── SensorReading.java
├── store/
│ └── DataStore.java
├── resource/
│ ├── DiscoveryResource.java
│ ├── RoomResource.java
│ ├── SensorResource.java
│ └── SensorReadingResource.java
└── filter/
└── LoggingFilter.javaHow to Run
git clone https://github.com/AshanWijesundara7/smart-campus-api.gitcd smart-campus-apimvn clean packagejava -jar target/smart-campus-api-1.0-SNAPSHOT.jarServer starts at http://localhost:8080/api/v1 · Requires Java 11+ and Maven 3.6+