or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration-management.mddata-structure-utilities.mdframework-integration.mdindex.mdio-file-operations.mdnetwork-operations.mdpath-template-matching.mdsecurity-cryptography.mdstring-processing.mdtime-date-operations.md

framework-integration.mddocs/

0

# Framework Constants & Integration

1

2

Framework constants and module registry functionality for Light-4J ecosystem integration, including HTTP headers, JWT claims, component registration, and general utility functions for microservices frameworks.

3

4

## Capabilities

5

6

### Framework Constants

7

8

Shared constants for all Light-4J components providing standardized string constants for headers, JWT claims, protocols, and framework identifiers.

9

10

```java { .api }

11

/**

12

* Shared constants for all light-4j components (65 total constants)

13

*/

14

public class Constants {

15

// HTTP Headers & Request/Response Constants

16

public static final String CORRELATION_ID_STRING = "X-Correlation-Id";

17

public static final String TRACEABILITY_ID_STRING = "X-Traceability-Id";

18

public static final String ADM_PASSTHROUGH_STRING = "X-Adm-PassThrough";

19

public static final String SCOPE_TOKEN_STRING = "X-Scope-Token";

20

public static final String CONSUL_TOKEN_STRING = "X-Consul-Token";

21

public static final String CSRF_TOKEN_STRING = "X-CSRF-TOKEN";

22

public static final String AUTHORIZATION_STRING = "authorization";

23

public static final String SWAGGER_OPERATION_STRING = "swagger_operation";

24

public static final String OPENAPI_OPERATION_STRING = "openapi_operation";

25

public static final String SERVICE_ID_STRING = "service_id";

26

public static final String SERVICE_URL_STRING = "service_url";

27

public static final String ENV_TAG_STRING = "env_tag";

28

public static final String HASH_KEY_STRING = "hash_key";

29

public static final String HEADER = "header";

30

public static final String HOST = "host";

31

32

// JWT Claims & Authentication Constants

33

public static final String USER_ID_STRING = "user_id";

34

public static final String UID = "uid";

35

public static final String USER_TYPE = "user_type";

36

public static final String ROLES = "roles";

37

public static final String CLIENT_ID_STRING = "client_id";

38

public static final String CID = "cid";

39

public static final String ISS = "iss";

40

public static final String CALLER_ID_STRING = "caller_id";

41

public static final String SCOPE_CLIENT_ID_STRING = "scope_client_id";

42

public static final String SCOPE_STRING = "scope";

43

public static final String SCP_STRING = "scp";

44

public static final String PRIMARY_SCOPES = "primary_scopes";

45

public static final String SECONDARY_SCOPES = "secondary_scopes";

46

public static final String ENDPOINT_STRING = "endpoint";

47

public static final String CSRF = "csrf";

48

public static final String EID = "eid";

49

public static final String AUDIT_INFO = "auditInfo";

50

public static final String SUBJECT_CLAIMS = "subject_claims";

51

public static final String ACCESS_CLAIMS = "access_claims";

52

public static final String ISSUER_CLAIMS = "issuer_claims";

53

54

// User Management & Entity Constants

55

public static final String ATT = "att";

56

public static final String POS = "pos";

57

public static final String GRP = "grp";

58

public static final String ROLE = "role";

59

public static final String EML = "eml";

60

public static final String EMAIL = "email";

61

public static final String GROUPS = "groups";

62

public static final String GROUP = "group";

63

public static final String POSITIONS = "positions";

64

public static final String POSITION = "position";

65

public static final String ATTRIBUTES = "attributes";

66

public static final String ATTRIBUTE = "attribute";

67

public static final String USERS = "users";

68

public static final String USER = "user";

69

public static final String COL = "col";

70

public static final String ROW = "row";

71

72

// Time & Numeric Constants

73

public static final int MILLS = 1;

74

public static final int SECOND_MILLS = 1000;

75

public static final int MINUTE_MILLS = 60 * SECOND_MILLS;

76

public static final int DEFAULT_INT_VALUE = 0;

77

78

// Protocol & Network Constants

79

public static final String PROTOCOL_SEPARATOR = "://";

80

public static final String PROTOCOL_LIGHT = "light";

81

public static final String PROTOCOL_HTTPS = "https";

82

public static final String HTTPS = "https";

83

public static final String PROTOCOL = "protocol";

84

public static final String REGISTRY_PROTOCOL_LOCAL = "local";

85

public static final String REGISTRY_PROTOCOL_DIRECT = "direct";

86

public static final String REGISTRY_PROTOCOL_ZOOKEEPER = "zookeeper";

87

public static final String ZOOKEEPER_REGISTRY_NAMESPACE = "/light";

88

public static final String ZOOKEEPER_REGISTRY_COMMAND = "/command";

89

90

// Framework & Service Constants

91

public static final String FRAMEWORK_NAME = "light";

92

public static final String METHOD_CONFIG_PREFIX = "methodconfig.";

93

public static final String LIGHT_4J = "Light4j";

94

public static final String SPRING_BOOT = "SpringBoot";

95

public static final String HYBRID_SERVICE_ID = "hybrid_service_id";

96

public static final String HYBRID_SERVICE_MAP = "hybrid_service_map";

97

public static final String HYBRID_SERVICE_DATA = "hybrid_service_data";

98

99

// Default Values & Configuration Constants

100

public static final String DEFAULT_VERSION = "1.0";

101

public static final String DEFAULT_VALUE = "default";

102

public static final String DEFAULT_CHARACTER = "utf-8";

103

public static final String UNKNOWN = "unknown";

104

public static final String NODE_TYPE_SERVICE = "service";

105

public static final String TAG_ENVIRONMENT = "environment";

106

public static final String PATH_SEPARATOR = "/";

107

108

// Rate Limiting Constants

109

public static final String RATELIMIT_LIMIT = "RateLimit-Limit";

110

public static final String RATELIMIT_REMAINING = "RateLimit-Remaining";

111

public static final String RATELIMIT_RESET = "RateLimit-Reset";

112

public static final String RETRY_AFTER = "Retry-After";

113

114

// Logging & Auditing Constants

115

public static final String AUDIT_LOGGER = "Audit";

116

public static final String STATUS = "Status";

117

public static final String STACK_TRACE = "StackTrace";

118

public static final String ERROR_MESSAGE = "errorMessage";

119

120

// Encoding & Compression Constants

121

public static final String ENCODE_GZIP = "gzip";

122

public static final String ENCODE_DEFLATE = "deflate";

123

124

// Miscellaneous Constants

125

public static final String REGISTRY_HEARTBEAT_SWITCHER = "RegistryHeartBeat";

126

public static final String RULE_ID = "ruleId";

127

}

128

```

129

130

### General Utilities

131

132

Generic utilities for UUID generation, encoding, version information, and various helper functions.

133

134

```java { .api }

135

/**

136

* Generic utilities for UUID generation, encoding, etc.

137

*/

138

public class Util {

139

public static final List<String> METHODS; // List of HTTP methods

140

141

// UUID generation

142

public static String getUUID();

143

public static String getAlphaNumUUID();

144

145

// String utilities

146

public static String quote(String value);

147

148

// Network utilities

149

@Deprecated

150

public static InetAddress getInetAddress();

151

152

// Version information

153

public static String getJarVersion();

154

public static String getFrameworkVersion();

155

156

// Parsing utilities

157

public static int parseInteger(String intStr);

158

159

// URL encoding/decoding

160

public static String urlEncode(String value);

161

public static String urlDecode(String value);

162

163

// Template processing

164

public static String substituteVariables(String template, Map<String, String> variables);

165

166

// JWT utilities

167

public static Map<String, String> parseAttributes(String attributesString);

168

169

// Service identification

170

public static String getServiceId(Map<String, Object> jsonMap);

171

public static String getServiceId(String host, String service, String name, String version);

172

}

173

```

174

175

### Module Registry

176

177

Module and plugin registry for server info component providing dynamic component registration and discovery.

178

179

```java { .api }

180

/**

181

* Module and plugin registry for server info component

182

*/

183

public class ModuleRegistry {

184

// Module registration

185

public static void registerModule(String configName, String moduleClass, Map<String, Object> config, List<String> masks);

186

public static Map<String, Object> getModuleRegistry();

187

public static List<String> getModuleClasses();

188

189

// Plugin registration

190

public static void registerPlugin(String pluginName, String pluginVersion, String configName, String pluginClass, Map<String, Object> config, List<String> masks);

191

public static Map<String, Object> getPluginRegistry();

192

public static List<Map<String, Object>> getPlugins();

193

public static List<String> getPluginClasses();

194

}

195

```

196

197

**Usage Examples:**

198

199

```java

200

import com.networknt.utility.Constants;

201

import com.networknt.utility.Util;

202

import com.networknt.utility.ModuleRegistry;

203

204

// Using framework constants

205

String correlationHeader = Constants.CORRELATION_ID_STRING; // "X-Correlation-Id"

206

String userIdClaim = Constants.USER_ID_STRING; // "user_id"

207

String jsonContentType = Constants.APPLICATION_JSON; // "application/json"

208

209

// Time calculations

210

long cacheExpiry = System.currentTimeMillis() + (5 * Constants.MINUTE_MILLS);

211

long dayInMillis = Constants.DAY_MILLS; // 86400000

212

213

// UUID generation

214

String uniqueId = Util.getUUID(); // Base64 URL-safe UUID

215

String alphaNumId = Util.getAlphaNumUUID(); // Alphanumeric only

216

217

// Service identification

218

String serviceId = Util.getServiceId("api.example.com", "user-service", "users", "1.0.0");

219

// Result: "api.example.com/user-service/users/1.0.0"

220

221

// Template variable substitution

222

String template = "Hello ${name}, welcome to ${service}";

223

Map<String, String> variables = Map.of("name", "Alice", "service", "UserAPI");

224

String result = Util.substituteVariables(template, variables);

225

// Result: "Hello Alice, welcome to UserAPI"

226

227

// URL encoding

228

String encoded = Util.urlEncode("hello world!"); // "hello%20world%21"

229

String decoded = Util.urlDecode(encoded); // "hello world!"

230

231

// Module registration

232

Map<String, Object> moduleConfig = Map.of(

233

"enabled", true,

234

"timeout", 5000

235

);

236

List<String> configMasks = Arrays.asList("password", "secret");

237

238

ModuleRegistry.registerModule(

239

"database-config",

240

"com.example.DatabaseModule",

241

moduleConfig,

242

configMasks

243

);

244

245

// Plugin registration

246

ModuleRegistry.registerPlugin(

247

"auth-plugin",

248

"1.2.0",

249

"auth-config",

250

"com.example.AuthPlugin",

251

Map.of("provider", "oauth2"),

252

Arrays.asList("clientSecret")

253

);

254

255

// Retrieve registered components

256

Map<String, Object> modules = ModuleRegistry.getModuleRegistry();

257

List<String> moduleClasses = ModuleRegistry.getModuleClasses();

258

List<Map<String, Object>> plugins = ModuleRegistry.getPlugins();

259

260

// Framework integration example

261

public class MicroserviceSetup {

262

public void configureService() {

263

// Use framework constants for consistent configuration

264

System.setProperty("framework.type", Constants.LIGHT_4J);

265

System.setProperty("protocol", Constants.PROTOCOL_HTTPS);

266

267

// Generate service identifiers

268

String serviceId = Util.getUUID();

269

String correlationId = Util.getAlphaNumUUID();

270

271

// Register service modules

272

ModuleRegistry.registerModule(

273

"service-config",

274

this.getClass().getName(),

275

getServiceConfig(),

276

getConfigMasks()

277

);

278

}

279

}

280

```