LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Codegen Web Portal

Most developers use light-codegen as a Java command line tool or Docker command line tool to scaffold their project. There is another option that is still working in progress which you can utilize a service from light-portal to generate the code from the specification defined in marketplace.

There are two parts for the light-codegen in light-portal: an API built with light-hybrid-4j and a single page application built with React.

The following tutorial focuses on how to start the light-port/hybrid-query server with code generator API embedded.

Preparation

In order to complete this tutorial, you need to clone the following repository into your workspace. The following assumes networknt as workspace folder under user home directory.

cd ~/networknt
git clone https://github.com/networknt/light-codegen.git
git clone https://github.com/networknt/light-config-test.git
git clone https://github.com/networknt/light-portal.git

The configuration files are located at light-config-test/light-portal/hybrid-query/cloud folder and you need to go to that folder to start the server.

First let’s build light-codegen so that we can have all the jar files locally. As light-codegen is released to maven central, you can download the right version of jar files from there as well.

cd ~/networknt/light-codegen
mvn clean install -DskipTests

Now let’s build the hybrid-query server in light-portal.

cd ~/networknt/light-portal/hybrid-query
mvn clean install

Start server with service dependencies in pom.xml

By default, hybrid-query project pom.xml include all the dependencies for codegen-web. The following block can be found in pom.xml file.

        <!-- light-codegen dependencies can be removed and put the jar file into service folder. -->
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>codegen-core</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>codegen-fwk</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>light-graphql-4j-generator</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>light-hybrid-4j-generator</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>light-rest-4j-generator</artifactId>
            <version>${version.light-4j}</version>
        </dependency>

In this case, the jar files for light-codegen is loaded form maven central when the project is built.

Now let’s copy the codegen-web jar file to ~/networknt/light-config-test/light-portal/hybrid-query/service

cd ~/networknt/light-config-test/light-portal/hybrid-query/service
cp ~/networknt/light-codegen/codegen-web/target/codegen-web-1.5.11.jar .

Note that this service jar must be copied to service folder in order to load and merge schema file with other services on the same server.

To start the server, let’s use the externalized config files in light-config-test folder.

cd ~/networknt/light-config-test/light-portal/hybrid-query/cloud
java -Dlight-4j-config-dir=./config -Dlogback.configurationFile=./logback.xml -cp ~/networknt/light-portal/hybrid-query/target/hybrid-query-1.0.0.jar:../service/* com.networknt.server.Server

Once the server is up and running, you can follow the step below Test Codegen Service to confirm it is working.

Start server with dependencies in service folder

Putting dependent services into hybrid-query pom.xml file is one way to embed services but it is not flexible as you have to rebuild the project in order to change the version of services. Another way is to add these dependent jar files into a service folder and then load dynamically during server startup by putting these files into the classpath. In this way, if you want to upgrade your services, you just need to copy the new version of jar files into the service folder and restart the hybrid-query server.

In summary, it makes sense to include the dependencies into pom.xml during development as it is very convenient. However, when you goto production, it is wise to put these services into a separate folder to load them dynamically.

Now let’s first copy the jar files to ~/networknt/light-config-test/light-portal/hybrid-query/service folder from just built light-codegen project.

cd ~/networknt/light-config-test/light-portal/hybrid-query/service
cp ~/networknt/light-codegen/codegen-core/target/codegen-core-1.5.11.jar .
cp ~/networknt/light-codegen/codegen-fwk/target/codegen-fwk-1.5.11.jar .
cp ~/networknt/light-codegen/codegen-web/target/codegen-web-1.5.11.jar .
cp ~/networknt/light-codegen/light-graphql-4j/target/light-graphql-4j-generator-1.5.11.jar .
cp ~/networknt/light-codegen/light-hybrid-4j/target/light-hybrid-4j-generator-1.5.11.jar .
cp ~/networknt/light-codegen/light-rest-4j/target/light-rest-4j-generator-1.5.11.jar .

Once this is done, you need to comment out the section in pom.xml for all light-codegen dependencies.


        <!-- light-codegen dependencies can be removed and put the jar file into service folder. -->
        <!--
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>codegen-core</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>codegen-fwk</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>light-graphql-4j-generator</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>light-hybrid-4j-generator</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>light-rest-4j-generator</artifactId>
            <version>${version.light-4j}</version>
        </dependency>
        -->

Rebuild the hybrid-query server without the light-codegen in the fat jar.

cd ~/networknt/light-portal/hybrid-query
mvn clean install

Now we can start the server from cloud folder again with light-codegen services loaded from service folder in classpath.

cd ~/networknt/light-config-test/light-portal/hybrid-query/cloud
java -Dlight-4j-config-dir=./config -Dlogback.configurationFile=./logback.xml -cp ~/networknt/light-portal/hybrid-query/target/hybrid-query-1.0.0.jar:../service/* com.networknt.server.Server

To confirm the services are working follow the next step to test.

Test Codegen Service

Given that light-codegen/codegen-web is one of the services, to ensure your hybrid-server is working, we are going to call one of the action in codegen-web to verify if the server is functioning.

curl -k -X POST \
  https://localhost:8082/api/json \
  -H 'cache-control: no-cache' \
  -d '{"host":"lightapi.net","service":"codegen","action":"listFramework","version":"0.0.1"}'

and the expected result should be

["light-hybrid-4j-server","light-graphql-4j","openapi","light-hybrid-4j-service","swagger"]
  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Codegen Web Portal” was last updated: July 5, 2021: fixes #275 checked and corrected grammar/spelling for majority of pages (#276) (b3bbb7b)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute