0
# Configuration Management
1
2
Configuration utilities for service mapping, path normalization, and key management in microservices environments. Designed for Light-4J framework configuration patterns and service discovery mechanisms.
3
4
## Capabilities
5
6
### Configuration Utilities
7
8
Utility class providing configuration management functionality for service mapping and path normalization.
9
10
```java { .api }
11
/**
12
* Configuration utilities for service mapping and path normalization
13
*/
14
public class ConfigUtils {
15
public static final String DELIMITOR = "@";
16
17
// Service mapping
18
public static String findServiceEntry(String method, String searchKey, Map<String, Object> mapping);
19
20
// Path operations
21
public static String normalisePath(String requestPath);
22
23
// Key management
24
public static String toInternalKey(String key);
25
public static String toInternalKey(String method, String path);
26
27
// Data normalization
28
public static Map<String, Object> normalizeMap(Map<String, Object> map, List<String> keysToNotSort);
29
public static List<?> normalizeList(List<?> list, List<String> keysToNotSort);
30
31
// Pattern matching
32
public static boolean matchesAny(String input, List<String> stringsToMatch);
33
}
34
```
35
36
**Usage Examples:**
37
38
```java
39
import com.networknt.utility.ConfigUtils;
40
import java.util.*;
41
42
// Service discovery and mapping
43
Map<String, Object> serviceMapping = Map.of(
44
"GET@/api/users", "UserService",
45
"POST@/api/orders", "OrderService",
46
"GET@/api/products/{id}", "ProductService"
47
);
48
49
String service = ConfigUtils.findServiceEntry("GET", "/api/users", serviceMapping);
50
// Result: "UserService"
51
52
// Path normalization
53
String normalizedPath = ConfigUtils.normalisePath("/api//users///123/");
54
// Result: "/api/users/123"
55
56
// Internal key generation
57
String methodPathKey = ConfigUtils.toInternalKey("GET", "/api/users");
58
// Result: "GET@/api/users"
59
60
String simpleKey = ConfigUtils.toInternalKey("user.config");
61
// Result: normalized internal key format
62
63
// Configuration map normalization
64
Map<String, Object> config = new HashMap<>();
65
config.put("database.host", "localhost");
66
config.put("database.port", 5432);
67
config.put("api.version", "v1");
68
69
List<String> preserveOrder = Arrays.asList("api.version");
70
Map<String, Object> normalized = ConfigUtils.normalizeMap(config, preserveOrder);
71
72
// Pattern matching for configuration
73
List<String> patterns = Arrays.asList("*.json", "*.yml", "*.properties");
74
boolean matches = ConfigUtils.matchesAny("config.json", patterns); // true
75
76
// Service routing example
77
public class ServiceRouter {
78
private final Map<String, Object> routingConfig;
79
80
public ServiceRouter(Map<String, Object> routingConfig) {
81
this.routingConfig = ConfigUtils.normalizeMap(routingConfig, null);
82
}
83
84
public String findService(String method, String path) {
85
String normalizedPath = ConfigUtils.normalisePath(path);
86
return ConfigUtils.findServiceEntry(method, normalizedPath, routingConfig);
87
}
88
}
89
```