Skip to content

Commit

Permalink
fixes #338 update codegen-web to handler.yml and change the path to c…
Browse files Browse the repository at this point in the history
…odegen (#339)
  • Loading branch information
stevehu authored Jun 29, 2019
1 parent 5ffbc0b commit 141ce6a
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 70 deletions.
8 changes: 8 additions & 0 deletions codegen-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
<groupId>com.networknt</groupId>
<artifactId>resource</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>health</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>info</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
Expand Down
86 changes: 86 additions & 0 deletions codegen-web/src/main/resources/config/handler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Handler middleware chain configuration
---
enabled: true

#------------------------------------------------------------------------------
# Support individual handler chains for each separate endpoint. It allows framework
# handlers like health check, server info to bypass majority of the middleware handlers
# and allows mixing multiple frameworks like OpenAPI and GraphQL in the same instance.
#
# handlers -- list of handlers to be used across chains in this microservice
# including the routing handlers for ALL endpoints
# -- format: fully qualified handler class name@optional:given name
# chains -- allows forming of [1..N] chains, which could be wholly or
# used to form handler chains for each endpoint
# ex.: default chain below, reused partially across multiple endpoints
# paths -- list all the paths to be used for routing within the microservice
# ---- path: the URI for the endpoint (ex.: path: '/v1/pets')
# ---- method: the operation in use (ex.: 'post')
# ---- exec: handlers to be executed -- this element forms the list and
# the order of execution for the handlers
#
# IMPORTANT NOTES:
# - to avoid executing a handler, it has to be removed/commented out in the chain
# or change the enabled:boolean to false for a middleware handler configuration.
# - all handlers, routing handler included, are to be listed in the execution chain
# - for consistency, give a name to each handler; it is easier to refer to a name
# vs a fully qualified class name and is more elegant
# - you can list in chains the fully qualified handler class names, and avoid using the
# handlers element altogether
#------------------------------------------------------------------------------
handlers:
# Light-framework cross-cutting concerns implemented in the microservice
- com.networknt.exception.ExceptionHandler@exception
- com.networknt.metrics.MetricsHandler@metrics
- com.networknt.traceability.TraceabilityHandler@traceability
- com.networknt.correlation.CorrelationHandler@correlation
# Cors handler to handler post/put pre-flight
- com.networknt.cors.CorsHttpHandler@cors
# - com.networknt.openapi.OpenApiHandler@specification
# - com.networknt.openapi.JwtVerifyHandler@security
# - com.networknt.body.BodyHandler@body
# - com.networknt.audit.AuditHandler@audit
# - com.networknt.sanitizer.SanitizerHandler@sanitizer
# - com.networknt.openapi.ValidatorHandler@validator
# Header middleware to manipulate request and/or response headers before or after downstream server
# - com.networknt.header.HeaderHandler@header
# Direct requests to named services based on the request path
# - com.networknt.router.middleware.PathPrefixServiceHandler@path
# - com.networknt.router.RouterHandler@router
# - com.networknt.resource.PathResourceHandler@resource
- com.networknt.rpc.router.JsonHandler@json
# Customer business domain specific cross-cutting concerns handlers
# - com.example.validator.CustomizedValidator@custvalidator
# Framework endpoint handlers
- com.networknt.health.HealthGetHandler@health
- com.networknt.info.ServerInfoGetHandler@info
# - com.networknt.metrics.prometheus.PrometheusGetHandler@getprometheus

chains:
default:
- exception
- metrics
- traceability
- correlation
- json

paths:
- path: '/codegen'
method: 'POST'
exec:
- default
- path: '/codegen'
method: 'GET'
exec:
- default

- path: '/health/com.networknt.codegen-web-2.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'
method: 'get'
exec:
- info
4 changes: 4 additions & 0 deletions codegen-web/src/main/resources/config/rpc-router.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
description: RPC router description
handlerPackage: 'com.networknt.codegen'
jsonPath: /codegen
45 changes: 0 additions & 45 deletions codegen-web/src/main/resources/config/secret.yml

This file was deleted.

2 changes: 1 addition & 1 deletion codegen-web/src/main/resources/config/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enableTwoWayTls: false
truststoreName: server.truststore

# Unique service identifier. Used in service registration and discovery etc.
serviceId: com.networknt.example-graphql-subscription-1.0.0
serviceId: com.networknt.codegen-web-2.0.0

# Flag to enable service registration. Only be true if running as standalone Java jar.
enableRegistry: false
Expand Down
15 changes: 1 addition & 14 deletions codegen-web/src/main/resources/config/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ singletons:
# - com.networknt.server.ShutdownHookProvider:
# - com.networknt.server.Test1ShutdownHook
# - com.networknt.server.Test2ShutdownHook
# MiddlewareHandler implementations
- com.networknt.handler.MiddlewareHandler:
# Exception Global exception handler that needs to be called first.
- com.networknt.exception.ExceptionHandler
# Metrics In order to calculate response time accurately, this needs to be the second.
- com.networknt.metrics.MetricsHandler
# Traceability Put traceabilityId into response header from request header if it exists
- com.networknt.traceability.TraceabilityHandler
# Correlation Create correlationId if it doesn't exist in the request header and put it into the request header
- com.networknt.correlation.CorrelationHandler
# Cors handler to handler post/put pre-flight
- com.networknt.cors.CorsHttpHandler
# SimpleAudit Log important info about the request into audit log
- com.networknt.audit.AuditHandler

# Generator interface implementations
- com.networknt.codegen.Generator:
- com.networknt.codegen.rest.OpenApiGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGenerator() throws ClientException, ApiException, UnsupportedEnc
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testMissingGeneratorItem() throws ClientException {
}
try {
connection.getIoThread().execute(() -> {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");

request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testInvalidFrameworkMultiple() throws ClientException, IOException {
}
try {
connection.getIoThread().execute(() -> {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -183,7 +183,7 @@ public void testInvalidFrameworkSingle() throws ClientException, IOException {
}
try {
connection.getIoThread().execute(() -> {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -232,7 +232,7 @@ public void testGeneratorMultipleText() throws ClientException, ApiException, IO
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -276,7 +276,7 @@ public void testGeneratorSingleText() throws ClientException, ApiException, IOEx
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -320,7 +320,7 @@ public void testGeneratorMultipleAllUrl() throws ClientException, ApiException,
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -364,7 +364,7 @@ public void testGeneratorSingleModelUrl() throws ClientException, ApiException,
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testGetSchema() throws ClientException, ApiException, UnsupportedEnc
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down
2 changes: 1 addition & 1 deletion codegen-web/view/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function submitForm(action) {
};
//console.log(request);
try {
const response = await fetch('/portal/query', request);
const response = await fetch('/codegen', request);
const data = await response.blob();
const filename = 'light-project.zip';
if (typeof window.navigator.msSaveBlob !== 'undefined') {
Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@
<artifactId>resource</artifactId>
<version>${version.light-4j}</version>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>health</artifactId>
<version>${version.light-4j}</version>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>info</artifactId>
<version>${version.light-4j}</version>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
Expand Down

0 comments on commit 141ce6a

Please sign in to comment.