Skip to content

Commit

Permalink
fixes #703 update the codegen-web with the new light-hybrid-4j updates (
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu authored Aug 6, 2024
1 parent 1684b1a commit b95089c
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 212 deletions.
4 changes: 4 additions & 0 deletions codegen-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<groupId>com.networknt</groupId>
<artifactId>rpc-router</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>rpc-security</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.networknt.codegen.graphql.GraphqlGenerator;
import com.networknt.config.Config;
import com.networknt.config.JsonMapper;
import com.networknt.rpc.Handler;
import com.networknt.rpc.HybridHandler;
import com.networknt.rpc.router.JsonHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.utility.HashUtil;
Expand Down Expand Up @@ -37,7 +37,7 @@
* @author Steve Hu
*/
@ServiceHandler(id="lightapi.net/codegen/multiple/0.0.1")
public class CodegenMultipleHandler implements Handler {
public class CodegenMultipleHandler implements HybridHandler {
static private final String CONFIG_NAME = "codegen-web";
static private final String STATUS_INVALID_FRAMEWORK = "ERR11100";
static private final String STATUS_MISSING_GENERATOR_ITEM = "ERR11101";
Expand Down Expand Up @@ -159,20 +159,4 @@ public ByteBuffer handle(HttpServerExchange exchange, Object input) {
File file = new File(codegenWebConfig.getZipFolder() + separator + zipFile);
return NioUtils.toByteBuffer(file);
}

@Override
public ByteBuffer validate(String serviceId, Object object) {
// get schema from serviceId, remember that the schema is for the data object only.
// the input object is the data attribute of the request body.
Map<String, Object> serviceMap = (Map<String, Object>) JsonHandler.schema.get(serviceId);
if(logger.isDebugEnabled()) {
try {
logger.debug("serviceId = " + serviceId + " serviceMap = " + Config.getInstance().getMapper().writeValueAsString(serviceMap));
} catch (Exception e) {
logger.error("Exception:", e);
}
}
logger.debug("Skipping validation on generator request for now.");
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.networknt.codegen.graphql.GraphqlGenerator;
import com.networknt.config.Config;
import com.networknt.config.JsonMapper;
import com.networknt.rpc.Handler;
import com.networknt.rpc.HybridHandler;
import com.networknt.rpc.router.JsonHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.utility.HashUtil;
Expand Down Expand Up @@ -37,7 +37,7 @@
* @author Steve Hu
*/
@ServiceHandler(id="lightapi.net/codegen/single/0.0.1")
public class CodegenSingleHandler implements Handler {
public class CodegenSingleHandler implements HybridHandler {
static private final String CONFIG_NAME = "codegen-web";
static private final String STATUS_INVALID_FRAMEWORK = "ERR11100";
static private final String STATUS_MISSING_GENERATOR_ITEM = "ERR11101";
Expand Down Expand Up @@ -161,20 +161,4 @@ public ByteBuffer handle(HttpServerExchange exchange, Object input) {
File file = new File(codegenWebConfig.getZipFolder() + separator + zipFile);
return NioUtils.toByteBuffer(file);
}

@Override
public ByteBuffer validate(String serviceId, Object object) {
// get schema from serviceId, remember that the schema is for the data object only.
// the input object is the data attribute of the request body.
Map<String, Object> serviceMap = (Map<String, Object>) JsonHandler.schema.get(serviceId);
if(logger.isDebugEnabled()) {
try {
logger.debug("serviceId = " + serviceId + " serviceMap = " + Config.getInstance().getMapper().writeValueAsString(serviceMap));
} catch (Exception e) {
logger.error("Exception:", e);
}
}
logger.debug("Skipping validation on generator request for now.");
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.networknt.codegen.FrameworkRegistry;
import com.networknt.config.Config;
import com.networknt.rpc.Handler;
import com.networknt.rpc.HybridHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.utility.NioUtils;
import io.undertow.server.HttpServerExchange;
Expand All @@ -18,7 +18,7 @@
* Created by steve on 26/04/17.
*/
@ServiceHandler(id="lightapi.net/codegen/listFramework/0.0.1")
public class FrameworkListHandler implements Handler {
public class FrameworkListHandler implements HybridHandler {
static private final Logger logger = LoggerFactory.getLogger(FrameworkListHandler.class);
static private Set<String> frameworks = FrameworkRegistry.getInstance().getFrameworks();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.networknt.codegen.FrameworkRegistry;
import com.networknt.codegen.Generator;
import com.networknt.rpc.Handler;
import com.networknt.rpc.HybridHandler;
import com.networknt.rpc.router.ServiceHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;
Expand All @@ -17,7 +17,7 @@
* Created by steve on 10/05/17.
*/
@ServiceHandler(id="lightapi.net/codegen/getSchema/0.0.1")
public class SchemaGetHandler implements Handler {
public class SchemaGetHandler implements HybridHandler {
static private final Logger logger = LoggerFactory.getLogger(SchemaGetHandler.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.networknt.codegen.handler;

import com.networknt.rpc.Handler;
import com.networknt.rpc.HybridHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.utility.NioUtils;
import io.undertow.server.HttpServerExchange;
Expand All @@ -20,7 +20,7 @@
*/
@Deprecated
@ServiceHandler(id="lightapi.net/codegen/validateUploadFile/0.0.1")
public class ValidateUploadFileHandler implements Handler {
public class ValidateUploadFileHandler implements HybridHandler {
static private final Logger logger = LoggerFactory.getLogger(ValidateUploadFileHandler.class);

/**
Expand Down
28 changes: 22 additions & 6 deletions codegen-web/src/main/resources/config/handler.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Handler middleware chain configuration
---
enabled: true
enabled: ${handler.enabled:true}

# Configuration for the LightHttpHandler. The handler is the base class for all middleware, server and health handlers
# set the Status Object in the AUDIT_INFO, for auditing purposes
# default, if not set:false
auditOnError: ${handler.auditOnError:false}

# set the StackTrace in the AUDIT_INFO, for auditing purposes
# default, if not set:false
auditStackTrace: ${handler.auditStackTrace:false}

#------------------------------------------------------------------------------
# Support individual handler chains for each separate endpoint. It allows framework
Expand Down Expand Up @@ -31,11 +40,12 @@ enabled: true
handlers:
# Light-framework cross-cutting concerns implemented in the microservice
- com.networknt.exception.ExceptionHandler@exception
- com.networknt.metrics.MetricsHandler@metrics
# - com.networknt.metrics.MetricsHandler@metrics
- com.networknt.traceability.TraceabilityHandler@traceability
- com.networknt.correlation.CorrelationHandler@correlation
# - com.networknt.jaeger.tracing.JaegerHandler@jaeger
# Cors handler to handler post/put pre-flight
- com.networknt.cors.CorsHttpHandler@cors
# - com.networknt.cors.CorsHttpHandler@cors
# - com.networknt.openapi.OpenApiHandler@specification
# - com.networknt.openapi.JwtVerifyHandler@security
# - com.networknt.body.BodyHandler@body
Expand All @@ -48,7 +58,12 @@ handlers:
# - com.networknt.router.middleware.PathPrefixServiceHandler@path
# - com.networknt.router.RouterHandler@router
# - com.networknt.resource.PathResourceHandler@resource
- com.networknt.rpc.router.SchemaHandler@schema
- com.networknt.rpc.router.JsonHandler@json
- com.networknt.rpc.security.HybridJwtVerifyHandler@jwt
- com.networknt.apikey.ApiKeyHandler@apikey
- com.networknt.basicauth.BasicAuthHandler@basic
- com.networknt.security.UnifiedSecurityHandler@security
# Customer business domain specific cross-cutting concerns handlers
# - com.example.validator.CustomizedValidator@custvalidator
# Framework endpoint handlers
Expand All @@ -59,9 +74,10 @@ handlers:
chains:
default:
- exception
- metrics
- traceability
- correlation
- schema
- security
- json

paths:
Expand All @@ -74,13 +90,13 @@ paths:
exec:
- default

- path: '/health/com.networknt.codegen-web-2.0.0'
- path: '/adm/health/com.networknt.portal.hybrid.command-1.0.0'
method: 'get'
exec:
- health

# In most case, the /server/info endpoint shouldn't be exposed. If it is, then it must be protected by OAuth 2.0 or Basic Auth
- path: '/server/info'
- path: '/adm/server/info'
method: 'get'
exec:
- info
36 changes: 0 additions & 36 deletions codegen-web/src/main/resources/config/hybrid-security.yml

This file was deleted.

49 changes: 0 additions & 49 deletions codegen-web/src/main/resources/config/server.yml

This file was deleted.

3 changes: 0 additions & 3 deletions codegen-web/src/main/resources/config/service.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Singleton service factory configuration/IoC injection
singletons:
# HandlerProvider implementation
- com.networknt.handler.HandlerProvider:
- com.networknt.rpc.router.RpcRouter
# StartupHookProvider implementations
- com.networknt.server.StartupHookProvider:
# registry all service handlers by from annotations
Expand Down
8 changes: 4 additions & 4 deletions codegen-web/src/main/resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"enum": ["C", "U"]
},
"modelText": {
"type": "string"
"type": ["string", "object"]
},
"modelUrl": {
"type": "string"
Expand All @@ -46,7 +46,7 @@
"enum": ["C", "U"]
},
"configText" : {
"type": "string"
"type": ["string", "object"]
},
"configUrl": {
"type": "string"
Expand Down Expand Up @@ -77,7 +77,7 @@
"enum": ["C", "U"]
},
"modelText": {
"type": "string"
"type": ["string", "object"]
},
"modelUrl": {
"type": "string"
Expand All @@ -87,7 +87,7 @@
"enum": ["C", "U"]
},
"configText" : {
"type" : "string"
"type": ["string", "object"]
},
"configUrl": {
"type": "string"
Expand Down
Loading

0 comments on commit b95089c

Please sign in to comment.