HTTP REST API server for platform-java management using JDK's built-in com.sun.net.httpserver.
The platform-java-rest-api module provides a complete HTTP REST API for managing platform-java instances. It offers programmatic access to deployment, lifecycle management, and metrics retrieval.
- Full CRUD Operations: Deploy, list, start, stop, undeploy applications
- Metrics Retrieval: Get real-time resource usage (CPU, memory, threads)
- Status Monitoring: Query application states and health
- JSON API: Request and response bodies use JSON format
- Lightweight: Uses JDK's built-in HTTP server (no external dependencies)
- Authentication: Optional API key authentication via
ApiAuthFilter
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/applications |
Deploy a new application |
| GET | /api/applications |
List all applications |
| GET | /api/applications/{id} |
Get application details |
| GET | /api/applications/{id}/status |
Get application status and metrics |
| POST | /api/applications/{id}/start |
Start an application |
| POST | /api/applications/{id}/stop |
Stop an application |
| DELETE | /api/applications/{id} |
Undeploy an application |
| GET | /api/applications/{id}/metrics |
Get resource metrics history |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/platform/status |
Get platform status and summary |
| GET | /api/platform/health |
Health check endpoint |
import org.flossware.platform-java.api.PlatformManager;
import org.flossware.platform-java.core.ApplicationManager;
import org.flossware.platform-java.rest.JdkHttpApiServer;
public class Main {
public static void main(String[] args) throws IOException {
PlatformManager manager = new ApplicationManager();
JdkHttpApiServer server = new JdkHttpApiServer(manager, 8080);
server.start();
System.out.println("API server running on http://localhost:8080");
}
}curl -X POST http://localhost:8080/api/applications \
-H "Content-Type: application/json" \
-d '{
"applicationId": "my-app",
"name": "My Application",
"mainClass": "com.example.MyApp",
"classpathEntries": ["file:///path/to/app.jar"],
"threadPool": {
"corePoolSize": 4,
"maxPoolSize": 20
}
}'Response (201 Created):
{
"applicationId": "my-app",
"name": "My Application",
"mainClass": "com.example.MyApp",
"state": "DEPLOYED",
"deployedAt": "2024-05-24T10:30:00Z",
"metrics": {
"cpuTimeNanos": 0,
"heapUsedBytes": 0,
"threadCount": 0
}
}curl http://localhost:8080/api/applicationsResponse (200 OK):
[
{
"applicationId": "my-app",
"name": "My Application",
"mainClass": "com.example.MyApp",
"state": "DEPLOYED",
"deployedAt": "2024-05-24T10:30:00Z",
"metrics": { ... }
}
]curl -X POST http://localhost:8080/api/applications/my-app/startResponse (200 OK):
{
"applicationId": "my-app",
"state": "RUNNING",
...
}curl http://localhost:8080/api/applications/my-app/statusResponse (200 OK):
{
"applicationId": "my-app",
"state": "RUNNING",
"deployedAt": "2024-05-24T10:30:00Z",
"metrics": {
"cpuTimeNanos": 1234567890,
"heapUsedBytes": 52428800,
"threadCount": 15
}
}curl -X POST http://localhost:8080/api/applications/my-app/stopResponse (200 OK)
curl -X DELETE http://localhost:8080/api/applications/my-appResponse (204 No Content)
curl http://localhost:8080/api/platform/statusResponse (200 OK):
{
"totalApplications": 3,
"runningApplications": 2,
"stoppedApplications": 1,
"failedApplications": 0,
"uptime": "2h 15m 30s"
}All errors return a consistent JSON structure:
{
"error": "Application not found",
"status": 404,
"timestamp": "2024-05-24T10:30:00Z"
}Common status codes:
400- Bad Request (invalid JSON, missing required fields)404- Not Found (application does not exist)409- Conflict (application already exists, invalid state transition)500- Internal Server Error
Enable API key authentication:
JdkHttpApiServer server = new JdkHttpApiServer(manager, 8080);
server.setApiKey("your-secret-api-key");
server.start();Clients must include the API key in the X-API-Key header:
curl -H "X-API-Key: your-secret-api-key" \
http://localhost:8080/api/applicationsDefault port is 8080. Override in constructor:
JdkHttpApiServer server = new JdkHttpApiServer(manager, 9090);CORS is enabled by default for all origins. To restrict:
// Custom CORS configuration requires modifying ApiAuthFilter- JdkHttpApiServer: Main server class, manages HTTP server lifecycle
- ApplicationApiHandler: Handles
/api/applications/*endpoints - PlatformApiHandler: Handles
/api/platform/*endpoints - ApiAuthFilter: Optional authentication filter
- ApplicationResponseDTO: JSON response model for applications
- ErrorResponseDTO: JSON response model for errors
platform-java-api- Platform management APIjackson-databind- JSON serializationslf4j-api- Logging- JDK 21+ (HttpServer is part of JDK)
Run tests with:
mvn testTest coverage includes:
- All HTTP endpoints (deploy, start, stop, undeploy, list, status)
- Error handling and validation
- Authentication filter
- JSON serialization/deserialization
- Web Console - Browser-based UI built on this API
- Swing UI - Desktop UI using this API
- QUICKSTART - Quick start guide with API examples
- Main README - Platform overview