Back to blog
Dec 27, 2024
4 min read

Configuration driven REST framework - 4.Config samples (Configuration driven REST framework)

Comprehensive Guide to Strategy Pattern Implementation with Spring Framework

Configuration Examples for Service Implementations

1. Notification Service Configuration

Endpoint Configuration (notification-endpoints.json)

{
"path": "/api/notifications",
"httpMethod": "POST",
"requiredRights": ["SEND_NOTIFICATIONS", "USE_TEMPLATES"],
"inputTransformer": "notificationRequestTransformer",
"businessLogicBean": "notificationProcessor",
"outputTransformer": "notificationResponseTransformer",
"validationRules": {
"rateLimit": {
"maxRequests": 100,
"timeWindowSeconds": 60
},
"maxRequestSizeBytes": 32768,
"allowedContentTypes": ["application/json"],
"customValidations": {
"maxBulkSize": "1000",
"templateValidation": "strict",
"priorityCheck": "true"
}
}
}

Application Properties (notification-service.yml)

notification:
channels:
email:
maxRetries: 3
retryDelaySeconds: 300
timeout: 30000
maxConcurrentConnections: 50
sms:
provider: twilio
maxRetries: 2
retryDelaySeconds: 60
priorityQueues: true
push:
fcmEnabled: true
apnsEnabled: true
maxBatchSize: 500
templates:
cacheDuration: 3600
maxSize: 1000
validateOnLoad: true
scheduling:
threadPoolSize: 10
maxQueueSize: 10000
defaultDelay: 60

2. Report Generation Service Configuration

Endpoint Configuration (report-endpoints.json)

{
"path": "/api/reports",
"httpMethod": "POST",
"requiredRights": ["GENERATE_REPORTS", "ACCESS_DATA_WAREHOUSE"],
"inputTransformer": "reportRequestTransformer",
"businessLogicBean": "reportGenerator",
"outputTransformer": "reportResponseTransformer",
"validationRules": {
"rateLimit": {
"maxRequests": 10,
"timeWindowSeconds": 300
},
"maxRequestSizeBytes": 65536,
"allowedContentTypes": ["application/json"],
"customValidations": {
"maxMetrics": "20",
"maxDimensions": "10",
"dateRangeValidation": "strict"
}
}
}

Application Properties (report-service.yml)

report:
generation:
maxConcurrentJobs: 5
defaultTimeout: 3600
maxRowsPerFile: 1000000
formats:
excel:
maxSheets: 10
enableMacros: false
template: "classpath:templates/report-template.xlsx"
pdf:
dpi: 300
pageSize: A4
enableCompression: true
csv:
delimiter: ","
includeHeaders: true
encoding: UTF-8
cache:
enabled: true
ttlMinutes: 60
maxEntries: 1000
dataSource:
readTimeout: 300
fetchSize: 10000
poolSize: 20

3. Document Processing Service Configuration

Endpoint Configuration (document-endpoints.json)

{
"path": "/api/documents/process",
"httpMethod": "POST",
"requiredRights": ["PROCESS_DOCUMENTS", "ACCESS_STORAGE"],
"inputTransformer": "documentRequestTransformer",
"businessLogicBean": "documentProcessor",
"outputTransformer": "documentResponseTransformer",
"validationRules": {
"rateLimit": {
"maxRequests": 50,
"timeWindowSeconds": 3600
},
"maxRequestSizeBytes": 104857600,
"allowedContentTypes": [
"multipart/form-data",
"application/pdf",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
],
"customValidations": {
"virusScan": "true",
"fileTypeValidation": "strict",
"maxOperations": "5"
}
}
}

Application Properties (document-service.yml)

document:
processing:
async:
corePoolSize: 10
maxPoolSize: 20
queueCapacity: 1000
threadNamePrefix: "doc-proc-"
storage:
type: s3
tempDir: "/tmp/doc-processing"
retentionDays: 7
operations:
ocr:
engine: tesseract
language: eng
dpi: 300
timeout: 600
compression:
quality: 0.8
maxSizeMB: 10
conversion:
supportedFormats:
- pdf
- docx
- txt
- html
callbacks:
maxRetries: 3
retryDelay: 60
timeout: 30
monitoring:
enabled: true
metricsInterval: 60
alertThresholds:
queueSize: 1000
processingTime: 3600
errorRate: 0.05

4. Security Configuration Example

Security Properties (security-config.yml)

security:
jwt:
issuer: "your-company"
tokenDuration: 3600
refreshTokenDuration: 86400
algorithm: RS256
rateLimit:
enabled: true
repository: redis
fallback: inMemory
cors:
allowedOrigins:
- "https://your-domain.com"
allowedMethods:
- GET
- POST
- PUT
- DELETE
allowedHeaders:
- Authorization
- Content-Type
exposedHeaders:
- X-Rate-Limit
- X-Rate-Remaining
encryption:
algorithm: AES256
keyRotationDays: 30
audit:
enabled: true
logPattern: "%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n"
retention: 90

5. Caching Configuration Example

Cache Properties (cache-config.yml)

cache:
provider: redis
fallback: caffeine
redis:
host: localhost
port: 6379
database: 0
timeout: 2000
poolSize: 20
caffeine:
initialCapacity: 100
maximumSize: 1000
expireAfterWrite: 3600
policies:
templates:
ttl: 3600
maxEntries: 1000
reports:
ttl: 7200
maxEntries: 500
documents:
ttl: 1800
maxEntries: 200

6. Monitoring Configuration Example

Monitoring Properties (monitoring-config.yml)

monitoring:
metrics:
enabled: true
exportType: prometheus
stepInterval: 60
tracing:
enabled: true
sampler: probabilistic
probability: 0.1
health:
diskSpace:
enabled: true
threshold: 10GB
memory:
enabled: true
threshold: 0.9
alerting:
slack:
webhook: "https://hooks.slack.com/services/xxx"
channel: "#alerts"
email:
enabled: true
recipients:
- "ops@your-company.com"
dashboard:
refresh: 30
retentionDays: 30

These configurations demonstrate:

  1. Comprehensive security settings
  2. Performance tuning parameters
  3. Resource limits and thresholds
  4. Integration settings
  5. Monitoring and alerting configuration
  6. Caching strategies
  7. Async processing setup